Changeset - 501bd251cbf3
[Not reviewed]
0 3 0
Brett Smith - 4 years ago 2020-03-19 19:04:53
brettcsmith@brettcsmith.org
tests: Turn tested hooks into fixtures.

This is in preparation for passing configuration to hooks.
That'll be a big change already, so I wanted this to be a
boring diff first.
3 files changed with 58 insertions and 69 deletions:
0 comments (0 inline, 0 general)
tests/test_meta_expense_allocation.py
Show inline comments
...
 
@@ -39,4 +39,8 @@ TEST_KEY = 'expense-allocation'
 

	
 
@pytest.fixture(scope='module')
 
def hook():
 
    return meta_expense_allocation.MetaExpenseAllocation()
 

	
 
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items())
 
def test_valid_values_on_postings(src_value, set_value):
 
def test_valid_values_on_postings(hook, src_value, set_value):
 
    txn = testutil.Transaction(postings=[
...
 
@@ -45,4 +49,3 @@ def test_valid_values_on_postings(src_value, set_value):
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -51,3 +54,3 @@ def test_valid_values_on_postings(src_value, set_value):
 
@pytest.mark.parametrize('src_value', INVALID_VALUES)
 
def test_invalid_values_on_postings(src_value):
 
def test_invalid_values_on_postings(hook, src_value):
 
    txn = testutil.Transaction(postings=[
...
 
@@ -56,4 +59,3 @@ def test_invalid_values_on_postings(src_value):
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
...
 
@@ -62,3 +64,3 @@ 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):
 
def test_valid_values_on_transactions(hook, src_value, set_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
...
 
@@ -67,4 +69,3 @@ def test_valid_values_on_transactions(src_value, set_value):
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -73,3 +74,3 @@ def test_valid_values_on_transactions(src_value, set_value):
 
@pytest.mark.parametrize('src_value', INVALID_VALUES)
 
def test_invalid_values_on_transactions(src_value):
 
def test_invalid_values_on_transactions(hook, src_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
...
 
@@ -78,4 +79,3 @@ def test_invalid_values_on_transactions(src_value):
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
...
 
@@ -90,3 +90,3 @@ def test_invalid_values_on_transactions(src_value):
 
])
 
def test_non_expense_accounts_skipped(account):
 
def test_non_expense_accounts_skipped(hook, account):
 
    meta = {TEST_KEY: 'program'}
...
 
@@ -96,4 +96,3 @@ def test_non_expense_accounts_skipped(account):
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -108,3 +107,3 @@ def test_non_expense_accounts_skipped(account):
 
])
 
def test_default_values(account, set_value):
 
def test_default_values(hook, account, set_value):
 
    txn = testutil.Transaction(postings=[
...
 
@@ -113,4 +112,3 @@ def test_default_values(account, set_value):
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -125,3 +123,3 @@ def test_default_values(account, set_value):
 
])
 
def test_default_value_set_in_date_range(date, set_value):
 
def test_default_value_set_in_date_range(hook, date, set_value):
 
    txn = testutil.Transaction(date=date, postings=[
...
 
@@ -130,4 +128,3 @@ def test_default_value_set_in_date_range(date, set_value):
 
    ])
 
    checker = meta_expense_allocation.MetaExpenseAllocation()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
tests/test_meta_income_type.py
Show inline comments
...
 
@@ -39,4 +39,8 @@ TEST_KEY = 'income-type'
 

	
 
@pytest.fixture(scope='module')
 
def hook():
 
    return meta_income_type.MetaIncomeType()
 

	
 
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items())
 
def test_valid_values_on_postings(src_value, set_value):
 
