From 13df0390a19b4904a38ad9ad7e7c002385d2a5a0 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Sat, 23 May 2020 08:48:41 -0400 Subject: [PATCH] tests: Generate configuration in accrual-report tests. Usually reduces the amount of testing boilerplate. --- tests/test_reports_accrual.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index 5fa0aba..fe5b2f7 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -346,7 +346,12 @@ def test_outgoing_report_custom_field_fallbacks(accrual_postings): r'^PAYMENT METHOD:\s*$', ]) -def run_main(arglist, config): +def run_main(arglist, config=None): + if config is None: + config = testutil.TestConfig( + books_path=testutil.test_path('books/accruals.beancount'), + rt_client=RTClient(), + ) output = io.StringIO() errors = io.StringIO() retcode = accrual.main(arglist, output, errors, config) @@ -366,15 +371,10 @@ def check_main_fails(arglist, config, error_flags, error_patterns): ['entity=Lawyer'], ]) def test_main_outgoing_report(arglist): - rt_client = RTClient() - config = testutil.TestConfig( - books_path=testutil.test_path('books/accruals.beancount'), - rt_client=rt_client, - ) - retcode, output, errors = run_main(arglist, config) + retcode, output, errors = run_main(arglist) assert not errors.getvalue() assert retcode == 0 - rt_url = rt_client.DEFAULT_URL[:-9] + rt_url = RTClient.DEFAULT_URL[:-9] rt_id_url = re.escape(f'<{rt_url}Ticket/Display.html?id=510>') contract_url = re.escape(f'<{rt_url}Ticket/Attachment/4000/4000/contract.pdf>') check_output(output, [ @@ -391,10 +391,7 @@ def test_main_outgoing_report(arglist): ['entity=DonorB'], ]) def test_main_balance_report(arglist): - config = testutil.TestConfig( - books_path=testutil.test_path('books/accruals.beancount'), - ) - retcode, output, errors = run_main(arglist, config) + retcode, output, errors = run_main(arglist) assert not errors.getvalue() assert retcode == 0 check_output(output, [ @@ -413,10 +410,7 @@ def test_main_no_books(): ['entity=NonExistent'], ]) def test_main_no_matches(arglist): - config = testutil.TestConfig( - books_path=testutil.test_path('books/accruals.beancount'), - ) - check_main_fails(arglist, config, 8, [ + check_main_fails(arglist, None, 8, [ r'^warning: no matching entries found to report$', ])