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:
		
							parent
							
								
									53329c7a23
								
							
						
					
					
						commit
						e9e2bb9b00
					
				
					 5 changed files with 20 additions and 20 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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():
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue