Changeset - 581046f988a3
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-09 13:04:27
brettcsmith@brettcsmith.org
reports: Balance.format() respects tolerance.
2 files changed with 25 insertions and 4 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/core.py
Show inline comments
...
 
@@ -200,2 +200,3 @@ class Balance(Mapping[str, data.Amount]):
 
               empty: str="Zero balance",
 
               tolerance: Optional[Decimal]=None,
 
    ) -> str:
...
 
@@ -203,5 +204,5 @@ class Balance(Mapping[str, data.Amount]):
 

	
 
        If the balance is zero, returns ``empty``. Otherwise, returns a string
 
        with each amount in the balance formatted as ``fmt``, separated by
 
        ``sep``.
 
        If the balance is zero (within tolerance), returns ``empty``.
 
        Otherwise, returns a string with each amount in the balance formatted
 
        as ``fmt``, separated by ``sep``.
 

	
...
 
@@ -210,3 +211,3 @@ class Balance(Mapping[str, data.Amount]):
 
        """
 
        amounts = [amount for amount in self.values() if amount.number]
 
        amounts = list(self.clean_copy(tolerance).values())
 
        if not amounts:
tests/test_reports_balance.py
Show inline comments
...
 
@@ -34,2 +34,4 @@ DEFAULT_STRINGS = [
 
    ({'JPY': '-5500.00', 'BRL': '-8500.00'}, "-8,500.00 BRL, -5,500 JPY"),
 
    ({'USD': 10, 'EUR': '.00015'}, "10.00 USD"),
 
    ({'JPY': '-.00015'}, "Zero balance"),
 
]
...
 
@@ -381 +383,19 @@ def test_format_empty(empty):
 
    assert balance.format(empty=empty) == empty
 

	
 
@pytest.mark.parametrize('tolerance', TOLERANCES)
 
def test_str_tolerance(tolerance):
 
    chf = testutil.Amount('.005', 'CHF')
 
    actual = str(core.Balance([chf], tolerance))
 
    if tolerance > chf.number:
 
        assert actual == "Zero balance"
 
    else:
 
        assert actual == "00.00 CHF"
 

	
 
@pytest.mark.parametrize('tolerance', TOLERANCES)
 
def test_format_tolerance(tolerance):
 
    chf = testutil.Amount('.005', 'CHF')
 
    actual = core.Balance([chf]).format(tolerance=tolerance)
 
    if tolerance > chf.number:
 
        assert actual == "Zero balance"
 
    else:
 
        assert actual == "00.00 CHF"
0 comments (0 inline, 0 general)