From 5b68312924014e5a01f6e524c5e878d62b116df8 2020-06-20 13:11:01 From: Brett Smith Date: 2020-06-20 13:11:01 Subject: [PATCH] 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. --- diff --git a/tests/test_reports_balance.py b/tests/test_reports_balance.py index ce81dce1e9e160b3a5eda0ff542be36cefb5d080..4eafad259855b52aad61d776df1007abf308df1a 100644 --- a/tests/test_reports_balance.py +++ b/tests/test_reports_balance.py @@ -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):