diff --git a/tests/test_plugin_run.py b/tests/test_plugin_run.py index 3cdb3522b085d5de944871a045f331d66097f6e4..957e280a653e5ddf745c72f76b8e5539c6588338 100644 --- a/tests/test_plugin_run.py +++ b/tests/test_plugin_run.py @@ -23,22 +23,25 @@ from conservancy_beancount import plugin CONFIG_MAP = {} class TransactionCounter: - HOOK_GROUPS = frozenset(['Transaction']) - - def __init__(self): - self.counter = 0 + HOOK_GROUPS = frozenset(['Transaction', 'counter']) def run(self, txn): - self.counter += 1 - return () + return ['txn:{}'.format(id(txn))] class PostingCounter(TransactionCounter): - HOOK_GROUPS = frozenset(['Posting']) + HOOK_GROUPS = frozenset(['Posting', 'counter']) def run(self, txn, post): - return super().run(txn) + return ['post:{}'.format(id(post))] + +def map_errors(errors): + retval = {} + for errkey in errors: + key, _, errid = errkey.partition(':') + retval.setdefault(key, set()).add(errid) + return retval def test_with_multiple_hooks(): txn_counter = TransactionCounter() @@ -55,9 +58,9 @@ def test_with_multiple_hooks(): ] out_entries, errors = plugin.run(in_entries, CONFIG_MAP, [txn_counter, post_counter]) assert len(out_entries) == 2 - assert len(errors) == 0 - assert txn_counter.counter == 2 - assert post_counter.counter == 4 + errmap = map_errors(errors) + assert len(errmap.get('txn', '')) == 2 + assert len(errmap.get('post', '')) == 4 def test_with_posting_hooks_only(): post_counter = PostingCounter() @@ -73,5 +76,6 @@ def test_with_posting_hooks_only(): ] out_entries, errors = plugin.run(in_entries, CONFIG_MAP, [post_counter]) assert len(out_entries) == 2 - assert len(errors) == 0 - assert post_counter.counter == 4 + errmap = map_errors(errors) + assert len(errmap.get('txn', '')) == 0 + assert len(errmap.get('post', '')) == 4