Files
@ 6fa12789661e
Branch filter:
Location: NPO-Accounting/conservancy_beancount/tests/test_meta_tax_reporting.py - annotation
6fa12789661e
5.2 KiB
text/x-python
query: Improve formatting of ODS output.
* Provide dedicated formatting for more Beancount types.
* Improve code to determine when we're looking up link metadata
and should format output as links.
* Provide dedicated formatting for more Beancount types.
* Improve code to determine when we're looking up link metadata
and should format output as links.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa fe3560b748fa | """test_meta_tax_reporting.py - Unit tests for tax-reporting metadata validation"""
# Copyright © 2021 Brett Smith
# License: AGPLv3-or-later WITH Beancount-Plugin-Additional-Permission-1.0
#
# Full copyright and licensing details can be found at toplevel file
# LICENSE.txt in the repository.
import pytest
from . import testutil
from conservancy_beancount.plugin import meta_tax_reporting
TEST_KEY = 'tax-reporting'
IMPLICATION_KEY = 'tax-implication'
REQUIRED_ACCOUNTS = {
'Assets:Checking',
'Assets:Bank:Savings',
}
NON_REQUIRED_ACCOUNTS = {
'Assets:Prepaid:Expenses',
'Assets:Receivable:Accounts',
'Liabilities:CreditCard',
}
REQUIRED_AMOUNTS = {-50, -500}
NON_REQUIRED_AMOUNTS = {-5, 500}
REQUIRED_IMPLICATIONS = {
'1099',
'1099-Misc-Other',
'foreign-grantee',
'Foreign-Individual-Contractor',
'USA-501c3',
'US-Grantee',
}
NON_REQUIRED_IMPLICATIONS = {
'Bank-Transfer',
'chargeback',
'Foreign-Corp',
'Loan',
'refund',
'Reimbursement',
'retirement-pretax',
'Tax-Payment',
'us-corp',
'w2',
}
@pytest.fixture(scope='module')
def hook():
config = testutil.TestConfig(payment_threshold=10)
return meta_tax_reporting.MetaTaxReporting(config)
@pytest.mark.parametrize('account,amount,implication,value', testutil.combine_values(
REQUIRED_ACCOUNTS,
REQUIRED_AMOUNTS,
REQUIRED_IMPLICATIONS,
testutil.LINK_METADATA_STRINGS,
))
def test_pass_on_txn(hook, account, amount, implication, value):
txn_meta = {
IMPLICATION_KEY: implication,
TEST_KEY: value,
}
txn = testutil.Transaction(**txn_meta, postings=[
(account, amount),
('Expenses:Other', -amount),
])
assert not list(hook.run(txn))
@pytest.mark.parametrize('account,amount,implication,value', testutil.combine_values(
REQUIRED_ACCOUNTS,
REQUIRED_AMOUNTS,
REQUIRED_IMPLICATIONS,
testutil.LINK_METADATA_STRINGS,
))
def test_pass_on_post(hook, account, amount, implication, value):
post_meta = {
IMPLICATION_KEY: implication,
TEST_KEY: value,
}
txn = testutil.Transaction(postings=[
(account, amount, post_meta),
('Expenses:Other', -amount),
])
assert not list(hook.run(txn))
@pytest.mark.parametrize('account,amount,implication', testutil.combine_values(
REQUIRED_ACCOUNTS,
REQUIRED_AMOUNTS,
REQUIRED_IMPLICATIONS,
))
def test_error_when_missing(hook, account, amount, implication):
txn = testutil.Transaction(postings=[
(account, amount, {IMPLICATION_KEY: implication}),
('Expenses:Other', -amount),
])
assert list(hook.run(txn))
@pytest.mark.parametrize('account,amount,implication,value', testutil.combine_values(
REQUIRED_ACCOUNTS,
REQUIRED_AMOUNTS,
REQUIRED_IMPLICATIONS,
testutil.NON_LINK_METADATA_STRINGS,
))
def test_error_when_empty(hook, account, amount, implication, value):
txn_meta = {
IMPLICATION_KEY: implication,
TEST_KEY: value,
}
txn = testutil.Transaction(**txn_meta, postings=[
(account, amount),
('Expenses:Other', -amount),
])
assert list(hook.run(txn))
@pytest.mark.parametrize('account,amount,implication,value', testutil.combine_values(
REQUIRED_ACCOUNTS,
REQUIRED_AMOUNTS,
REQUIRED_IMPLICATIONS,
testutil.NON_STRING_METADATA_VALUES,
))
def test_error_when_wrong_type(hook, account, amount, implication, value):
txn_meta = {
IMPLICATION_KEY: implication,
TEST_KEY: value,
}
txn = testutil.Transaction(**txn_meta, postings=[
(account, amount),
('Expenses:Other', -amount),
])
assert list(hook.run(txn))
@pytest.mark.parametrize('account,amount,implication', testutil.combine_values(
NON_REQUIRED_ACCOUNTS,
REQUIRED_AMOUNTS,
REQUIRED_IMPLICATIONS,
))
def test_skip_by_account(hook, account, amount, implication):
txn = testutil.Transaction(postings=[
(account, amount, {IMPLICATION_KEY: implication}),
('Expenses:Other', -amount),
])
assert not list(hook.run(txn))
@pytest.mark.parametrize('account,amount,implication', testutil.combine_values(
REQUIRED_ACCOUNTS,
NON_REQUIRED_AMOUNTS,
REQUIRED_IMPLICATIONS,
))
def test_skip_by_amount(hook, account, amount, implication):
txn = testutil.Transaction(postings=[
(account, amount, {IMPLICATION_KEY: implication}),
('Expenses:Other', -amount),
])
assert not list(hook.run(txn))
@pytest.mark.parametrize('account,amount,implication', testutil.combine_values(
REQUIRED_ACCOUNTS,
REQUIRED_AMOUNTS,
NON_REQUIRED_IMPLICATIONS,
))
def test_skip_by_implication(hook, account, amount, implication):
txn = testutil.Transaction(postings=[
(account, amount, {IMPLICATION_KEY: implication}),
('Expenses:Other', -amount),
])
assert not list(hook.run(txn))
@pytest.mark.parametrize('account,amount,implication', testutil.combine_values(
REQUIRED_ACCOUNTS,
REQUIRED_AMOUNTS,
REQUIRED_IMPLICATIONS,
))
def test_skip_by_flag(hook, account, amount, implication):
txn = testutil.Transaction(flag='!', postings=[
(account, amount, {IMPLICATION_KEY: implication}),
('Expenses:Other', -amount),
])
assert not list(hook.run(txn))
|