Files
@ 68acb86e7e07
Branch filter:
Location: NPO-Accounting/conservancy_beancount/tests/test_reports_balance.py - annotation
68acb86e7e07
2.6 KiB
text/x-python
reports: Add Balance.__str__() method.
5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 5aa30e5456d0 68acb86e7e07 68acb86e7e07 68acb86e7e07 68acb86e7e07 68acb86e7e07 68acb86e7e07 68acb86e7e07 68acb86e7e07 68acb86e7e07 68acb86e7e07 68acb86e7e07 | """test_reports_balance - Unit tests for reports.core.Balance"""
# 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
from decimal import Decimal
import pytest
from . import testutil
from conservancy_beancount.reports import core
def test_empty_balance():
balance = core.Balance()
assert not balance
assert len(balance) == 0
assert balance.is_zero()
with pytest.raises(KeyError):
balance['USD']
@pytest.mark.parametrize('currencies', [
'USD',
'EUR GBP',
'JPY INR BRL',
])
def test_zero_balance(currencies):
keys = currencies.split()
balance = core.Balance(testutil.balance_map((key, 0) for key in keys))
assert balance
assert len(balance) == len(keys)
assert balance.is_zero()
assert all(balance[key].number == 0 for key in keys)
assert all(balance[key].currency == key for key in keys)
@pytest.mark.parametrize('currencies', [
'USD',
'EUR GBP',
'JPY INR BRL',
])
def test_nonzero_balance(currencies):
amounts = testutil.balance_map(zip(currencies.split(), itertools.count(110, 100)))
balance = core.Balance(amounts.items())
assert balance
assert len(balance) == len(amounts)
assert not balance.is_zero()
assert all(balance[key] == amt for key, amt in amounts.items())
def test_mixed_balance():
amounts = testutil.balance_map(USD=0, EUR=120)
balance = core.Balance(amounts.items())
assert balance
assert len(balance) == 2
assert not balance.is_zero()
assert all(balance[key] == amt for key, amt in amounts.items())
@pytest.mark.parametrize('balance_map_kwargs,expected', [
({}, "Zero balance"),
({'JPY': 0, 'BRL': 0}, "Zero balance"),
({'USD': '20.00'}, "20.00 USD"),
({'EUR': '50.00', 'GBP': '80.00'}, "80.00 GBP, 50.00 EUR"),
({'JPY': '-55.00', 'BRL': '-85.00'}, "-85.00 BRL, -55.00 JPY"),
])
def test_str(balance_map_kwargs, expected):
amounts = testutil.balance_map(**balance_map_kwargs)
assert str(core.Balance(amounts.items())) == expected
|