From cc1f757696a2c8af7972a96c75dbbaa6763a2657 Mon Sep 17 00:00:00 2001 From: Matthew Newville Date: Sun, 29 Sep 2024 18:01:49 -0500 Subject: [PATCH] strengthen tests to assure length of errors, testing both .__call__() and .run() --- tests/test_asteval.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_asteval.py b/tests/test_asteval.py index 3d3f107..75c3517 100644 --- a/tests/test_asteval.py +++ b/tests/test_asteval.py @@ -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 @@ -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