Changeset - ce34554bd4ba
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-04-07 19:44:40
brettcsmith@brettcsmith.org
meta_payable_documentation: Don't check Liabilites:Payable:Vacation.
2 files changed with 32 insertions and 49 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/plugin/meta_payable_documentation.py
Show inline comments
...
 
@@ -28,3 +28,3 @@ class MetaPayableDocumentation(core._RequireLinksPostingMetadataHook):
 
    def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
 
        if post.account.is_under('Liabilities:Payable'):
 
        if post.account.is_under('Liabilities:Payable:Accounts'):
 
            return not post.is_credit()
tests/test_meta_payable_documentation.py
Show inline comments
...
 
@@ -25,7 +25,2 @@ from conservancy_beancount.plugin import meta_payable_documentation
 

	
 
ACCOUNTS = [
 
    'Liabilities:Payable:Accounts',
 
    'Liabilities:Payable:Vacation',
 
]
 

	
 
SUPPORTING_METADATA = [
...
 
@@ -43,4 +38,5 @@ NON_SUPPORTING_METADATA = [
 

	
 
TEST_ACCT = 'Liabilities:Payable:Accounts'
 
OTHER_ACCT = 'Expenses:Other'
 
MISSING_MSG = f"{{}} missing approval/contract".format
 
MISSING_MSG = f"{TEST_ACCT} missing approval/contract"
 

	
...
 
@@ -61,5 +57,5 @@ def seed_meta(support_values=testutil.NON_LINK_METADATA_STRINGS, **kwargs):
 

	
 
def wrong_type_message(acct, key, wrong_value):
 
def wrong_type_message(key, wrong_value):
 
    return  "{} has wrong type of {}: expected str but is a {}".format(
 
        acct,
 
        TEST_ACCT,
 
        key,
...
 
@@ -68,3 +64,3 @@ def wrong_type_message(acct, key, wrong_value):
 

	
 
def check(hook, expected, test_acct, other_acct=OTHER_ACCT, *,
 
def check(hook, expected, test_acct=TEST_ACCT, other_acct=OTHER_ACCT, *,
 
          txn_meta={}, post_meta={}, min_amt=10):
...
 
@@ -83,4 +79,3 @@ def check(hook, expected, test_acct, other_acct=OTHER_ACCT, *,
 

	
 
@pytest.mark.parametrize('acct,support_key,support_value', testutil.combine_values(
 
    ACCOUNTS,
 
@pytest.mark.parametrize('support_key,support_value', testutil.combine_values(
 
    SUPPORTING_METADATA,
...
 
@@ -88,9 +83,8 @@ def check(hook, expected, test_acct, other_acct=OTHER_ACCT, *,
 
))
 
def test_valid_docs_in_post(hook, acct, support_key, support_value):
 
def test_valid_docs_in_post(hook, support_key, support_value):
 
    meta = seed_meta()
 
    meta[support_key] = support_value
 
    check(hook, None, acct, post_meta=meta)
 
    check(hook, None, post_meta=meta)
 

	
 
@pytest.mark.parametrize('acct,support_key,support_value', testutil.combine_values(
 
    ACCOUNTS,
 
@pytest.mark.parametrize('support_key,support_value', testutil.combine_values(
 
    SUPPORTING_METADATA,
...
 
@@ -98,12 +92,9 @@ def test_valid_docs_in_post(hook, acct, support_key, support_value):
 
))
 
def test_valid_docs_in_txn(hook, acct, support_key, support_value):
 
def test_valid_docs_in_txn(hook, support_key, support_value):
 
    meta = seed_meta()
 
    meta[support_key] = support_value
 
    check(hook, None, acct, txn_meta=meta)
 
    check(hook, None, txn_meta=meta)
 

	
 
@pytest.mark.parametrize('acct,meta_type', testutil.combine_values(
 
    ACCOUNTS,
 
    ['post_meta', 'txn_meta'],
 
))
 
def test_no_valid_docs(hook, acct, meta_type):
 
@pytest.mark.parametrize('meta_type', ['post_meta', 'txn_meta'])
 
def test_no_valid_docs(hook, meta_type):
 
    meta = seed_meta()
...
 
@@ -113,19 +104,15 @@ def test_no_valid_docs(hook, acct, meta_type):
 
    ))
 
    check(hook, {MISSING_MSG(acct)}, acct, **{meta_type: meta})
 
    check(hook, {MISSING_MSG}, **{meta_type: meta})
 

	
 
@pytest.mark.parametrize('acct,meta_type', testutil.combine_values(
 
    ACCOUNTS,
 
    ['post_meta', 'txn_meta'],
 
))
 
def test_docs_all_bad_type(hook, acct, meta_type):
 
@pytest.mark.parametrize('meta_type', ['post_meta', 'txn_meta'])
 
def test_docs_all_bad_type(hook, meta_type):
 
    meta = seed_meta(testutil.NON_STRING_METADATA_VALUES)
 
    expected = {
 
        wrong_type_message(acct, key, value)
 
        wrong_type_message(key, value)
 
        for key, value in meta.items()
 
    }
 
    expected.add(MISSING_MSG(acct))
 
    check(hook, expected, acct, **{meta_type: meta})
 
    expected.add(MISSING_MSG)
 
    check(hook, expected, **{meta_type: meta})
 

	
 
@pytest.mark.parametrize('acct,support_key,support_value', testutil.combine_values(
 
    ACCOUNTS,
 
@pytest.mark.parametrize('support_key,support_value', testutil.combine_values(
 
    SUPPORTING_METADATA,
...
 
@@ -133,3 +120,3 @@ def test_docs_all_bad_type(hook, acct, meta_type):
 
))
 
def test_type_errors_reported_with_valid_post_docs(hook, acct, support_key, support_value):
 
def test_type_errors_reported_with_valid_post_docs(hook, support_key, support_value):
 
    meta = seed_meta(testutil.NON_STRING_METADATA_VALUES)
...
 
@@ -137,3 +124,3 @@ def test_type_errors_reported_with_valid_post_docs(hook, acct, support_key, supp
 
    expected = {
 
        wrong_type_message(acct, key, value)
 
        wrong_type_message(key, value)
 
        for key, value in meta.items()
...
 
@@ -141,6 +128,5 @@ def test_type_errors_reported_with_valid_post_docs(hook, acct, support_key, supp
 
    }
 
    check(hook, expected, acct, post_meta=meta)
 
    check(hook, expected, post_meta=meta)
 

	
 
@pytest.mark.parametrize('acct,support_key,support_value', testutil.combine_values(
 
    ACCOUNTS,
 
@pytest.mark.parametrize('support_key,support_value', testutil.combine_values(
 
    SUPPORTING_METADATA,
...
 
@@ -148,3 +134,3 @@ def test_type_errors_reported_with_valid_post_docs(hook, acct, support_key, supp
 
))
 
def test_type_errors_reported_with_valid_txn_docs(hook, acct, support_key, support_value):
 
def test_type_errors_reported_with_valid_txn_docs(hook, support_key, support_value):
 
    meta = seed_meta(testutil.NON_STRING_METADATA_VALUES)
...
 
@@ -152,3 +138,3 @@ def test_type_errors_reported_with_valid_txn_docs(hook, acct, support_key, suppo
 
    expected = {
 
        wrong_type_message(acct, key, value)
 
        wrong_type_message(key, value)
 
        for key, value in meta.items()
...
 
@@ -156,12 +142,8 @@ def test_type_errors_reported_with_valid_txn_docs(hook, acct, support_key, suppo
 
    }
 
    check(hook, expected, acct, txn_meta=meta)
 
    check(hook, expected, txn_meta=meta)
 

	
 
@pytest.mark.parametrize('acct,other_acct', testutil.combine_values(
 
    ACCOUNTS,
 
    ['Assets:Checking', 'Liabilities:CreditCard'],
 
))
 
def test_paid_accts_not_checked(hook, acct, other_acct):
 
def test_paid_accts_not_checked(hook):
 
    txn = testutil.Transaction(postings=[
 
        (acct, 250),
 
        (other_acct, -250),
 
        (TEST_ACCT, 250),
 
        (OTHER_ACCT, -250),
 
    ])
...
 
@@ -177,2 +159,3 @@ def test_paid_accts_not_checked(hook, acct, other_acct):
 
    'Liabilities:CreditCard',
 
    'Liabilities:Payable:Vacation',
 
    'Liabilities:UnearnedIncome:Donations',
0 comments (0 inline, 0 general)