Changeset - 547ae657808f
[Not reviewed]
0 6 0
Brett Smith - 4 years ago 2020-03-08 15:32:03
brettcsmith@brettcsmith.org
plugin.core: _meta_set properly handles when post.meta is None.

post is a NamedTuple, so attribute assignment is not allowed.
Instead we have to construct a whole new Posting.
6 files changed with 23 insertions and 20 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/plugin/__init__.py
Show inline comments
...
 
@@ -88,5 +88,5 @@ def run(entries, options_map, config='', hook_registry=HOOK_REGISTRY):
 
        if entry_type == 'Transaction':
 
            for post in entry.postings:
 
            for index, post in enumerate(entry.postings):
 
                for hook in hooks['Posting']:
 
                    errors.extend(hook.run(entry, post))
 
                    errors.extend(hook.run(entry, post, index))
 
    return entries, errors
conservancy_beancount/plugin/core.py
Show inline comments
...
 
@@ -134,6 +134,7 @@ class PostingChecker:
 

	
 
    def _meta_set(self, post, key, value):
 
    def _meta_set(self, txn, post, post_index, key, value):
 
        if post.meta is None:
 
            post.meta = {}
 
        post.meta[key] = value
 
            txn.postings[post_index] = Posting(*post[:5], {key: value})
 
        else:
 
            post.meta[key] = value
 

	
tests/test_meta_expenseAllocation.py
Show inline comments
...
 
@@ -44,3 +44,3 @@ def test_valid_values_on_postings(src_value, set_value):
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = checker.run(txn, txn.postings[-1])
 
    errors = checker.run(txn, txn.postings[-1], -1)
 
    assert not errors
...
 
@@ -55,3 +55,3 @@ def test_invalid_values_on_postings(src_value):
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = checker.run(txn, txn.postings[-1])
 
    errors = checker.run(txn, txn.postings[-1], -1)
 
    assert errors
...
 
@@ -65,3 +65,3 @@ def test_valid_values_on_transactions(src_value, set_value):
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = checker.run(txn, txn.postings[-1])
 
    errors = checker.run(txn, txn.postings[-1], -1)
 
    assert not errors
...
 
@@ -76,3 +76,3 @@ def test_invalid_values_on_transactions(src_value):
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = checker.run(txn, txn.postings[-1])
 
    errors = checker.run(txn, txn.postings[-1], -1)
 
    assert errors
...
 
@@ -92,3 +92,3 @@ def test_non_expense_accounts_skipped(account):
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = checker.run(txn, txn.postings[0])
 
    errors = checker.run(txn, txn.postings[0], 0)
 
    assert not errors
...
 
@@ -108,3 +108,3 @@ def test_default_values(account, set_value):
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = checker.run(txn, txn.postings[-1])
 
    errors = checker.run(txn, txn.postings[-1], -1)
 
    assert not errors
...
 
@@ -125,3 +125,3 @@ def test_default_value_set_in_date_range(date, set_value):
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = checker.run(txn, txn.postings[-1])
 
    errors = checker.run(txn, txn.postings[-1], -1)
 
    assert not errors
tests/test_meta_taxImplication.py
Show inline comments
...
 
@@ -56,3 +56,3 @@ def test_valid_values_on_postings(src_value, set_value):
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = checker.run(txn, txn.postings[-1])
 
    errors = checker.run(txn, txn.postings[-1], -1)
 
    assert not errors
...
 
@@ -67,3 +67,3 @@ def test_invalid_values_on_postings(src_value):
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = checker.run(txn, txn.postings[-1])
 
    errors = checker.run(txn, txn.postings[-1], -1)
 
    assert errors
...
 
@@ -77,3 +77,3 @@ def test_valid_values_on_transactions(src_value, set_value):
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = checker.run(txn, txn.postings[-1])
 
    errors = checker.run(txn, txn.postings[-1], -1)
 
    assert not errors
...
 
@@ -88,3 +88,3 @@ def test_invalid_values_on_transactions(src_value):
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = checker.run(txn, txn.postings[-1])
 
    errors = checker.run(txn, txn.postings[-1], -1)
 
    assert errors
...
 
@@ -102,3 +102,3 @@ def test_non_asset_accounts_skipped(account):
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = checker.run(txn, txn.postings[0])
 
    errors = checker.run(txn, txn.postings[0], 0)
 
    assert not errors
...
 
@@ -111,3 +111,3 @@ def test_asset_credits_skipped():
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = checker.run(txn, txn.postings[-1])
 
    errors = checker.run(txn, txn.postings[-1], -1)
 
    assert not errors
...
 
@@ -128,3 +128,3 @@ def test_default_value_set_in_date_range(date, need_value):
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = checker.run(txn, txn.postings[-1])
 
    errors = checker.run(txn, txn.postings[-1], -1)
 
    assert bool(errors) == bool(need_value)
tests/test_plugin_run.py
Show inline comments
...
 
@@ -37,3 +37,3 @@ class PostingCounter(TransactionCounter):
 

	
 
    def run(self, txn, post):
 
    def run(self, txn, post, post_index):
 
        return ['post:{}'.format(id(post))]
tests/testutil.py
Show inline comments
...
 
@@ -35,2 +35,4 @@ def Posting(account, number,
 
            **meta):
 
    if not meta:
 
        meta = None
 
    return bc_data.Posting(
0 comments (0 inline, 0 general)