diff --git a/conservancy_beancount/reports/core.py b/conservancy_beancount/reports/core.py index 01e04cd6eea99fe3f3246ff8d394d08632a302b9..9c0ae798bb891aeba9307b0c50b554c6d89770b2 100644 --- a/conservancy_beancount/reports/core.py +++ b/conservancy_beancount/reports/core.py @@ -140,6 +140,9 @@ class Balance(Mapping[str, data.Amount]): def __neg__(self: BalanceType) -> BalanceType: return type(self)(-amt for amt in self.values()) + def __pos__(self: BalanceType) -> BalanceType: + return self + def __getitem__(self, key: str) -> data.Amount: return self._currency_map[key] diff --git a/tests/test_reports_balance.py b/tests/test_reports_balance.py index 93a918f14c0ac0a04de5dabbdd1645436dc3394d..3a424b405be9846968db6acf3bf92c199ef56ed2 100644 --- a/tests/test_reports_balance.py +++ b/tests/test_reports_balance.py @@ -168,6 +168,20 @@ def test_neg(mapping): for key, number in mapping.items(): assert actual[key] == testutil.Amount(-number, key) +@pytest.mark.parametrize('mapping', [ + {}, + {'USD': 0}, + {'EUR': 10}, + {'JPY': 20, 'BRL': 30}, + {'EUR': -15}, + {'JPY': -25, 'BRL': -35}, + {'JPY': 40, 'USD': 0, 'EUR': -50}, +]) +def test_pos(mapping): + amounts = frozenset(amounts_from_map(mapping)) + actual = +core.Balance(amounts) + assert set(actual.values()) == amounts + @pytest.mark.parametrize('map1,map2,expected', [ ({}, {}, True), ({}, {'USD': 0}, True),