crdoconnor / xeger

Library to generate random strings from regular expressions.
Other
117 stars 21 forks source link

Broken on python 3.5 #4

Closed kapsh closed 7 years ago

kapsh commented 7 years ago

xeger is completely unusable with python 3.5.

Traceback (most recent call last):
  File "/home/kapsh/tmp/xeger/xeger/tests/test_xeger.py", line 119, in test_zero_or_more_non_greedy
    self.match(r'a*?')
  File "/home/kapsh/tmp/xeger/xeger/tests/test_xeger.py", line 11, in match
    assert re.match(pattern, xeger.xeger(pattern))
  File "/home/kapsh/tmp/xeger/xeger/xeger.py", line 82, in xeger
    result = self._build_string(parsed)
  File "/home/kapsh/tmp/xeger/xeger/xeger.py", line 89, in _build_string
    newstr.append(self._handle_state(state))
  File "/home/kapsh/tmp/xeger/xeger/xeger.py", line 94, in _handle_state
    return self._cases[opcode](value)
KeyError: MIN_REPEAT

Unit test output: py35tests.txt

kapsh commented 7 years ago

This is because re.sre_parse.parse(pattern) returns tuple of _NamedIntConstant instead of strings. Fix with type conevrsion and normalization: #5 Checked on 3.5 and 2.7.