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:
parent
7f3a26b555
commit
5b68312924
1 changed files with 19 additions and 5 deletions
|
@ -345,11 +345,23 @@ def test_iadd_balance(mapping):
|
||||||
expected = core.Balance(amounts_from_map(expect_numbers))
|
expected = core.Balance(amounts_from_map(expect_numbers))
|
||||||
assert balance == expected
|
assert balance == expected
|
||||||
|
|
||||||
def test_copy():
|
@pytest.mark.parametrize('tolerance', TOLERANCES)
|
||||||
amounts = frozenset(amounts_from_map({'USD': 10, 'EUR': '.001'}))
|
def test_copy(tolerance):
|
||||||
# Use a ridiculous tolerance to test it doesn't matter.
|
eur = testutil.Amount('.003', 'EUR')
|
||||||
actual = core.Balance(amounts, 100).copy()
|
source = core.Balance([eur], tolerance)
|
||||||
assert frozenset(actual.values()) == amounts
|
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)
|
@pytest.mark.parametrize('tolerance', TOLERANCES)
|
||||||
def test_clean_copy(tolerance):
|
def test_clean_copy(tolerance):
|
||||||
|
@ -361,6 +373,7 @@ def test_clean_copy(tolerance):
|
||||||
else:
|
else:
|
||||||
expected = {usd}
|
expected = {usd}
|
||||||
assert frozenset(actual.values()) == expected
|
assert frozenset(actual.values()) == expected
|
||||||
|
assert actual.tolerance == tolerance
|
||||||
|
|
||||||
@pytest.mark.parametrize('tolerance', TOLERANCES)
|
@pytest.mark.parametrize('tolerance', TOLERANCES)
|
||||||
def test_clean_copy_arg(tolerance):
|
def test_clean_copy_arg(tolerance):
|
||||||
|
@ -372,6 +385,7 @@ def test_clean_copy_arg(tolerance):
|
||||||
else:
|
else:
|
||||||
expected = {usd}
|
expected = {usd}
|
||||||
assert frozenset(actual.values()) == expected
|
assert frozenset(actual.values()) == expected
|
||||||
|
assert actual.tolerance == tolerance
|
||||||
|
|
||||||
@pytest.mark.parametrize('mapping,expected', DEFAULT_STRINGS)
|
@pytest.mark.parametrize('mapping,expected', DEFAULT_STRINGS)
|
||||||
def test_str(mapping, expected):
|
def test_str(mapping, expected):
|
||||||
|
|
Loading…
Reference in a new issue