diff --git a/tests/test_reports_balance.py b/tests/test_reports_balance.py index 07e238662870c712fc76a39a84f210ac8aa691c1..7913156940639c97d059d69c585b24c8fbfa7d4d 100644 --- a/tests/test_reports_balance.py +++ b/tests/test_reports_balance.py @@ -24,6 +24,14 @@ from . import testutil from conservancy_beancount.reports import core +DEFAULT_STRINGS = [ + ({}, "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': '-5500.00', 'BRL': '-8500.00'}, "-8,500.00 BRL, -5,500 JPY"), +] + def test_empty_balance(): balance = core.Balance() assert not balance @@ -150,13 +158,44 @@ def test_eq(kwargs1, kwargs2, expected): actual = bal1 == bal2 assert actual == expected -@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"), -]) +@pytest.mark.parametrize('balance_map_kwargs,expected', DEFAULT_STRINGS) def test_str(balance_map_kwargs, expected): amounts = testutil.balance_map(**balance_map_kwargs) assert str(core.Balance(amounts.items())) == expected + +@pytest.mark.parametrize('bal_kwargs,expected', DEFAULT_STRINGS) +def test_format_defaults(bal_kwargs, expected): + amounts = testutil.balance_map(**bal_kwargs) + assert core.Balance(amounts).format() == expected + +@pytest.mark.parametrize('fmt,expected', [ + ('¤##0.0', '¥5000, -€1500.00'), + ('#,#00.0¤¤', '5,000JPY, -1,500.00EUR'), + ('¤+##0.0;¤-##0.0', '¥+5000, €-1500.00'), + ('#,#00.0 ¤¤;(#,#00.0 ¤¤)', '5,000 JPY, (1,500.00 EUR)'), +]) +def test_format_fmt(fmt, expected): + amounts = testutil.balance_map(JPY=5000, EUR=-1500) + balance = core.Balance(amounts) + assert balance.format(fmt) == expected + +@pytest.mark.parametrize('sep', [ + '; ', + '—', + '\0', +]) +def test_format_sep(sep): + bal_kwargs, expected = DEFAULT_STRINGS[-1] + expected = expected.replace(', ', sep) + amounts = testutil.balance_map(**bal_kwargs) + balance = core.Balance(amounts) + assert balance.format(sep=sep) == expected + +@pytest.mark.parametrize('empty', [ + "N/A", + "Zero", + "ø", +]) +def test_format_empty(empty): + balance = core.Balance() + assert balance.format(empty=empty) == empty