Zac-HD / hypothesmith

Hypothesis strategies for generating Python programs, something like CSmith
https://pypi.org/project/hypothesmith/
Mozilla Public License 2.0
95 stars 9 forks source link

Error when generating single_input #9

Closed sk- closed 4 years ago

sk- commented 4 years ago

With the following test:

@hypothesis.given(hypothesmith.from_grammar(start="single_input"))
def test_statements(self, statement: str):
    statement = statement.strip()
    hypothesis.assume(statement and not statement.startswith('#'))
    print(repr(statement))
    # Assert logic ommited

I get the following error in hypothesmith:

Traceback (most recent call last):
  File "/projects/test/tests/test_matcher.py", line 47, in test_statements
    def test_statements(self, statement: str):
  File "/.virtualenvs/test/lib/python3.7/site-packages/hypothesis/core.py", line 1142, in wrapped_test
    raise the_error_hypothesis_found
  File "/.virtualenvs/test/lib/python3.7/site-packages/hypothesmith/syntactic.py", line 93, in do_draw
    nodes = list(ast.walk(ast.parse(result)))
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 2
    ‡xrÁԘ󩅲•ró򣯽
              ^
SyntaxError: invalid character in identifier
Zac-HD commented 4 years ago

Fixed by version 0.1.4, 6124cd71317add93500e0cb04c98cf5606adedea

You may get HealthCheck errors instead, but unfortunately there's not much to do about those without a substantial research project on program generation :confused: - I recommend just disabling them with Hypothesis' suppress_health_check setting.