def test_valid_values_on_postings(hook, src_value, set_value):
 
    txn = testutil.Transaction(postings=[
...
 
@@ -45,4 +49,3 @@ def test_valid_values_on_postings(src_value, set_value):
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -51,3 +54,3 @@ def test_valid_values_on_postings(src_value, set_value):
 
@pytest.mark.parametrize('src_value', INVALID_VALUES)
 
def test_invalid_values_on_postings(src_value):
 
def test_invalid_values_on_postings(hook, src_value):
 
    txn = testutil.Transaction(postings=[
...
 
@@ -56,4 +59,3 @@ def test_invalid_values_on_postings(src_value):
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
...
 
@@ -62,3 +64,3 @@ 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):
 
def test_valid_values_on_transactions(hook, src_value, set_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
...
 
@@ -67,4 +69,3 @@ def test_valid_values_on_transactions(src_value, set_value):
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -73,3 +74,3 @@ def test_valid_values_on_transactions(src_value, set_value):
 
@pytest.mark.parametrize('src_value', INVALID_VALUES)
 
def test_invalid_values_on_transactions(src_value):
 
def test_invalid_values_on_transactions(hook, src_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
...
 
@@ -78,4 +79,3 @@ def test_invalid_values_on_transactions(src_value):
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
...
 
@@ -89,3 +89,3 @@ def test_invalid_values_on_transactions(src_value):
 
])
 
def test_non_income_accounts_skipped(account):
 
def test_non_income_accounts_skipped(hook, account):
 
    meta = {TEST_KEY: 'RBI'}
...
 
@@ -95,4 +95,3 @@ def test_non_income_accounts_skipped(account):
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -112,3 +111,3 @@ def test_non_income_accounts_skipped(account):
 
])
 
def test_default_values(account, set_value):
 
def test_default_values(hook, account, set_value):
 
    txn = testutil.Transaction(postings=[
...
 
@@ -117,4 +116,3 @@ def test_default_values(account, set_value):
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -125,3 +123,3 @@ def test_default_values(account, set_value):
 
])
 
def test_no_default_value(account):
 
def test_no_default_value(hook, account):
 
    txn = testutil.Transaction(postings=[
...
 
@@ -130,4 +128,3 @@ def test_no_default_value(account):
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
...
 
@@ -142,3 +139,3 @@ def test_no_default_value(account):
 
])
 
def test_default_value_set_in_date_range(date, set_value):
 
def test_default_value_set_in_date_range(hook, date, set_value):
 
    txn = testutil.Transaction(date=date, postings=[
...
 
@@ -147,4 +144,3 @@ def test_default_value_set_in_date_range(date, set_value):
 
    ])
 
    checker = meta_income_type.MetaIncomeType()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
tests/test_meta_tax_implication.py
Show inline comments
...
 
@@ -51,4 +51,8 @@ TEST_KEY = 'tax-implication'
 

	
 
@pytest.fixture(scope='module')
 
def hook():
 
    return meta_tax_implication.MetaTaxImplication()
 

	
 
@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items())
 
def test_valid_values_on_postings(src_value, set_value):
 
def test_valid_values_on_postings(hook, src_value, set_value):
 
    txn = testutil.Transaction(postings=[
...
 
@@ -57,4 +61,3 @@ def test_valid_values_on_postings(src_value, set_value):
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -63,3 +66,3 @@ def test_valid_values_on_postings(src_value, set_value):
 
@pytest.mark.parametrize('src_value', INVALID_VALUES)
 
def test_invalid_values_on_postings(src_value):
 
def test_invalid_values_on_postings(hook, src_value):
 
    txn = testutil.Transaction(postings=[
...
 
@@ -68,4 +71,3 @@ def test_invalid_values_on_postings(src_value):
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
...
 
@@ -74,3 +76,3 @@ 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):
 
def test_valid_values_on_transactions(hook, src_value, set_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
...
 
@@ -79,4 +81,3 @@ def test_valid_values_on_transactions(src_value, set_value):
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -85,3 +86,3 @@ def test_valid_values_on_transactions(src_value, set_value):
 
@pytest.mark.parametrize('src_value', INVALID_VALUES)
 
def test_invalid_values_on_transactions(src_value):
 
def test_invalid_values_on_transactions(hook, src_value):
 
    txn = testutil.Transaction(**{TEST_KEY: src_value}, postings=[
...
 
@@ -90,4 +91,3 @@ def test_invalid_values_on_transactions(src_value):
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert errors
...
 
@@ -100,3 +100,3 @@ def test_invalid_values_on_transactions(src_value):
 
])
 
def test_non_asset_accounts_skipped(account):
 
def test_non_asset_accounts_skipped(hook, account):
 
    meta = {TEST_KEY: 'USA-Corporation'}
...
 
@@ -106,4 +106,3 @@ def test_non_asset_accounts_skipped(account):
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -111,3 +110,3 @@ def test_non_asset_accounts_skipped(account):
 

	
 
def test_prepaid_expenses_skipped():
 
def test_prepaid_expenses_skipped(hook, ):
 
    txn = testutil.Transaction(postings=[
...
 
@@ -116,4 +115,3 @@ def test_prepaid_expenses_skipped():
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -121,3 +119,3 @@ def test_prepaid_expenses_skipped():
 

	
 
def test_asset_credits_skipped():
 
def test_asset_credits_skipped(hook, ):
 
    txn = testutil.Transaction(postings=[
...
 
@@ -126,4 +124,3 @@ def test_asset_credits_skipped():
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert not errors
...
 
@@ -138,3 +135,3 @@ def test_asset_credits_skipped():
 
])
 
def test_validation_only_in_date_range(date, need_value):
 
def test_validation_only_in_date_range(hook, date, need_value):
 
    txn = testutil.Transaction(date=date, postings=[
...
 
@@ -143,4 +140,3 @@ def test_validation_only_in_date_range(date, need_value):
 
    ])
 
    checker = meta_tax_implication.MetaTaxImplication()
 
    errors = list(checker.run(txn))
 
    errors = list(hook.run(txn))
 
    assert bool(errors) == bool(need_value)
0 comments (0 inline, 0 general)