Changeset - c9ff4ab74617
[Not reviewed]
2 3 2
Brett Smith - 4 years ago 2020-03-15 14:36:49
brettcsmith@brettcsmith.org
plugin: Settle on words-with-dashes metadata keys.
5 files changed with 29 insertions and 25 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/plugin/meta_expense_allocation.py
Show inline comments
 
"""meta_expense_allocation - Validate expenseAllocation metadata"""
 
"""meta_expense_allocation - Validate expense-allocation metadata"""
 
# Copyright © 2020  Brett Smith
...
 
@@ -20,3 +20,3 @@ class MetaExpenseAllocation(core.PostingChecker):
 
    ACCOUNTS = ('Expenses:',)
 
    METADATA_KEY = 'expenseAllocation'
 
    METADATA_KEY = 'expense-allocation'
 
    VALUES_ENUM = core.MetadataEnum(METADATA_KEY, {
conservancy_beancount/plugin/meta_tax_implication.py
Show inline comments
 
"""meta_tax_implication - Validate taxImplication metadata"""
 
"""meta_tax_implication - Validate tax-implication metadata"""
 
# Copyright © 2020  Brett Smith
...
 
@@ -24,3 +24,3 @@ class MetaTaxImplication(core.PostingChecker):
 
    ACCOUNTS = ('Assets:',)
 
    METADATA_KEY = 'taxImplication'
 
    METADATA_KEY = 'tax-implication'
 
    VALUES_ENUM = core.MetadataEnum(METADATA_KEY, [
tests/test_meta_expense_allocation.py
Show inline comments
 
file renamed from tests/test_meta_expenseAllocation.py to tests/test_meta_expense_allocation.py
 
"""Test handling of expenseAllocation metadata"""
 
"""Test handling of expense-allocation metadata"""
 
# Copyright © 2020  Brett Smith
...
 
@@ -37,2 +37,4 @@ INVALID_VALUES = {
 

	
 
TEST_KEY = 'expense-allocation'
 

	
 
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items())
...
 
@@ -41,3 +43,3 @@ def test_valid_values_on_postings(src_value, set_value):
 
        ('Assets:Cash', -25),
 
        ('Expenses:General', 25, {'expenseAllocation': src_value}),
 
        ('Expenses:General', 25, {TEST_KEY: src_value}),
 
    ])
...
 
@@ -46,3 +48,3 @@ def test_valid_values_on_postings(src_value, set_value):
 
    assert not errors
 
    assert txn.postings[-1].meta.get('expenseAllocation') == set_value
 
    assert txn.postings[-1].meta.get(TEST_KEY) == set_value
 

	
...
 
@@ -52,3 +54,3 @@ def test_invalid_values_on_postings(src_value):
 
        ('Assets:Cash', -25),
 
        ('Expenses:General', 25, {'expenseAllocation': src_value}),
 
        ('Expenses:General', 25, {TEST_KEY: src_value}),
 
    ])
...
 
@@ -60,3 +62,3 @@ def test_invalid_values_on_postings(src_value):
 
def test_valid_values_on_transactions(src_value, set_value):
 
    txn = testutil.Transaction(expenseAllocation=src_value, postings=[
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
 
        ('Assets:Cash', -25),
...
 
@@ -67,3 +69,3 @@ def test_valid_values_on_transactions(src_value, set_value):
 
    assert not errors
 
    assert txn.postings[-1].meta.get('expenseAllocation') == set_value
 
    assert txn.postings[-1].meta.get(TEST_KEY) == set_value
 

	
...
 
@@ -71,3 +73,3 @@ def test_valid_values_on_transactions(src_value, set_value):
 
def test_invalid_values_on_transactions(src_value):
 
    txn = testutil.Transaction(expenseAllocation=src_value, postings=[
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
 
        ('Assets:Cash', -25),
...
 
@@ -89,3 +91,3 @@ def test_non_expense_accounts_skipped(account):
 
        (account, -25),
 
        ('Expenses:General', 25, {'expenseAllocation': 'program'}),
 
        ('Expenses:General', 25, {TEST_KEY: 'program'}),
 
    ])
...
 
@@ -110,3 +112,3 @@ def test_default_values(account, set_value):
 
    assert not errors
 
    assert txn.postings[-1].meta['expenseAllocation'] == set_value
 
    assert txn.postings[-1].meta[TEST_KEY] == set_value
 

	
...
 
@@ -127,3 +129,3 @@ def test_default_value_set_in_date_range(date, set_value):
 
    assert not errors
 
    got_value = (txn.postings[-1].meta or {}).get('expenseAllocation')
 
    got_value = (txn.postings[-1].meta or {}).get(TEST_KEY)
 
    assert bool(got_value) == bool(set_value)
tests/test_meta_tax_implication.py
Show inline comments
 
file renamed from tests/test_meta_taxImplication.py to tests/test_meta_tax_implication.py
 
"""Test handling of taxImplication metadata"""
 
"""Test handling of tax-implication metadata"""
 
# Copyright © 2020  Brett Smith
...
 
@@ -49,2 +49,4 @@ INVALID_VALUES = {
 

	
 
TEST_KEY = 'tax-implication'
 

	
 
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items())
...
 
@@ -53,3 +55,3 @@ def test_valid_values_on_postings(src_value, set_value):
 
        ('Accrued:AccountsPayable', 25),
 
        ('Assets:Cash', -25, {'taxImplication': src_value}),
 
        ('Assets:Cash', -25, {TEST_KEY: src_value}),
 
    ])
