From 2431b3ff5bc0833f6c75b7cfca9cdc58b859c43a Mon Sep 17 00:00:00 2001 From: Scott Carpenter Date: Sun, 15 Jul 2018 17:56:48 -0500 Subject: [PATCH] Branch coverage and set branch cov in pytest.ini --- ledgerbil/reconciler.py | 9 +++++---- ledgerbil/tests/test_reconciler.py | 22 ++++++++++++++++++++++ pytest.ini | 2 +- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/ledgerbil/reconciler.py b/ledgerbil/reconciler.py index ec4a744..7c30a13 100644 --- a/ledgerbil/reconciler.py +++ b/ledgerbil/reconciler.py @@ -462,8 +462,10 @@ def finish_balancing(self): return for thing in self.open_transactions: - if thing.is_pending(): - thing.set_cleared() + # todo: removing previous check for the sake of branch coverage: + # thing.is_pending() + # remove this todo if things don't suffer for it... + thing.set_cleared() self.previous_balance = self.ending_balance self.previous_date = date.today() @@ -596,8 +598,7 @@ def reconciled_status(): for balance_line in balance_lines: ledger = get_account_balance_generic(balance_line) - if ledger: - accounts[ledger.account].ledger_balance = ledger.amount + accounts[ledger.account].ledger_balance = ledger.amount reconciled_status_report(accounts) diff --git a/ledgerbil/tests/test_reconciler.py b/ledgerbil/tests/test_reconciler.py index 4f715f6..d321435 100644 --- a/ledgerbil/tests/test_reconciler.py +++ b/ledgerbil/tests/test_reconciler.py @@ -405,6 +405,7 @@ def test_get_rec_account_matched_when_match_in_either_file(): assert reconciler.get_rec_account_matched() == 'a: 401k: james bonds idx' + # reverse order of reconciler files with FileTester.temp_input(ledgerfile_data) as tempfilename: with FileTester.temp_input(ledgerfile2_data) as tempfilename2: reconciler = Reconciler([ @@ -415,6 +416,27 @@ def test_get_rec_account_matched_when_match_in_either_file(): assert reconciler.get_rec_account_matched() == 'a: 401k: james bonds idx' +def test_get_rec_account_matched_when_match_in_neither_file(): + ledgerfile_data = dedent(''' + 2017/11/28 zombie investments + a: 401k: stock idx 12.357 qwrty @ $20.05 + i: investment: adjustment + ''') + ledgerfile2_data = dedent(''' + 2017/12/28 zombie investments + a: 401k: james bonds idx 45.678 qwrty @ $31.11 + i: investment: adjustment + ''') + + with FileTester.temp_input(ledgerfile_data) as tempfilename: + with FileTester.temp_input(ledgerfile2_data) as tempfilename2: + with pytest.raises(StopIteration): + Reconciler([ + LedgerFile(tempfilename, 'goldfinger'), + LedgerFile(tempfilename2, 'goldfinger'), + ]) + + def test_init_things(): with FileTester.temp_input(testdata) as tempfilename: ledgerfile = LedgerFile(tempfilename, 'cash') diff --git a/pytest.ini b/pytest.ini index f106b9f..b6c4e2b 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,3 @@ [pytest] norecursedirs = .* __pycache__ ve -addopts = --cov . --cov-report term-missing -q --color=yes --no-cov-on-fail +addopts = --cov . --cov-report term-missing -q --color=yes --no-cov-on-fail --cov-branch