Closed github-actions[bot] closed 2 years ago
Stacking division and floor division does not parse safely
line 120, in test_parse_arith
assert eval(stmt) == eval(''.join(arith_expr.parseString(stmt)))
AssertionError: assert -1.0 == Undefined(None, (), {})
where -1.0 = eval('-1/1//1')
and Undefined(None, (), {}) = eval('Maybe(SafeDiv, Maybe(SafeFloorDiv, -1, 1, 1)())()')
where 'Maybe(SafeDiv, Maybe(SafeFloorDiv, -1, 1, 1)())()' = <built-in method join of str object at 0x10ac04030>((['Maybe(SafeDiv, Maybe(SafeFloorDiv, -1, 1, 1)())()'], {}))
where <built-in method join of str object at 0x10ac04030> = ''.join
and (['Maybe(SafeDiv, Maybe(SafeFloorDiv, -1, 1, 1)())()'], {}) = <bound method ParserElement.parseString of Combine:(Forward: bitwise operator term)>('-1/1//1')
where <bound method ParserElement.parseString of Combine:(Forward: bitwise operator term)> = arith_expr.parseString
https://github.com/rjdbcm/Aspidites/blob/5fc3dee979efc38553db5630f38fbf50c912315b/Aspidites/tests/test_aspidites.py#L113
main(['Aspidites', woma_file, f'-o={python_file}', '-c']) @hypothesis.settings(suppress_health_check=[hypothesis.HealthCheck.filter_too_much]) @hypothesis.given(st.text([c for c in ascii_letters]), st.text([c for c in ascii_lowercase]), st.integers(), st.integers(1, 10)) def test_parse_func_def(w, x, y, z): assume(str(w).isidentifier() and str(x).isidentifier()) assume(not iskeyword(w) and not iskeyword(x)) assume(w is not x) assume(y > 0) f = f"({w}({x} = {y} -> int)) int\n <*>{x}" exec(''.join(func_def.parseString(f))) args = '' for i in range(z): args += f"{x + str(i)} = {y} -> int;" args = args[:-1] f2 = f"({w}({x} = {y} -> int; {args})) int\n <*>{x}" print(f2) exec(''.join(func_def.parseString(f2))) # TODO Stacking unary operators onto their respective positive/negative operands does not parse safely # line 105, in test_parse_arith # assert eval(stmt) == eval(''.join(arith_expr.parseString(stmt))) # AssertionError: assert 1 == -1 # + where 1 = eval('--1-0//-1') # + and -1 = eval('Maybe(SafeFloorDiv, --1-0, -1)()') # + where 'Maybe(SafeFloorDiv, --1-0, -1)()' = <built-in method join of str object at 0x1033f0030>((['Maybe(SafeFloorDiv, --1-0, -1)()'], {})) # + where <built-in method join of str object at 0x1033f0030> = ''.join # + and (['Maybe(SafeFloorDiv, --1-0, -1)()'], {}) = <bound method ParserElement.parseString of Combine:(Forward: bitwise operator term)>('--1-0//-1') # + where <bound method ParserElement.parseString of Combine:(Forward: bitwise operator term)> = arith_expr.parseString # # Falsifying example: test_parse_arith( # p=1, q=0, binop='-', unop='-', # ) # TODO Stacking division and floor division does not parse safely # line 120, in test_parse_arith # assert eval(stmt) == eval(''.join(arith_expr.parseString(stmt))) # AssertionError: assert -1.0 == Undefined(None, (), {}) # + where -1.0 = eval('-1/1//1') # + and Undefined(None, (), {}) = eval('Maybe(SafeDiv, Maybe(SafeFloorDiv, -1, 1, 1)())()') # + where 'Maybe(SafeDiv, Maybe(SafeFloorDiv, -1, 1, 1)())()' = <built-in method join of str object at 0x10ac04030>((['Maybe(SafeDiv, Maybe(SafeFloorDiv, -1, 1, 1)())()'], {})) # + where <built-in method join of str object at 0x10ac04030> = ''.join # + and (['Maybe(SafeDiv, Maybe(SafeFloorDiv, -1, 1, 1)())()'], {}) = <bound method ParserElement.parseString of Combine:(Forward: bitwise operator term)>('-1/1//1') # + where <bound method ParserElement.parseString of Combine:(Forward: bitwise operator term)> = arith_expr.parseString @hypothesis.given(st.integers(min_value=1, max_value=255), # exponent st.integers(min_value=1), st.text(['/', '*', '%', '+', '-'], min_size=1, max_size=1), st.text(['+', '-'], min_size=1, max_size=1)) def test_parse_arith(p, q, binop, unop): stmt = str(p) + binop + "(" + str(q) + binop + str(p) + "+1" ")" assert eval(stmt) == eval(''.join(arith_expr.parseString(stmt))) stmt = str(p) + binop + str(q) assert eval(stmt) == eval(''.join(arith_expr.parseString(stmt))) # @pt.mark.filterwarnings('ignore::RuntimeWarning') def test_compile_to_shared_object(inject_config): python_file_ = str(Path('examples/compiled.pyx'))
3fb0a6d8387f8570309b1d2af1a53881f1aef9db
fixed in 1.6.x
Stacking division and floor division does not parse safely
line 120, in test_parse_arith
assert eval(stmt) == eval(''.join(arith_expr.parseString(stmt)))
AssertionError: assert -1.0 == Undefined(None, (), {})
where -1.0 = eval('-1/1//1')
and Undefined(None, (), {}) = eval('Maybe(SafeDiv, Maybe(SafeFloorDiv, -1, 1, 1)())()')
where 'Maybe(SafeDiv, Maybe(SafeFloorDiv, -1, 1, 1)())()' = <built-in method join of str object at 0x10ac04030>((['Maybe(SafeDiv, Maybe(SafeFloorDiv, -1, 1, 1)())()'], {}))
where <built-in method join of str object at 0x10ac04030> = ''.join
and (['Maybe(SafeDiv, Maybe(SafeFloorDiv, -1, 1, 1)())()'], {}) = <bound method ParserElement.parseString of Combine:(Forward: bitwise operator term)>('-1/1//1')
where <bound method ParserElement.parseString of Combine:(Forward: bitwise operator term)> = arith_expr.parseString
https://github.com/rjdbcm/Aspidites/blob/5fc3dee979efc38553db5630f38fbf50c912315b/Aspidites/tests/test_aspidites.py#L113
3fb0a6d8387f8570309b1d2af1a53881f1aef9db