Files
@ 8ec3a12d5af7
Branch filter:
Location: NPO-Accounting/conservancy_beancount/tests/test_data_account_meta.py - annotation
8ec3a12d5af7
4.1 KiB
text/x-python
accrual: Key on entity for Liabilities:Payable:Vacation.
The invoice metadata is less operative in this account.
The invoice metadata is less operative in this account.
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 | 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 6a7815090ca0 | """Test AccountMeta 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 itertools
import pytest
from datetime import date as Date
from beancount.core.data import Open, Close, Booking
from conservancy_beancount import data
def test_attributes():
open_date = Date(2019, 6, 1)
name = 'Assets:Bank:Checking'
currencies = ['USD', 'EUR']
booking = Booking.STRICT
actual = data.AccountMeta(Open({}, open_date, name, list(currencies), booking))
assert actual.open_date == open_date
assert actual.account == name
assert isinstance(actual.account, data.Account)
assert actual.currencies == currencies
assert actual.booking == booking
def test_mapping():
src_meta = {'filename': 'maptest', 'lineno': 10}
actual = data.AccountMeta(Open(
src_meta.copy(), Date(2019, 6, 1), 'Income:Donations', None, None,
))
assert len(actual) == 2
assert set(actual) == set(src_meta) # Test __iter__
for key, expected in src_meta.items():
assert actual[key] == expected
def test_close_attributes_without_closing():
actual = data.AccountMeta(Open(
{}, Date(2019, 6, 1), 'Assets:Cash', None, None,
))
assert actual.close_date is None
assert actual.close_meta is None
def test_close_at_init():
src_meta = {'filename': 'initclose', 'lineno': 50}
close_date = Date(2020, 6, 1)
name = 'Assets:Bank:MoneyMarket'
actual = data.AccountMeta(
Open({}, Date(2019, 6, 1), name, None, None),
Close(src_meta.copy(), close_date, name),
)
assert actual.close_date == close_date
assert actual.close_meta == src_meta
def test_add_closing():
src_meta = {'filename': 'laterclose', 'lineno': 65}
close_date = Date(2020, 1, 1)
name = 'Assets:Bank:EUR'
actual = data.AccountMeta(Open({}, Date(2019, 6, 1), name, None, None))
assert actual.close_date is None
assert actual.close_meta is None
actual.add_closing(Close(src_meta.copy(), close_date, name))
assert actual.close_date == close_date
assert actual.close_meta == src_meta
def test_add_closing_already_inited():
name = 'Assets:Bank:Savings'
actual = data.AccountMeta(
Open({}, Date(2019, 6, 1), name, None, None),
Close({}, Date(2019, 7, 1), name),
)
with pytest.raises(ValueError):
actual.add_closing(Close({}, Date(2019, 8, 1), name))
def test_add_closing_called_twice():
name = 'Assets:Bank:FX'
actual = data.AccountMeta(Open({}, Date(2019, 6, 1), name, None, None))
actual.add_closing(Close({}, Date(2019, 7, 1), name))
with pytest.raises(ValueError):
actual.add_closing(Close({}, Date(2019, 8, 1), name))
@pytest.mark.parametrize('close_date,close_name', [
(Date(2020, 6, 1), 'Income:Grants'), # Account name doesn't match
(Date(2010, 6, 1), 'Income:Donations'), # Close predates Open
])
def test_bad_closing_at_init(close_date, close_name):
with pytest.raises(ValueError):
data.AccountMeta(
Open({}, Date(2019, 6, 1), 'Income:Donations', None, None),
Close({}, close_date, close_name),
)
@pytest.mark.parametrize('close_date,close_name', [
(Date(2020, 6, 1), 'Income:Grants'), # Account name doesn't match
(Date(2010, 6, 1), 'Income:Donations'), # Close predates Open
])
def test_add_closing_wrong_account(close_date, close_name):
actual = data.AccountMeta(
Open({}, Date(2019, 6, 1), 'Income:Donations', None, None),
)
with pytest.raises(ValueError):
actual.add_closing(Close({}, close_date, close_name))
|