...
 
@@ -58,3 +60,3 @@ def test_valid_values_on_postings(src_value, set_value):
 
    assert not errors
 
    assert txn.postings[-1].meta.get('taxImplication') == set_value
 
    assert txn.postings[-1].meta.get(TEST_KEY) == set_value
 

	
...
 
@@ -64,3 +66,3 @@ def test_invalid_values_on_postings(src_value):
 
        ('Accrued:AccountsPayable', 25),
 
        ('Assets:Cash', -25, {'taxImplication': src_value}),
 
        ('Assets:Cash', -25, {TEST_KEY: src_value}),
 
    ])
...
 
@@ -72,3 +74,3 @@ def test_invalid_values_on_postings(src_value):
 
def test_valid_values_on_transactions(src_value, set_value):
 
    txn = testutil.Transaction(taxImplication=src_value, postings=[
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
 
        ('Accrued:AccountsPayable', 25),
...
 
@@ -79,3 +81,3 @@ def test_valid_values_on_transactions(src_value, set_value):
 
    assert not errors
 
    assert txn.postings[-1].meta.get('taxImplication') == set_value
 
    assert txn.postings[-1].meta.get(TEST_KEY) == set_value
 

	
...
 
@@ -83,3 +85,3 @@ def test_valid_values_on_transactions(src_value, set_value):
 
def test_invalid_values_on_transactions(src_value):
 
    txn = testutil.Transaction(taxImplication=src_value, postings=[
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
 
        ('Accrued:AccountsPayable', 25),
...
 
@@ -99,3 +101,3 @@ def test_non_asset_accounts_skipped(account):
 
        (account, 25),
 
        ('Assets:Cash', -25, {'taxImplication': 'USA-Corporation'}),
 
        ('Assets:Cash', -25, {TEST_KEY: 'USA-Corporation'}),
 
    ])
tests/test_plugin_HookRegistry.py
Show inline comments
...
 
@@ -33,3 +33,3 @@ def test_default_registrations():
 
def test_exclude_single():
 
    hooks = plugin.HOOK_REGISTRY.group_by_directive('-expenseAllocation')
 
    hooks = plugin.HOOK_REGISTRY.group_by_directive('-expense-allocation')
 
    post_hook_names = hook_names(hooks, 'Posting')
...
 
@@ -39,3 +39,3 @@ def test_exclude_single():
 
def test_exclude_group_then_include_single():
 
    hooks = plugin.HOOK_REGISTRY.group_by_directive('-metadata expenseAllocation')
 
    hooks = plugin.HOOK_REGISTRY.group_by_directive('-metadata expense-allocation')
 
    post_hook_names = hook_names(hooks, 'Posting')
...
 
@@ -45,3 +45,3 @@ def test_exclude_group_then_include_single():
 
def test_include_group_then_exclude_single():
 
    hooks = plugin.HOOK_REGISTRY.group_by_directive('metadata -taxImplication')
 
    hooks = plugin.HOOK_REGISTRY.group_by_directive('metadata -tax-implication')
 
    post_hook_names = hook_names(hooks, 'Posting')
0 comments (0 inline, 0 general)