Files
@ ae974b8e50c0
Branch filter:
Location: NPO-Accounting/conservancy_beancount/tests/test_data_account.py
ae974b8e50c0
6.9 KiB
text/x-python
reports: Balance.copy() accepts tolerance argument.
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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | """Test Account class"""
# Copyright © 2020 Brett Smith
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import pytest
from conservancy_beancount import data
@pytest.mark.parametrize('acct_name,under_arg,expected', [
('Expenses:Tax:Sales', 'Expenses:Tax:Sales:', False),
('Expenses:Tax:Sales', 'Expenses:Tax:Sales', True),
('Expenses:Tax:Sales', 'Expenses:Tax:', True),
('Expenses:Tax:Sales', 'Expenses:Tax', True),
('Expenses:Tax:Sales', 'Expenses:', True),
('Expenses:Tax:Sales', 'Expenses', True),
('Expenses:Tax:Sales', 'Expense', False),
('Expenses:Tax:Sales', 'Equity:', False),
('Expenses:Tax:Sales', 'Equity', False),
])
def test_is_under_one_arg(acct_name, under_arg, expected):
expected = under_arg if expected else None
assert data.Account(acct_name).is_under(under_arg) == expected
@pytest.mark.parametrize('acct_name,expected', [
('Assets:Cash', None),
('Assets:Checking', None),
('Assets:Prepaid:Expenses', 'Assets:Prepaid'),
('Assets:Receivable:Accounts', 'Assets:Receivable'),
])
def test_is_under_multi_arg(acct_name, expected):
assert expected == data.Account(acct_name).is_under(
'Assets:Prepaid', 'Assets:Receivable',
)
if expected:
expected += ':'
assert expected == data.Account(acct_name).is_under(
'Assets:Prepaid:', 'Assets:Receivable:',
)
@pytest.mark.parametrize('acct_name,expected', [
('Assets:Bank:Checking', True),
('Assets:Cash', True),
('Assets:Cash:EUR', True),
('Assets:Prepaid:Expenses', False),
('Assets:Prepaid:Vacation', False),
('Assets:Receivable:Accounts', False),
('Assets:Receivable:Fraud', False),
('Expenses:Other', False),
('Equity:OpeningBalance', False),
('Income:Other', False),
('Liabilities:CreditCard', False),
])
def test_is_cash_equivalent(acct_name, expected):
assert data.Account(acct_name).is_cash_equivalent() == expected
@pytest.mark.parametrize('acct_name,expected', [
('Assets:Bank:Check9999', True),
('Assets:Bank:CheckCard', True),
('Assets:Bank:Checking', True),
('Assets:Bank:Savings', False),
('Assets:Cash', False),
('Assets:Check9999', True),
('Assets:CheckCard', True),
('Assets:Checking', True),
('Assets:Prepaid:Expenses', False),
('Assets:Receivable:Accounts', False),
('Expenses:Other', False),
('Equity:OpeningBalance', False),
('Income:Other', False),
('Liabilities:CreditCard', False),
])
def test_is_checking(acct_name, expected):
assert data.Account(acct_name).is_checking() == expected
@pytest.mark.parametrize('acct_name,expected', [
('Assets:Cash', False),
('Assets:Prepaid:Expenses', False),
('Assets:Receivable:Accounts', False),
('Expenses:Other', False),
('Equity:OpeningBalance', False),
('Income:Other', False),
('Liabilities:CreditCard', True),
('Liabilities:CreditCard:Visa', True),
('Liabilities:Payable:Accounts', False),
('Liabilities:UnearnedIncome:Donations', False),
])
def test_is_credit_card(acct_name, expected):
assert data.Account(acct_name).is_credit_card() == expected
@pytest.mark.parametrize('acct_name,expected', [
('Assets:Cash', False),
('Assets:Prepaid:Expenses', False),
('Assets:Receivable:Accounts', False),
('Expenses:Other', False),
('Equity:Funds:Restricted', True),
('Equity:Funds:Unrestricted', True),
('Equity:OpeningBalance', True),
('Equity:Retained:Costs', False),
('Income:Other', False),
('Liabilities:CreditCard', False),
('Liabilities:Payable:Accounts', False),
('Liabilities:UnearnedIncome:Donations', False),
])
def test_is_opening_equity(acct_name, expected):
assert data.Account(acct_name).is_opening_equity() == expected
@pytest.mark.parametrize('acct_name', [
'Assets:Cash',
'Assets:Receivable:Accounts',
'Expenses:Other',
'Equity:Funds:Restricted',
'Income:Other',
'Liabilities:CreditCard',
'Liabilities:Payable:Accounts',
])
def test_slice_parts_no_args(acct_name):
account = data.Account(acct_name)
assert account.slice_parts() == acct_name.split(':')
@pytest.mark.parametrize('acct_name', [
'Assets:Cash',
'Assets:Receivable:Accounts',
'Expenses:Other',
'Equity:Funds:Restricted',
'Income:Other',
'Liabilities:CreditCard',
'Liabilities:Payable:Accounts',
])
def test_slice_parts_index(acct_name):
account = data.Account(acct_name)
parts = acct_name.split(':')
for index, expected in enumerate(parts):
assert account.slice_parts(index) == expected
with pytest.raises(IndexError):
account.slice_parts(index + 1)
@pytest.mark.parametrize('acct_name', [
'Assets:Cash',
'Assets:Receivable:Accounts',
'Expenses:Other',
'Equity:Funds:Restricted',
'Income:Other',
'Liabilities:CreditCard',
'Liabilities:Payable:Accounts',
])
def test_slice_parts_range(acct_name):
account = data.Account(acct_name)
parts = acct_name.split(':')
for start, stop in zip([0, 0, 1, 1], [2, 3, 2, 3]):
assert account.slice_parts(start, stop) == parts[start:stop]
@pytest.mark.parametrize('acct_name', [
'Assets:Cash',
'Assets:Receivable:Accounts',
'Expenses:Other',
'Equity:Funds:Restricted',
'Income:Other',
'Liabilities:CreditCard',
'Liabilities:Payable:Accounts',
])
def test_slice_parts_slice(acct_name):
account = data.Account(acct_name)
parts = acct_name.split(':')
for start, stop in zip([0, 0, 1, 1], [2, 3, 2, 3]):
sl = slice(start, stop)
assert account.slice_parts(sl) == parts[start:stop]
@pytest.mark.parametrize('acct_name', [
'Assets:Cash',
'Assets:Receivable:Accounts',
'Expenses:Other',
'Equity:Funds:Restricted',
'Income:Other',
'Liabilities:CreditCard',
'Liabilities:Payable:Accounts',
])
def test_count_parts(acct_name):
account = data.Account(acct_name)
assert account.count_parts() == acct_name.count(':') + 1
@pytest.mark.parametrize('acct_name', [
'Assets:Cash',
'Assets:Receivable:Accounts',
'Expenses:Other',
'Equity:Funds:Restricted',
'Income:Other',
'Liabilities:CreditCard',
'Liabilities:Payable:Accounts',
])
def test_root_part(acct_name):
account = data.Account(acct_name)
parts = acct_name.split(':')
assert account.root_part() == parts[0]
assert account.root_part(1) == parts[0]
assert account.root_part(2) == ':'.join(parts[:2])
|