tests: Add tests for Balance.copy() tolerance handling.

I wrote the changes to Balance.format() before the dependent changes to
Balance.copy(), so I was sort of counting on them to be implicitly
tested. But they should be explicit.
This commit is contained in:
Brett Smith 2020-06-20 09:08:35 -04:00
parent 7f3a26b555
commit 5b68312924

View file

@ -345,11 +345,23 @@ def test_iadd_balance(mapping):
expected = core.Balance(amounts_from_map(expect_numbers))
assert balance == expected
def test_copy():
amounts = frozenset(amounts_from_map({'USD': 10, 'EUR': '.001'}))
# Use a ridiculous tolerance to test it doesn't matter.
actual = core.Balance(amounts, 100).copy()
assert frozenset(actual.values()) == amounts
@pytest.mark.parametrize('tolerance', TOLERANCES)
def test_copy(tolerance):
eur = testutil.Amount('.003', 'EUR')
source = core.Balance([eur], tolerance)
new = source.copy()
assert source is not new
assert dict(source) == dict(new)
assert new.tolerance == tolerance
@pytest.mark.parametrize('tolerance', TOLERANCES)
def test_copy_tolerance_arg(tolerance):
eur = testutil.Amount('.003', 'EUR')
source = core.Balance([eur])
new = source.copy(tolerance)
assert source is not new
assert dict(source) == dict(new)
assert new.tolerance == tolerance
@pytest.mark.parametrize('tolerance', TOLERANCES)
def test_clean_copy(tolerance):
@ -361,6 +373,7 @@ def test_clean_copy(tolerance):
else:
expected = {usd}
assert frozenset(actual.values()) == expected
assert actual.tolerance == tolerance
@pytest.mark.parametrize('tolerance', TOLERANCES)
def test_clean_copy_arg(tolerance):
@ -372,6 +385,7 @@ def test_clean_copy_arg(tolerance):
else:
expected = {usd}
assert frozenset(actual.values()) == expected
assert actual.tolerance == tolerance
@pytest.mark.parametrize('mapping,expected', DEFAULT_STRINGS)
def test_str(mapping, expected):