This commit is contained in:
@@ -22,6 +22,10 @@ from slic.utils.eval import *
|
||||
("-(-(-2))", -2),
|
||||
("3 + +4", 7),
|
||||
("3 + -4", -1),
|
||||
("True + 1", 2),
|
||||
("string", "string"),
|
||||
("1e1000 * 1e1000", inf),
|
||||
("'a' + 'b'", "ab") # string concatenation supported !!!
|
||||
])
|
||||
def test_arithmetic_eval_valid(expr, expected):
|
||||
assert arithmetic_eval(expr) == expected
|
||||
@@ -33,9 +37,6 @@ def test_arithmetic_eval_valid(expr, expected):
|
||||
"1 < 2", # comparison not supported
|
||||
"abs(3)", # function call not supported
|
||||
"a + 2", # undefined variable
|
||||
"'a' + 'b'", # string concatenation not supported
|
||||
"'string'", # string constant alone
|
||||
"True + 1", # booleans not explicitly supported
|
||||
"[1, 2] + [3]", # lists not supported
|
||||
"{1: 2}", # dicts not supported
|
||||
])
|
||||
@@ -46,8 +47,7 @@ def test_arithmetic_eval_raises(expr):
|
||||
# Expressions that are syntactically valid but cause Python runtime errors
|
||||
@pytest.mark.parametrize("expr, exception", [
|
||||
("1 / 0", ZeroDivisionError),
|
||||
("10 % 0", ZeroDivisionError),
|
||||
("1e1000 * 1e1000", OverflowError),
|
||||
("10 % 0", ZeroDivisionError),
|
||||
])
|
||||
def test_arithmetic_eval_runtime_errors(expr, exception):
|
||||
with pytest.raises(exception):
|
||||
|
||||
Reference in New Issue
Block a user