From c9ff4ab74617378eef70dd9bb334bfe766c9d1d4 2020-03-15 14:36:49 From: Brett Smith Date: 2020-03-15 14:36:49 Subject: [PATCH] plugin: Settle on words-with-dashes metadata keys. --- diff --git a/conservancy_beancount/plugin/meta_expense_allocation.py b/conservancy_beancount/plugin/meta_expense_allocation.py index 603b2d70b4041a8540425e3b1c5faa4dc8ee125f..1f09cce60e631d7ca0a13b015b20149427eaee8e 100644 --- a/conservancy_beancount/plugin/meta_expense_allocation.py +++ b/conservancy_beancount/plugin/meta_expense_allocation.py @@ -1,4 +1,4 @@ -"""meta_expense_allocation - Validate expenseAllocation metadata""" +"""meta_expense_allocation - Validate expense-allocation metadata""" # Copyright © 2020 Brett Smith # # This program is free software: you can redistribute it and/or modify @@ -18,7 +18,7 @@ from . import core class MetaExpenseAllocation(core.PostingChecker): ACCOUNTS = ('Expenses:',) - METADATA_KEY = 'expenseAllocation' + METADATA_KEY = 'expense-allocation' VALUES_ENUM = core.MetadataEnum(METADATA_KEY, { 'administration', 'fundraising', diff --git a/conservancy_beancount/plugin/meta_tax_implication.py b/conservancy_beancount/plugin/meta_tax_implication.py index fb6226d2ac18c3f265d0f5d0bc4026c6f70d7cc7..c683e2db7903ee817e018bf465c83340da1fddf9 100644 --- a/conservancy_beancount/plugin/meta_tax_implication.py +++ b/conservancy_beancount/plugin/meta_tax_implication.py @@ -1,4 +1,4 @@ -"""meta_tax_implication - Validate taxImplication metadata""" +"""meta_tax_implication - Validate tax-implication metadata""" # Copyright © 2020 Brett Smith # # This program is free software: you can redistribute it and/or modify @@ -22,7 +22,7 @@ DEFAULT_STOP_AMOUNT = decimal.Decimal(0) class MetaTaxImplication(core.PostingChecker): ACCOUNTS = ('Assets:',) - METADATA_KEY = 'taxImplication' + METADATA_KEY = 'tax-implication' VALUES_ENUM = core.MetadataEnum(METADATA_KEY, [ '1099', 'Accountant-Advises-No-1099', diff --git a/tests/test_meta_expenseAllocation.py b/tests/test_meta_expense_allocation.py similarity index 85% rename from tests/test_meta_expenseAllocation.py rename to tests/test_meta_expense_allocation.py index 2c01e41e2d7976c83d809596d83110cb9db00666..f1e1a9dd4dd094d067a28f5b920271205ccf02d1 100644 --- a/tests/test_meta_expenseAllocation.py +++ b/tests/test_meta_expense_allocation.py @@ -1,4 +1,4 @@ -"""Test handling of expenseAllocation metadata""" +"""Test handling of expense-allocation metadata""" # Copyright © 2020 Brett Smith # # This program is free software: you can redistribute it and/or modify @@ -35,22 +35,24 @@ INVALID_VALUES = { '', } +TEST_KEY = 'expense-allocation' + @pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items()) def test_valid_values_on_postings(src_value, set_value): txn = testutil.Transaction(postings=[ ('Assets:Cash', -25), - ('Expenses:General', 25, {'expenseAllocation': src_value}), + ('Expenses:General', 25, {TEST_KEY: src_value}), ]) checker = meta_expense_allocation.MetaExpenseAllocation() errors = checker.run(txn, txn.postings[-1], -1) assert not errors - assert txn.postings[-1].meta.get('expenseAllocation') == set_value + assert txn.postings[-1].meta.get(TEST_KEY) == set_value @pytest.mark.parametrize('src_value', INVALID_VALUES) def test_invalid_values_on_postings(src_value): txn = testutil.Transaction(postings=[ ('Assets:Cash', -25), - ('Expenses:General', 25, {'expenseAllocation': src_value}), + ('Expenses:General', 25, {TEST_KEY: src_value}), ]) checker = meta_expense_allocation.MetaExpenseAllocation() errors = checker.run(txn, txn.postings[-1], -1) @@ -58,18 +60,18 @@ def test_invalid_values_on_postings(src_value): @pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items()) 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), ('Expenses:General', 25), ]) checker = meta_expense_allocation.MetaExpenseAllocation() errors = checker.run(txn, txn.postings[-1], -1) assert not errors - assert txn.postings[-1].meta.get('expenseAllocation') == set_value + assert txn.postings[-1].meta.get(TEST_KEY) == set_value @pytest.mark.parametrize('src_value', INVALID_VALUES) 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), ('Expenses:General', 25), ]) @@ -87,7 +89,7 @@ def test_invalid_values_on_transactions(src_value): def test_non_expense_accounts_skipped(account): txn = testutil.Transaction(postings=[ (account, -25), - ('Expenses:General', 25, {'expenseAllocation': 'program'}), + ('Expenses:General', 25, {TEST_KEY: 'program'}), ]) checker = meta_expense_allocation.MetaExpenseAllocation() errors = checker.run(txn, txn.postings[0], 0) @@ -108,7 +110,7 @@ def test_default_values(account, set_value): checker = meta_expense_allocation.MetaExpenseAllocation() errors = checker.run(txn, txn.postings[-1], -1) assert not errors - assert txn.postings[-1].meta['expenseAllocation'] == set_value + assert txn.postings[-1].meta[TEST_KEY] == set_value @pytest.mark.parametrize('date,set_value', [ (testutil.EXTREME_FUTURE_DATE, False), @@ -125,5 +127,5 @@ def test_default_value_set_in_date_range(date, set_value): checker = meta_expense_allocation.MetaExpenseAllocation() errors = checker.run(txn, txn.postings[-1], -1) 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) diff --git a/tests/test_meta_taxImplication.py b/tests/test_meta_tax_implication.py similarity index 88% rename from tests/test_meta_taxImplication.py rename to tests/test_meta_tax_implication.py index d745a164387f5db18966ebd39406d64a127bf6a4..94aa70a91a8dfbb8bc4f24d198c7a2189e02d716 100644 --- a/tests/test_meta_taxImplication.py +++ b/tests/test_meta_tax_implication.py @@ -1,4 +1,4 @@ -"""Test handling of taxImplication metadata""" +"""Test handling of tax-implication metadata""" # Copyright © 2020 Brett Smith # # This program is free software: you can redistribute it and/or modify @@ -47,22 +47,24 @@ INVALID_VALUES = { '', } +TEST_KEY = 'tax-implication' + @pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items()) def test_valid_values_on_postings(src_value, set_value): txn = testutil.Transaction(postings=[ ('Accrued:AccountsPayable', 25), - ('Assets:Cash', -25, {'taxImplication': src_value}), + ('Assets:Cash', -25, {TEST_KEY: src_value}), ]) checker = meta_tax_implication.MetaTaxImplication() errors = checker.run(txn, txn.postings[-1], -1) assert not errors - assert txn.postings[-1].meta.get('taxImplication') == set_value + assert txn.postings[-1].meta.get(TEST_KEY) == set_value @pytest.mark.parametrize('src_value', INVALID_VALUES) def test_invalid_values_on_postings(src_value): txn = testutil.Transaction(postings=[ ('Accrued:AccountsPayable', 25), - ('Assets:Cash', -25, {'taxImplication': src_value}), + ('Assets:Cash', -25, {TEST_KEY: src_value}), ]) checker = meta_tax_implication.MetaTaxImplication() errors = checker.run(txn, txn.postings[-1], -1) @@ -70,18 +72,18 @@ def test_invalid_values_on_postings(src_value): @pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items()) 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), ('Assets:Cash', -25), ]) checker = meta_tax_implication.MetaTaxImplication() errors = checker.run(txn, txn.postings[-1], -1) assert not errors - assert txn.postings[-1].meta.get('taxImplication') == set_value + assert txn.postings[-1].meta.get(TEST_KEY) == set_value @pytest.mark.parametrize('src_value', INVALID_VALUES) 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), ('Assets:Cash', -25), ]) @@ -97,7 +99,7 @@ def test_invalid_values_on_transactions(src_value): def test_non_asset_accounts_skipped(account): txn = testutil.Transaction(postings=[ (account, 25), - ('Assets:Cash', -25, {'taxImplication': 'USA-Corporation'}), + ('Assets:Cash', -25, {TEST_KEY: 'USA-Corporation'}), ]) checker = meta_tax_implication.MetaTaxImplication() errors = checker.run(txn, txn.postings[0], 0) diff --git a/tests/test_plugin_HookRegistry.py b/tests/test_plugin_HookRegistry.py index b7fd0b9521b6c461d0726c840e5203f0d2378bd3..6d899873a19af00d09e4a776c3a353f18653ff40 100644 --- a/tests/test_plugin_HookRegistry.py +++ b/tests/test_plugin_HookRegistry.py @@ -31,19 +31,19 @@ def test_default_registrations(): assert 'MetaTaxImplication' in post_hook_names 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') assert post_hook_names assert 'MetaExpenseAllocation' not in post_hook_names 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') assert 'MetaExpenseAllocation' in post_hook_names assert 'MetaTaxImplication' not in post_hook_names 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') assert 'MetaExpenseAllocation' in post_hook_names assert 'MetaTaxImplication' not in post_hook_names