tests: Test updates for accrual report changes in the last commit.

Where assertions are removed from individual tests, I believe that
functionality is covered by other tests (although probably not to the extent
of checking multiple splits).
This commit is contained in:
Brett Smith 2020-10-24 11:31:39 -04:00
parent 8ec3a12d5a
commit ea69d58957

View file

@ -54,13 +54,21 @@ ACCRUALS_COUNT = sum(
if post.account.startswith(('Assets:Receivable:', 'Liabilities:Payable:')) if post.account.startswith(('Assets:Receivable:', 'Liabilities:Payable:'))
) )
ACCOUNTS = [ # Accounts where invoice and entity metadata are both used to identify accruals.
INVOICE_ACCOUNTS = [
'Assets:Receivable:Accounts', 'Assets:Receivable:Accounts',
'Assets:Receivable:Loans', 'Assets:Receivable:Loans',
'Liabilities:Payable:Accounts', 'Liabilities:Payable:Accounts',
]
# Accounts where only entity metadata is used to identify accruals.
ENTITY_ACCOUNTS = [
'Assets:Prepaid:Expenses',
'Liabilities:Payable:Vacation', 'Liabilities:Payable:Vacation',
] ]
ACCOUNTS = INVOICE_ACCOUNTS + ENTITY_ACCOUNTS
AGE_SUM_RE = re.compile(r'(?:\b(\d+) Years?)?(?: ?\b(\d+) Days?)?[:]') AGE_SUM_RE = re.compile(r'(?:\b(\d+) Years?)?(?: ?\b(\d+) Days?)?[:]')
class AgingRow(NamedTuple): class AgingRow(NamedTuple):
@ -268,7 +276,7 @@ def test_report_type_by_unknown_name(arg):
accrual.ReportType.by_name(arg) accrual.ReportType.by_name(arg)
@pytest.mark.parametrize('acct_name,invoice,day', testutil.combine_values( @pytest.mark.parametrize('acct_name,invoice,day', testutil.combine_values(
ACCOUNTS, INVOICE_ACCOUNTS,
['FIXME', '', None, *testutil.NON_STRING_METADATA_VALUES], ['FIXME', '', None, *testutil.NON_STRING_METADATA_VALUES],
itertools.count(1), itertools.count(1),
)) ))
@ -321,7 +329,7 @@ def test_make_consistent_across_entity(acct_name):
for key, posts in consistent.items(): for key, posts in consistent.items():
assert len(posts) == 1 assert len(posts) == 1
@pytest.mark.parametrize('acct_name', ACCOUNTS) @pytest.mark.parametrize('acct_name', INVOICE_ACCOUNTS)
def test_make_consistent_entity_differs_accrual_payment(acct_name): def test_make_consistent_entity_differs_accrual_payment(acct_name):
invoice = 'Invoices/DifferPay.pdf' invoice = 'Invoices/DifferPay.pdf'
txn = testutil.Transaction(postings=[ txn = testutil.Transaction(postings=[
@ -429,7 +437,6 @@ def test_make_consistent_with_three_one_split(account, day):
entries = [testutil.Transaction(date=datetime.date(2019, 5, dd), postings=[( entries = [testutil.Transaction(date=datetime.date(2019, 5, dd), postings=[(
account, dd, meta, account, dd, meta,
)]) for dd in [5, 15, 25]] )]) for dd in [5, 15, 25]]
meta['entity'] = '1Split'
entries.insert(day // 10, testutil.Transaction( entries.insert(day // 10, testutil.Transaction(
date=datetime.date(2019, 5, day), date=datetime.date(2019, 5, day),
postings=[(account, -45, meta)], postings=[(account, -45, meta)],
@ -446,12 +453,10 @@ def test_make_consistent_with_three_one_split(account, day):
for related in actual.values(): for related in actual.values():
assert len(related) == post_count assert len(related) == post_count
assert sum(post.units.number for post in related) == 0 assert sum(post.units.number for post in related) == 0
assert all(post.meta['invoice'] == meta['invoice'] for post in related)
assert {post.meta['entity'] for post in related} == {'1Split', '3Split'}
@pytest.mark.parametrize('account', ACCOUNTS) @pytest.mark.parametrize('account', ACCOUNTS)
def test_make_consistent_with_three_two_split(account): def test_make_consistent_with_three_two_split(account):
meta = {'rt-id': '1', 'invoice': 'rt:1/9'} meta = {'rt-id': '1', 'invoice': 'rt:1/9', 'entity': '5Split'}
entries = [testutil.Transaction(date=datetime.date(2019, 5, day), postings=[( entries = [testutil.Transaction(date=datetime.date(2019, 5, day), postings=[(
account, day * (1 if day % 10 else -1.5), meta, account, day * (1 if day % 10 else -1.5), meta,
)]) for day in range(5, 30, 5)] )]) for day in range(5, 30, 5)]
@ -465,7 +470,6 @@ def test_make_consistent_with_three_two_split(account):
for related in actual.values(): for related in actual.values():
assert len(related) >= 2 assert len(related) >= 2
assert sum(post.units.number for post in related) == 0 assert sum(post.units.number for post in related) == 0
assert all(post.meta['invoice'] == meta['invoice'] for post in related)
def check_output(output, expect_patterns): def check_output(output, expect_patterns):
output.seek(0) output.seek(0)