From 1cd191f0eef39621902b9292381c119048bbcdb7 Mon Sep 17 00:00:00 2001 From: Matthew Newville Date: Sun, 18 Aug 2024 09:09:44 -0500 Subject: [PATCH] add test for non-boolean return values from comparison operators --- tests/test_asteval.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_asteval.py b/tests/test_asteval.py index f7a2865..79a6014 100644 --- a/tests/test_asteval.py +++ b/tests/test_asteval.py @@ -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"""