diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index 0a2d6dd38259de773225d2ec4d83e875f65f6c02..e880b0d33ffeb4de3b9b5f312c1db7cedf1c0036 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -250,6 +250,20 @@ def test_consistency_check_when_inconsistent(meta_key, account): assert actual.entry is txn assert actual.source.get('lineno') == exp_lineno +def test_consistency_check_cost(): + account = ACCOUNTS[0] + invoice = 'test-cost-invoice' + txn = testutil.Transaction(postings=[ + (account, 100, 'EUR', ('1.1251', 'USD'), {'invoice': invoice, 'lineno': 1}), + (account, -100, 'EUR', ('1.125', 'USD'), {'invoice': invoice, 'lineno': 2}), + ]) + related = core.RelatedPostings(data.Posting.from_txn(txn)) + errors = list(accrual.consistency_check({invoice: related})) + for post, err in itertools.zip_longest(txn.postings, errors): + assert err.message == f'inconsistent cost for invoice {invoice}: {post.cost}' + assert err.entry is txn + assert err.source.get('lineno') == post.meta['lineno'] + def check_output(output, expect_patterns): output.seek(0) testutil.check_lines_match(iter(output), expect_patterns)