From e9e2bb9b001d38cb5d8a7eee1e792c6ec1953c79 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Thu, 5 Mar 2020 17:48:59 -0500 Subject: [PATCH] plugin: Rename the main method of hooks from `check` to `run`. This will be more appropriate when we have hooks that do more than check metadata. --- conservancy_beancount/plugin/__init__.py | 4 ++-- conservancy_beancount/plugin/core.py | 2 +- tests/test_meta_expenseAllocation.py | 14 +++++++------- tests/test_meta_taxImplication.py | 14 +++++++------- tests/test_plugin_run.py | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/conservancy_beancount/plugin/__init__.py b/conservancy_beancount/plugin/__init__.py index 217212a..4cbf473 100644 --- a/conservancy_beancount/plugin/__init__.py +++ b/conservancy_beancount/plugin/__init__.py @@ -39,10 +39,10 @@ def run(entries, options_map, config): for entry in entries: entry_type = type(entry).__name__ for hook in hooks[entry_type]: - errors.extend(hook.check(entry)) + errors.extend(hook.run(entry)) if entry_type == 'Transaction': for post in entry.postings: for hook in hooks['Posting']: - errors.extend(hook.check(entry, post)) + errors.extend(hook.run(entry, post)) return entries, errors diff --git a/conservancy_beancount/plugin/core.py b/conservancy_beancount/plugin/core.py index d3cb6a8..4895c05 100644 --- a/conservancy_beancount/plugin/core.py +++ b/conservancy_beancount/plugin/core.py @@ -93,7 +93,7 @@ class PostingChecker: ok = ok and re.search(self.ACCOUNTS, post.account) return ok - def check(self, txn, post): + def run(self, txn, post): errors = [] if not self._should_check(txn, post): return errors diff --git a/tests/test_meta_expenseAllocation.py b/tests/test_meta_expenseAllocation.py index b5578f1..33240dc 100644 --- a/tests/test_meta_expenseAllocation.py +++ b/tests/test_meta_expenseAllocation.py @@ -42,7 +42,7 @@ def test_valid_values_on_postings(src_value, set_value): ('Expenses:General', 25, {'expenseAllocation': src_value}), ]) checker = meta_expense_allocation.MetaExpenseAllocation() - errors = checker.check(txn, txn.postings[-1]) + errors = checker.run(txn, txn.postings[-1]) assert not errors assert txn.postings[-1].meta.get('expenseAllocation') == set_value @@ -53,7 +53,7 @@ def test_invalid_values_on_postings(src_value): ('Expenses:General', 25, {'expenseAllocation': src_value}), ]) checker = meta_expense_allocation.MetaExpenseAllocation() - errors = checker.check(txn, txn.postings[-1]) + errors = checker.run(txn, txn.postings[-1]) assert errors @pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items()) @@ -63,7 +63,7 @@ def test_valid_values_on_transactions(src_value, set_value): ('Expenses:General', 25), ]) checker = meta_expense_allocation.MetaExpenseAllocation() - errors = checker.check(txn, txn.postings[-1]) + errors = checker.run(txn, txn.postings[-1]) assert not errors assert txn.postings[-1].meta.get('expenseAllocation') == set_value @@ -74,7 +74,7 @@ def test_invalid_values_on_transactions(src_value): ('Expenses:General', 25), ]) checker = meta_expense_allocation.MetaExpenseAllocation() - errors = checker.check(txn, txn.postings[-1]) + errors = checker.run(txn, txn.postings[-1]) assert errors @pytest.mark.parametrize('account', [ @@ -90,7 +90,7 @@ def test_non_expense_accounts_skipped(account): ('Expenses:General', 25, {'expenseAllocation': 'program'}), ]) checker = meta_expense_allocation.MetaExpenseAllocation() - errors = checker.check(txn, txn.postings[0]) + errors = checker.run(txn, txn.postings[0]) assert not errors @pytest.mark.parametrize('account,set_value', [ @@ -106,7 +106,7 @@ def test_default_values(account, set_value): (account, 25), ]) checker = meta_expense_allocation.MetaExpenseAllocation() - errors = checker.check(txn, txn.postings[-1]) + errors = checker.run(txn, txn.postings[-1]) assert not errors assert txn.postings[-1].meta['expenseAllocation'] == set_value @@ -123,7 +123,7 @@ def test_default_value_set_in_date_range(date, set_value): ('Expenses:General', 25), ]) checker = meta_expense_allocation.MetaExpenseAllocation() - errors = checker.check(txn, txn.postings[-1]) + errors = checker.run(txn, txn.postings[-1]) assert not errors got_value = (txn.postings[-1].meta or {}).get('expenseAllocation') assert bool(got_value) == bool(set_value) diff --git a/tests/test_meta_taxImplication.py b/tests/test_meta_taxImplication.py index 1b1cf8a..fe2a794 100644 --- a/tests/test_meta_taxImplication.py +++ b/tests/test_meta_taxImplication.py @@ -54,7 +54,7 @@ def test_valid_values_on_postings(src_value, set_value): ('Assets:Cash', -25, {'taxImplication': src_value}), ]) checker = meta_tax_implication.MetaTaxImplication() - errors = checker.check(txn, txn.postings[-1]) + errors = checker.run(txn, txn.postings[-1]) assert not errors assert txn.postings[-1].meta.get('taxImplication') == set_value @@ -65,7 +65,7 @@ def test_invalid_values_on_postings(src_value): ('Assets:Cash', -25, {'taxImplication': src_value}), ]) checker = meta_tax_implication.MetaTaxImplication() - errors = checker.check(txn, txn.postings[-1]) + errors = checker.run(txn, txn.postings[-1]) assert errors @pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items()) @@ -75,7 +75,7 @@ def test_valid_values_on_transactions(src_value, set_value): ('Assets:Cash', -25), ]) checker = meta_tax_implication.MetaTaxImplication() - errors = checker.check(txn, txn.postings[-1]) + errors = checker.run(txn, txn.postings[-1]) assert not errors assert txn.postings[-1].meta.get('taxImplication') == set_value @@ -86,7 +86,7 @@ def test_invalid_values_on_transactions(src_value): ('Assets:Cash', -25), ]) checker = meta_tax_implication.MetaTaxImplication() - errors = checker.check(txn, txn.postings[-1]) + errors = checker.run(txn, txn.postings[-1]) assert errors @pytest.mark.parametrize('account', [ @@ -100,7 +100,7 @@ def test_non_asset_accounts_skipped(account): ('Assets:Cash', -25, {'taxImplication': 'USA-Corporation'}), ]) checker = meta_tax_implication.MetaTaxImplication() - errors = checker.check(txn, txn.postings[0]) + errors = checker.run(txn, txn.postings[0]) assert not errors def test_asset_credits_skipped(): @@ -109,7 +109,7 @@ def test_asset_credits_skipped(): ('Assets:Cash', 25), ]) checker = meta_tax_implication.MetaTaxImplication() - errors = checker.check(txn, txn.postings[-1]) + errors = checker.run(txn, txn.postings[-1]) assert not errors assert not txn.postings[-1].meta @@ -126,5 +126,5 @@ def test_default_value_set_in_date_range(date, need_value): ('Assets:Cash', -25), ]) checker = meta_tax_implication.MetaTaxImplication() - errors = checker.check(txn, txn.postings[-1]) + errors = checker.run(txn, txn.postings[-1]) assert bool(errors) == bool(need_value) diff --git a/tests/test_plugin_run.py b/tests/test_plugin_run.py index 731cb68..3cdb352 100644 --- a/tests/test_plugin_run.py +++ b/tests/test_plugin_run.py @@ -28,7 +28,7 @@ class TransactionCounter: def __init__(self): self.counter = 0 - def check(self, txn): + def run(self, txn): self.counter += 1 return () @@ -36,8 +36,8 @@ class TransactionCounter: class PostingCounter(TransactionCounter): HOOK_GROUPS = frozenset(['Posting']) - def check(self, txn, post): - return super().check(txn) + def run(self, txn, post): + return super().run(txn) def test_with_multiple_hooks():