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.
This commit is contained in:
Brett Smith 2020-03-05 17:48:59 -05:00
parent 53329c7a23
commit e9e2bb9b00
5 changed files with 20 additions and 20 deletions

View file

@ -39,10 +39,10 @@ def run(entries, options_map, config):
for entry in entries: for entry in entries:
entry_type = type(entry).__name__ entry_type = type(entry).__name__
for hook in hooks[entry_type]: for hook in hooks[entry_type]:
errors.extend(hook.check(entry)) errors.extend(hook.run(entry))
if entry_type == 'Transaction': if entry_type == 'Transaction':
for post in entry.postings: for post in entry.postings:
for hook in hooks['Posting']: for hook in hooks['Posting']:
errors.extend(hook.check(entry, post)) errors.extend(hook.run(entry, post))
return entries, errors return entries, errors

View file

@ -93,7 +93,7 @@ class PostingChecker:
ok = ok and re.search(self.ACCOUNTS, post.account) ok = ok and re.search(self.ACCOUNTS, post.account)
return ok return ok
def check(self, txn, post): def run(self, txn, post):
errors = [] errors = []
if not self._should_check(txn, post): if not self._should_check(txn, post):
return errors return errors

View file

@ -42,7 +42,7 @@ def test_valid_values_on_postings(src_value, set_value):
('Expenses:General', 25, {'expenseAllocation': src_value}), ('Expenses:General', 25, {'expenseAllocation': src_value}),
]) ])
checker = meta_expense_allocation.MetaExpenseAllocation() checker = meta_expense_allocation.MetaExpenseAllocation()
errors = checker.check(txn, txn.postings[-1]) errors = checker.run(txn, txn.postings[-1])
assert not errors assert not errors
assert txn.postings[-1].meta.get('expenseAllocation') == set_value 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}), ('Expenses:General', 25, {'expenseAllocation': src_value}),
]) ])
checker = meta_expense_allocation.MetaExpenseAllocation() checker = meta_expense_allocation.MetaExpenseAllocation()
errors = checker.check(txn, txn.postings[-1]) errors = checker.run(txn, txn.postings[-1])
assert errors assert errors
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items()) @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), ('Expenses:General', 25),
]) ])
checker = meta_expense_allocation.MetaExpenseAllocation() checker = meta_expense_allocation.MetaExpenseAllocation()
errors = checker.check(txn, txn.postings[-1]) errors = checker.run(txn, txn.postings[-1])
assert not errors assert not errors
assert txn.postings[-1].meta.get('expenseAllocation') == set_value assert txn.postings[-1].meta.get('expenseAllocation') == set_value
@ -74,7 +74,7 @@ def test_invalid_values_on_transactions(src_value):
('Expenses:General', 25), ('Expenses:General', 25),
]) ])
checker = meta_expense_allocation.MetaExpenseAllocation() checker = meta_expense_allocation.MetaExpenseAllocation()
errors = checker.check(txn, txn.postings[-1]) errors = checker.run(txn, txn.postings[-1])
assert errors assert errors
@pytest.mark.parametrize('account', [ @pytest.mark.parametrize('account', [
@ -90,7 +90,7 @@ def test_non_expense_accounts_skipped(account):
('Expenses:General', 25, {'expenseAllocation': 'program'}), ('Expenses:General', 25, {'expenseAllocation': 'program'}),
]) ])
checker = meta_expense_allocation.MetaExpenseAllocation() checker = meta_expense_allocation.MetaExpenseAllocation()
errors = checker.check(txn, txn.postings[0]) errors = checker.run(txn, txn.postings[0])
assert not errors assert not errors
@pytest.mark.parametrize('account,set_value', [ @pytest.mark.parametrize('account,set_value', [
@ -106,7 +106,7 @@ def test_default_values(account, set_value):
(account, 25), (account, 25),
]) ])
checker = meta_expense_allocation.MetaExpenseAllocation() checker = meta_expense_allocation.MetaExpenseAllocation()
errors = checker.check(txn, txn.postings[-1]) errors = checker.run(txn, txn.postings[-1])
assert not errors assert not errors
assert txn.postings[-1].meta['expenseAllocation'] == set_value 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), ('Expenses:General', 25),
]) ])
checker = meta_expense_allocation.MetaExpenseAllocation() checker = meta_expense_allocation.MetaExpenseAllocation()
errors = checker.check(txn, txn.postings[-1]) errors = checker.run(txn, txn.postings[-1])
assert not errors assert not errors
got_value = (txn.postings[-1].meta or {}).get('expenseAllocation') got_value = (txn.postings[-1].meta or {}).get('expenseAllocation')
assert bool(got_value) == bool(set_value) assert bool(got_value) == bool(set_value)

