textX / Arpeggio

Parser interpreter based on PEG grammars written in Python http://textx.github.io/Arpeggio/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Few tests fail with pytest5.0+

scarabeusiv opened this issue · comments

Raises changed a bit the behaviour with 5.x series and now the exceptions need to be accessed slighly differently.

See the errors bellow:

[    5s] =================================== FAILURES ===================================
[    5s] _________________________ test_non_optional_precedence _________________________
[    5s] 
[    5s]     def test_non_optional_precedence():
[    5s]         """
[    5s]         Test that all tried match at position are reported.
[    5s]         """
[    5s]         def grammar():
[    5s]             return Optional('a'), 'b'
[    5s]     
[    5s]         parser = ParserPython(grammar)
[    5s]     
[    5s]         with pytest.raises(NoMatch) as e:
[    5s]             parser.parse('c')
[    5s] >       assert "Expected 'a' or 'b'" in str(e)
[    5s] E       assert "Expected 'a' or 'b'" in '<ExceptionInfo NoMatch tblen=12>'
[    5s] E        +  where '<ExceptionInfo NoMatch tblen=12>' = str(<ExceptionInfo NoMatch tblen=12>)
[    5s] 
[    5s] tests/unit/test_error_reporting.py:27: AssertionError
[    5s] _______________________ test_optional_with_better_match ________________________
[    5s] 
[    5s]     def test_optional_with_better_match():
[    5s]         """
[    5s]         Test that optional match that has gone further in the input stream
[    5s]         has precedence over non-optional.
[    5s]         """
[    5s]     
[    5s]         def grammar():  return [first, Optional(second)]
[    5s]         def first():    return 'one', 'two', 'three', '4'
[    5s]         def second():   return 'one', 'two', 'three', 'four', 'five'
[    5s]     
[    5s]         parser = ParserPython(grammar)
[    5s]     
[    5s]         with pytest.raises(NoMatch) as e:
[    5s]             parser.parse('one two three four 5')
[    5s]     
[    5s] >       assert "Expected 'five'" in str(e)
[    5s] E       assert "Expected 'five'" in '<ExceptionInfo NoMatch tblen=12>'
[    5s] E        +  where '<ExceptionInfo NoMatch tblen=12>' = str(<ExceptionInfo NoMatch tblen=12>)
[    5s] 
[    5s] tests/unit/test_error_reporting.py:57: AssertionError
[    5s] ____________________________ test_alternative_added ____________________________
[    5s] 
[    5s]     def test_alternative_added():
[    5s]         """
[    5s]         Test that matches from alternative branches at the same positiona are
[    5s]         reported.
[    5s]         """
[    5s]     
[    5s]         def grammar():
[    5s]             return ['one', 'two'], _(r'\w+')
[    5s]     
[    5s]         parser = ParserPython(grammar)
[    5s]     
[    5s]         with pytest.raises(NoMatch) as e:
[    5s]             parser.parse('   three ident')
[    5s] >       assert "Expected 'one' or 'two'" in str(e)
[    5s] E       assert "Expected 'one' or 'two'" in '<ExceptionInfo NoMatch tblen=16>'
[    5s] E        +  where '<ExceptionInfo NoMatch tblen=16>' = str(<ExceptionInfo NoMatch tblen=16>)
[    5s] 
[    5s] tests/unit/test_error_reporting.py:74: AssertionError
[    5s] ___________________________ test_file_name_reporting ___________________________
[    5s] 
[    5s]     def test_file_name_reporting():
[    5s]         """
[    5s]         Test that if parser has file name set it will be reported.
[    5s]         """
[    5s]     
[    5s]         def grammar():      return Optional('a'), 'b', EOF
[    5s]     
[    5s]         parser = ParserPython(grammar)
[    5s]     
[    5s]         with pytest.raises(NoMatch) as e:
[    5s]             parser.parse("\n\n   a c", file_name="test_file.peg")
[    5s] >       assert "Expected 'b' at position test_file.peg:(3, 6)" in str(e)
[    5s] E       assert "Expected 'b' at position test_file.peg:(3, 6)" in '<ExceptionInfo NoMatch tblen=8>'
[    5s] E        +  where '<ExceptionInfo NoMatch tblen=8>' = str(<ExceptionInfo NoMatch tblen=8>)
[    5s] 
[    5s] tests/unit/test_error_reporting.py:89: AssertionError
[    5s] ______________________ test_comment_matching_not_reported ______________________
[    5s] 
[    5s]     def test_comment_matching_not_reported():
[    5s]         """
[    5s]         Test that matching of comments is not reported.
[    5s]         """
[    5s]     
[    5s]         def grammar():      return Optional('a'), 'b', EOF
[    5s]         def comments():     return _('\/\/.*$')
[    5s]     
[    5s]         parser = ParserPython(grammar, comments)
[    5s]     
[    5s]         with pytest.raises(NoMatch) as e:
[    5s]             parser.parse('\n\n a // This is a comment \n c')
[    5s] >       assert "Expected 'b' at position (4, 2)" in str(e)
[    5s] E       assert "Expected 'b' at position (4, 2)" in '<ExceptionInfo NoMatch tblen=8>'
[    5s] E        +  where '<ExceptionInfo NoMatch tblen=8>' = str(<ExceptionInfo NoMatch tblen=8>)
[    5s] 
[    5s] tests/unit/test_error_reporting.py:105: AssertionError
[    5s] _________________________ test_not_match_at_beginning __________________________
[    5s] 
[    5s]     def test_not_match_at_beginning():
[    5s]         """
[    5s]         Test that matching of Not ParsingExpression is not reported in the
[    5s]         error message.
[    5s]         """
[    5s]     
[    5s]         def grammar():
[    5s]             return Not('one'), _(r'\w+')
[    5s]     
[    5s]         parser = ParserPython(grammar)
[    5s]     
[    5s]         with pytest.raises(NoMatch) as e:
[    5s]             parser.parse('   one ident')
[    5s] >       assert "Not expected input" in str(e)
[    5s] E       AssertionError: assert 'Not expected input' in '<ExceptionInfo NoMatch tblen=8>'
[    5s] E        +  where '<ExceptionInfo NoMatch tblen=8>' = str(<ExceptionInfo NoMatch tblen=8>)
[    5s] 
[    5s] tests/unit/test_error_reporting.py:122: AssertionError
[    5s] ________________________ test_not_match_as_alternative _________________________
[    5s] 
[    5s]     def test_not_match_as_alternative():
[    5s]         """
[    5s]         Test that Not is not reported if a part of OrderedChoice.
[    5s]         """
[    5s]     
[    5s]         def grammar():
[    5s]             return ['one', Not('two')], _(r'\w+')
[    5s]     
[    5s]         parser = ParserPython(grammar)
[    5s]     
[    5s]         with pytest.raises(NoMatch) as e:
[    5s]             parser.parse('   three ident')
[    5s] >       assert "Expected 'one' at " in str(e)
[    5s] E       assert "Expected 'one' at " in '<ExceptionInfo NoMatch tblen=16>'
[    5s] E        +  where '<ExceptionInfo NoMatch tblen=16>' = str(<ExceptionInfo NoMatch tblen=16>)
[    5s] 
[    5s] tests/unit/test_error_reporting.py:137: AssertionError
[    5s] ____________________________ test_sequence_of_nots _____________________________
[    5s] 
[    5s]     def test_sequence_of_nots():
[    5s]         """
[    5s]         Test that sequence of Not rules is handled properly.
[    5s]         """
[    5s]     
[    5s]         def grammar():
[    5s]             return Not('one'), Not('two'), _(r'\w+')
[    5s]     
[    5s]         parser = ParserPython(grammar)
[    5s]     
[    5s]         with pytest.raises(NoMatch) as e:
[    5s]             parser.parse('   two ident')
[    5s] >       assert "Not expected input" in str(e)
[    5s] E       AssertionError: assert 'Not expected input' in '<ExceptionInfo NoMatch tblen=12>'
[    5s] E        +  where '<ExceptionInfo NoMatch tblen=12>' = str(<ExceptionInfo NoMatch tblen=12>)
[    5s] 
[    5s] tests/unit/test_error_reporting.py:152: AssertionError
[    5s] ___________________________ test_compound_not_match ____________________________
[    5s] 
[    5s]     def test_compound_not_match():
[    5s]         """
[    5s]         Test a more complex Not match error reporting.
[    5s]         """
[    5s]         def grammar():
[    5s]             return [Not(['two', 'three']), 'one', 'two'], _(r'\w+')
[    5s]     
[    5s]         parser = ParserPython(grammar)
[    5s]     
[    5s]         with pytest.raises(NoMatch) as e:
[    5s]             parser.parse('   three ident')
[    5s] >       assert "Expected 'one' or 'two' at" in str(e)
[    5s] E       assert "Expected 'one' or 'two' at" in '<ExceptionInfo NoMatch tblen=24>'
[    5s] E        +  where '<ExceptionInfo NoMatch tblen=24>' = str(<ExceptionInfo NoMatch tblen=24>)
[    5s] 
[    5s] tests/unit/test_error_reporting.py:166: AssertionError
[    5s] =============================== warnings summary ===============================
[    5s] tests/unit/test_error_reporting.py:99
[    5s]   /home/abuild/rpmbuild/BUILD/Arpeggio-1.9.0/tests/unit/test_error_reporting.py:99: DeprecationWarning: invalid escape sequence \/
[    5s]     def comments():     return _('\/\/.*$')
[    5s] 
[    5s] tests/unit/test_peg_parser.py:20
[    5s]   /home/abuild/rpmbuild/BUILD/Arpeggio-1.9.0/tests/unit/test_peg_parser.py:20: DeprecationWarning: invalid escape sequence \d
[    5s]     '''
[    5s] 
[    5s] tests/unit/regressions/issue_16/test_issue_16.py:65
[    5s]   /home/abuild/rpmbuild/BUILD/Arpeggio-1.9.0/tests/unit/regressions/issue_16/test_issue_16.py:65: DeprecationWarning: invalid escape sequence \*
[    5s]     """
[    5s] 
[    5s] tests/unit/test_examples.py::test_examples
[    5s]   /home/abuild/rpmbuild/BUILD/Arpeggio-1.9.0/tests/unit/../../examples/simple/simple.py:19: DeprecationWarning: invalid escape sequence \*
[    5s]     def comment():          return [_("//.*"), _("/\*.*\*/")]
[    5s] 
[    5s] tests/unit/test_examples.py::test_examples
[    5s]   /home/abuild/rpmbuild/BUILD/Arpeggio-1.9.0/tests/unit/../../examples/json/json.py:22: DeprecationWarning: invalid escape sequence \d
[    5s]     def jsonNumber():       return _('-?\d+((\.\d*)?((e|E)(\+|-)?\d+)?)?')
[    5s] 
[    5s] -- Docs: https://docs.pytest.org/en/latest/warnings.html
[    5s] =============== 9 failed, 81 passed, 5 warnings in 0.71 seconds ================

Thanks for the report. Yes, it seems that with pytest.raises now returns a wrapper and not the original exception.

You can use the new syntax on the raises and it will work with older pytest, for us we use pytest4 on python2 and pytest-latest when python3 and it works on the whole distro.

Even in travis it will work out of the box using the pytest without restriction will use pytest 4.6.x on python2 and pytest-latest on python3.

@scarabeusiv You are right. I've just tested and it works fine with explicit checking of exception value even in older versions. Travis works fine. Updated and removed version constraint on pytest. It is on master branch. If you need a new release just let me know.

@igordejanovic if you would not mind doing another release so close to this one it would make the distro packaging easier (as we would not have to carry the patches for it).

@scarabeusiv I don't mind to make a bugfix release if what is on the master branch is ok and would make your job easier?

Git clone works for my purposes, so I suppose tagged release will work the same.