Changeset - 110e5038e103
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-09 13:04:27
brettcsmith@brettcsmith.org
reports: Balance.__init__ better handles multiple amounts of same currency.

This is something that should've happened with 3d704e286
but I didn't think of it at the time.
2 files changed with 23 insertions and 1 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/core.py
Show inline comments
...
 
@@ -90,8 +90,10 @@ class Balance(Mapping[str, data.Amount]):
 
    ) -> None:
 
        if tolerance is None:
 
            tolerance = self.TOLERANCE
 
        self._currency_map = {amount.currency: amount for amount in source}
 
        self.tolerance = tolerance
 
        self._currency_map: Dict[str, data.Amount] = {}
 
        for amount in source:
 
            self._add_amount(self._currency_map, amount)
 

	
 
    def _add_amount(self,
 
                    currency_map: MutableMapping[str, data.Amount],
tests/test_reports_balance.py
Show inline comments
...
 
@@ -81,6 +81,26 @@ def test_mixed_balance():
 
    assert not balance.is_zero()
 
    assert all(balance[key] == testutil.Amount(amt, key) for key, amt in amounts.items())
 

	
 
def test_init_recurring_currency():
 
    balance = core.Balance([
 
        testutil.Amount(20),
 
        testutil.Amount(40),
 
        testutil.Amount(60, 'EUR'),
 
        testutil.Amount(-80),
 
    ])
 
    assert balance
 
    assert balance['EUR'] == testutil.Amount(60, 'EUR')
 
    assert balance['USD'] == testutil.Amount(-20)
 

	
 
def test_init_zeroed_out():
 
    balance = core.Balance([
 
        testutil.Amount(25),
 
        testutil.Amount(40, 'EUR'),
 
        testutil.Amount(-25),
 
        testutil.Amount(-40, 'EUR'),
 
    ])
 
    assert balance.is_zero()
 

	
 
@pytest.mark.parametrize('mapping,expected', [
 
    ({}, True),
 
    ({'USD': 0}, True),
0 comments (0 inline, 0 general)