View file

@ -54,7 +54,7 @@ def test_valid_values_on_postings(src_value, set_value):
('Assets:Cash', -25, {'taxImplication': src_value}), ('Assets:Cash', -25, {'taxImplication': src_value}),
]) ])
checker = meta_tax_implication.MetaTaxImplication() checker = meta_tax_implication.MetaTaxImplication()
errors = checker.check(txn, txn.postings[-1]) errors = checker.run(txn, txn.postings[-1])
assert not errors assert not errors
assert txn.postings[-1].meta.get('taxImplication') == set_value 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}), ('Assets:Cash', -25, {'taxImplication': src_value}),
]) ])
checker = meta_tax_implication.MetaTaxImplication() checker = meta_tax_implication.MetaTaxImplication()
errors = checker.check(txn, txn.postings[-1]) errors = checker.run(txn, txn.postings[-1])
assert errors assert errors
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items()) @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), ('Assets:Cash', -25),
]) ])
checker = meta_tax_implication.MetaTaxImplication() checker = meta_tax_implication.MetaTaxImplication()
errors = checker.check(txn, txn.postings[-1]) errors = checker.run(txn, txn.postings[-1])
assert not errors assert not errors
assert txn.postings[-1].meta.get('taxImplication') == set_value assert txn.postings[-1].meta.get('taxImplication') == set_value
@ -86,7 +86,7 @@ def test_invalid_values_on_transactions(src_value):
('Assets:Cash', -25), ('Assets:Cash', -25),
]) ])
checker = meta_tax_implication.MetaTaxImplication() checker = meta_tax_implication.MetaTaxImplication()
errors = checker.check(txn, txn.postings[-1]) errors = checker.run(txn, txn.postings[-1])
assert errors assert errors
@pytest.mark.parametrize('account', [ @pytest.mark.parametrize('account', [
@ -100,7 +100,7 @@ def test_non_asset_accounts_skipped(account):
('Assets:Cash', -25, {'taxImplication': 'USA-Corporation'}), ('Assets:Cash', -25, {'taxImplication': 'USA-Corporation'}),
]) ])
checker = meta_tax_implication.MetaTaxImplication() checker = meta_tax_implication.MetaTaxImplication()
errors = checker.check(txn, txn.postings[0]) errors = checker.run(txn, txn.postings[0])
assert not errors assert not errors
def test_asset_credits_skipped(): def test_asset_credits_skipped():
@ -109,7 +109,7 @@ def test_asset_credits_skipped():
('Assets:Cash', 25), ('Assets:Cash', 25),
]) ])
checker = meta_tax_implication.MetaTaxImplication() checker = meta_tax_implication.MetaTaxImplication()
errors = checker.check(txn, txn.postings[-1]) errors = checker.run(txn, txn.postings[-1])
assert not errors assert not errors
assert not txn.postings[-1].meta assert not txn.postings[-1].meta
@ -126,5 +126,5 @@ def test_default_value_set_in_date_range(date, need_value):
('Assets:Cash', -25), ('Assets:Cash', -25),
]) ])
checker = meta_tax_implication.MetaTaxImplication() 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) assert bool(errors) == bool(need_value)

View file

@ -28,7 +28,7 @@ class TransactionCounter:
def __init__(self): def __init__(self):
self.counter = 0 self.counter = 0
def check(self, txn): def run(self, txn):
self.counter += 1 self.counter += 1
return () return ()
@ -36,8 +36,8 @@ class TransactionCounter:
class PostingCounter(TransactionCounter): class PostingCounter(TransactionCounter):
HOOK_GROUPS = frozenset(['Posting']) HOOK_GROUPS = frozenset(['Posting'])
def check(self, txn, post): def run(self, txn, post):
return super().check(txn) return super().run(txn)
def test_with_multiple_hooks(): def test_with_multiple_hooks():