diff --git a/tests/test_reports_rewrite.py b/tests/test_reports_rewrite.py index 50235c48925ab5eedd13ad48e074faec0147368d..a915d77d0075d881e5cad7a325b8b5aa3e202780 100644 --- a/tests/test_reports_rewrite.py +++ b/tests/test_reports_rewrite.py @@ -15,7 +15,7 @@ import yaml from . import testutil -from conservancy_beancount import data +from conservancy_beancount import data, errors from conservancy_beancount.reports import rewrite CMP_OPS = frozenset('< <= == != >= >'.split()) @@ -131,7 +131,7 @@ def test_parse_good_condition(subject, operator, operand): '.units == 5', # Bad subject (unknown) ]) def test_parse_bad_condition(cond_s): - with pytest.raises(ValueError): + with pytest.raises(errors.RewriteRuleConditionError): rewrite.TestRegistry.parse(cond_s) @pytest.mark.parametrize('value', ['Equity:Other', 'Income:Other']) @@ -195,7 +195,7 @@ def test_parse_good_set(subject, operator, operand): 'testkey *= 3', # Bad operator ]) def test_parse_bad_set(set_s): - with pytest.raises(ValueError): + with pytest.raises(errors.RewriteRuleActionError): rewrite.SetRegistry.parse(set_s) def test_good_rewrite_rule(): @@ -271,17 +271,12 @@ def test_valid_rewrite_rule(source): {}, {'if': ['.account in Equity']}, {'a': ['.account = Income:Other'], 'b': ['.account = Expenses:Other']}, - # Condition/assignment mixup - {'if': ['.account = Equity:Other'], 'then': ['equity-type = other']}, - {'if': ['.account == Equity:Other'], 'then': ['equity-type != other']}, # Cross-category account assignment {'if': ['.date >= 2020-01-01'], 'then': ['.account = Assets:Cash']}, {'if': ['.account in Equity'], 'then': ['.account = Assets:Cash']}, # Number reallocation != 1 {'if': ['.date >= 2020-01-01'], 'then': ['.number *= .5']}, {'if': ['.date >= 2020-01-01'], 'a': ['k1=v1'], 'b': ['k2=v2']}, - # Date assignment - {'if': ['.date == 2020-01-01'], 'then': ['.date = 2020-02-02']}, # Redundant assignments {'if': ['.account in Income'], 'then': ['.account = Income:Other', '.account = Income:Other']}, @@ -290,7 +285,7 @@ def test_valid_rewrite_rule(source): 'b': ['.number *= .5']}, ]) def test_invalid_rewrite_rule(source): - with pytest.raises(ValueError): + with pytest.raises(errors.RewriteRuleValidationError): rewrite.RewriteRule(source) def test_rewrite_ruleset(): @@ -333,7 +328,7 @@ def test_ruleset_from_yaml_str(): def test_bad_ruleset_yaml_path(): yaml_path = testutil.test_path('repository/Projects/project-data.yml') - with pytest.raises(ValueError): + with pytest.raises(errors.RewriteRuleLoadError): rewrite.RewriteRuleset.from_yaml(yaml_path) @pytest.mark.parametrize('source', [ @@ -344,13 +339,13 @@ def test_bad_ruleset_yaml_path(): None, {}, 'string', - [{}, 'a'], - [{}, ['b']], + ['a'], + [['b']], # Rules have wrong type [{'if': '.account in Equity', 'add': ['testkey = value']}], [{'if': ['.account in Equity'], 'add': 'testkey = value'}], ]) def test_bad_ruleset_yaml_str(source): yaml_doc = yaml.safe_dump(source) - with pytest.raises(ValueError): + with pytest.raises(errors.RewriteRuleLoadError): rewrite.RewriteRuleset.from_yaml(yaml_doc)