diff --git a/tests/test_reports_core.py b/tests/test_reports_core.py new file mode 100644 index 0000000000000000000000000000000000000000..a0b8a03a3604aab4ec266fc9e2cecd4388603bda --- /dev/null +++ b/tests/test_reports_core.py @@ -0,0 +1,66 @@ +"""test_reports_core - Unit tests for basic reports functions""" +# 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 . + +import pytest + +from decimal import Decimal + +from . import testutil + +from conservancy_beancount.reports import core + +AMOUNTS = [ + 2, + Decimal('4.40'), + testutil.Amount('6.60', 'CHF'), + core.Balance([testutil.Amount('8.80')]), +] + +@pytest.mark.parametrize('acct_name', [ + 'Assets:Checking', + 'Assets:Receivable:Accounts', + 'Expenses:Other', + 'Expenses:FilingFees', +]) +def test_normalize_amount_func_pos(acct_name): + actual = core.normalize_amount_func(acct_name) + for amount in AMOUNTS: + assert actual(amount) == amount + +@pytest.mark.parametrize('acct_name', [ + 'Equity:Funds:Restricted', + 'Equity:Realized:CurrencyConversion', + 'Income:Donations', + 'Income:Other', + 'Liabilities:CreditCard', + 'Liabilities:Payable:Accounts', +]) +def test_normalize_amount_func_neg(acct_name): + actual = core.normalize_amount_func(acct_name) + for amount in AMOUNTS: + assert actual(amount) == -amount + +@pytest.mark.parametrize('acct_name', [ + '', + 'Assets', + 'Equity', + 'Expenses', + 'Income', + 'Liabilities', +]) +def test_normalize_amount_func_bad_acct_name(acct_name): + with pytest.raises(ValueError): + core.normalize_amount_func(acct_name)