Skip to content

Commit

Permalink
add test for non-boolean return values from comparison operators
Browse files Browse the repository at this point in the history
  • Loading branch information
newville committed Aug 18, 2024
1 parent 45ef6e1 commit 1cd191f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_asteval.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,26 @@ def test_cmp(nested):
isfalse(interp, "3 > 5")
isfalse(interp, "5 < 3")

@pytest.mark.parametrize("nested", [False, True])
def test_comparisons_return(nested):
"""test comparisons that do not return a bool"""
interp = make_interpreter(nested_symtable=nested)
if HAS_NUMPY:

x = np.arange(10)/1.2
out = x > 2.3

interp("x = arange(10)/1.2")
interp("out = x > 2.3")

assert all(interp.symtable['out'] == out)
assert interp.symtable['out'].sum() == 7

interp("out = (x > 2.3 < 6.2)")

assert interp.error.pop().exc == ValueError


@pytest.mark.parametrize("nested", [False, True])
def test_bool(nested):
"""boolean logic"""
Expand Down

0 comments on commit 1cd191f

Please sign in to comment.