Skip to content

Commit

Permalink
strengthen tests to assure length of errors, testing both .__call__()…
Browse files Browse the repository at this point in the history
… and .run()
  • Loading branch information
newville committed Sep 29, 2024
1 parent 36dc5f1 commit cc1f757
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tests/test_asteval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,13 @@ def test_no_duplicate_exception(nested):
""" test that errors are not repeated GH #132
"""
interp = make_interpreter(nested_symtable=nested)
interp.run("print(hi)", with_raise = False)
interp.run("print(hi)", with_raise=False)
assert len(interp.error) == 1
assert interp.error[0].exc == NameError

# with plain eval too
interp.error = []
interp("print(hi)", raise_errors=False)
assert len(interp.error) == 1
assert interp.error[0].exc == NameError

Expand All @@ -1535,13 +1541,14 @@ def test_raise_errors_unknown_symbol(nested):
""" test that raise_error raises corret error type. GH #133
"""
interp = make_interpreter(nested_symtable=nested)
interp.error = []
try:
saw_exception = False
interp.run("unknown_value", with_raise=True)
except NameError:
saw_exception = True
assert saw_exception
assert len(interp.error) > 0
assert len(interp.error) == 1
assert interp.error[0].exc == NameError


Expand Down

0 comments on commit cc1f757

Please sign in to comment.