diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index 9b14372a419c3c84d05cf26b00427e12965c73cd..230545ce535fde450c54c69941e0454ddb87456c 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -37,6 +37,7 @@ from typing import NamedTuple, Optional, Sequence from beancount.core import data as bc_data from beancount import loader as bc_loader +from conservancy_beancount import cliutil from conservancy_beancount import data from conservancy_beancount import rtutil from conservancy_beancount.reports import accrual @@ -144,18 +145,6 @@ class RTClient(testutil.RTClient): def accrual_postings(): return data.Posting.from_entries(copy.deepcopy(ACCRUAL_TXNS)) -def check_link_regexp(regexp, match_s, first_link_only=False): - assert regexp - assert re.search(regexp, match_s) - assert re.search(regexp, match_s + ' postlink') - assert re.search(regexp, match_s + '0') is None - assert re.search(regexp, '1' + match_s) is None - end_match = re.search(regexp, 'prelink ' + match_s) - if first_link_only: - assert end_match is None - else: - assert end_match - def accruals_by_meta(postings, value, key='invoice', wrap_type=iter): return wrap_type( post for post in postings @@ -223,63 +212,6 @@ def check_aging_ods(ods_file, check_aging_sheet(sheets[0], recv_rows, date, -60) check_aging_sheet(sheets[1], pay_rows, date, -30) -@pytest.mark.parametrize('link_fmt', [ - '{}', - 'rt:{}', - 'rt://ticket/{}', -]) -def test_search_term_parse_rt_shortcuts(link_fmt): - key, regexp = accrual.SearchTerm.parse(link_fmt.format(220)) - assert key == 'rt-id' - check_link_regexp(regexp, 'rt:220', first_link_only=True) - check_link_regexp(regexp, 'rt://ticket/220', first_link_only=True) - -@pytest.mark.parametrize('link_fmt', [ - '{}/{}', - 'rt:{}/{}', - 'rt://ticket/{}/attachments/{}', -]) -def test_search_term_parse_invoice_shortcuts(link_fmt): - key, regexp = accrual.SearchTerm.parse(link_fmt.format(330, 660)) - assert key == 'invoice' - check_link_regexp(regexp, 'rt:330/660') - check_link_regexp(regexp, 'rt://ticket/330/attachments/660') - -@pytest.mark.parametrize('key', [ - 'approval', - 'contract', - 'invoice', -]) -def test_search_term_parse_metadata_rt_shortcut(key): - actual_key, regexp = accrual.SearchTerm.parse(f'{key}=440/420') - assert actual_key == key - check_link_regexp(regexp, 'rt:440/420') - check_link_regexp(regexp, 'rt://ticket/440/attachments/420') - -@pytest.mark.parametrize('key', [ - None, - 'approval', - 'contract', - 'invoice', -]) -def test_search_term_parse_repo_link(key): - document = '1234.pdf' - if key is None: - key = 'invoice' - search = document - else: - search = f'{key}={document}' - actual_key, regexp = accrual.SearchTerm.parse(search) - assert actual_key == key - check_link_regexp(regexp, document) - -@pytest.mark.parametrize('search,unmatched', [ - ('1234.pdf', '1234_pdf'), -]) -def test_search_term_parse_regexp_escaping(search, unmatched): - _, regexp = accrual.SearchTerm.parse(search) - assert re.search(regexp, unmatched) is None - @pytest.mark.parametrize('search_terms,expect_count,check_func', [ ([], ACCRUALS_COUNT, lambda post: post.account.is_under( 'Assets:Receivable:', 'Liabilities:Payable:', @@ -292,6 +224,7 @@ def test_search_term_parse_regexp_escaping(search, unmatched): ([('rt-id', '^rt:510$'), ('approval', '.')], 0, lambda post: False), ]) def test_filter_search(accrual_postings, search_terms, expect_count, check_func): + search_terms = [cliutil.SearchTerm._make(query) for query in search_terms] actual = list(accrual.filter_search(accrual_postings, search_terms)) if expect_count < ACCRUALS_COUNT: assert ACCRUALS_COUNT > len(actual) >= expect_count