Skip to content

Commit

Permalink
add tests for GH 129 and 132
Browse files Browse the repository at this point in the history
  • Loading branch information
newville committed Sep 7, 2024
1 parent 9e4c20c commit 473726d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_asteval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,32 @@ def test_stringio(nested):
intrep("print('out')")
assert out.getvalue() == 'out\n'

@pytest.mark.parametrize("nested", [False, True])
def test_gh129(nested):
""" test that errors are propagated correctly, GH #129
"""
interp = make_interpreter(nested_symtable=nested)
interp('one, two, default = 1, 2, 3')
interp(textwrap.dedent("""
try:
output = some_var
except NameError:
output = None
foo = output or default
"""))
assert len(interp.error) == 0
assert interp('foo') == 3

@pytest.mark.parametrize("nested", [False, True])
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)
assert len(interp.error) == 1
assert interp.error[0].exc == NameError



if __name__ == '__main__':
pytest.main(['-v', '-x', '-s'])

0 comments on commit 473726d

Please sign in to comment.