-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some tests for entries.update_postings
- Loading branch information
Showing
2 changed files
with
65 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Tests for the entry helpers.""" | ||
|
||
# pylint: disable=missing-docstring | ||
from beancount.parser import parser | ||
|
||
from smart_importer.entries import update_postings | ||
|
||
TEST_DATA, _errors, _options = parser.parse_string( | ||
""" | ||
2016-01-06 * "Farmer Fresh" "Buying groceries" | ||
Assets:US:BofA:Checking -10.00 USD | ||
2016-01-06 * "Farmer Fresh" "Buying groceries" | ||
Assets:US:BofA:Checking -10.00 USD | ||
Assets:US:BofA:Checking 10.00 USD | ||
""" | ||
) | ||
|
||
|
||
def test_update_postings() -> None: | ||
txn0 = TEST_DATA[0] | ||
|
||
def _update(accounts: list[str]) -> list[tuple[str, bool]]: | ||
"""Update, get accounts and whether this is the original posting.""" | ||
updated = update_postings(txn0, accounts) | ||
return [(p.account, p is txn0.postings[0]) for p in updated.postings] | ||
|
||
assert _update(["Assets:US:BofA:Checking", "Assets:Other"]) == [ | ||
("Assets:US:BofA:Checking", True), | ||
("Assets:Other", False), | ||
] | ||
|
||
assert _update( | ||
["Assets:US:BofA:Checking", "Assets:US:BofA:Checking", "Assets:Other"] | ||
) == [ | ||
("Assets:US:BofA:Checking", True), | ||
("Assets:US:BofA:Checking", False), | ||
("Assets:Other", False), | ||
] | ||
|
||
assert _update(["Assets:Other", "Assets:Other2"]) == [ | ||
("Assets:Other", False), | ||
("Assets:Other2", False), | ||
("Assets:US:BofA:Checking", True), | ||
] | ||
|
||
txn1 = TEST_DATA[1] | ||
assert update_postings(txn1, ["Assets:Other"]) == txn1 |