Skip to content

Commit

Permalink
Merge pull request #1122 from lark-parser/tests_small_fixes
Browse files Browse the repository at this point in the history
Tests: Small fixes
  • Loading branch information
erezsh authored Mar 1, 2022
2 parents 0e9edd1 + e739c8b commit 1a8c89f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion tests/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import

import logging
from unittest import TestCase, main
from unittest import TestCase, main, skipIf

from lark import Lark, Tree, Transformer
from lark.lexer import Lexer, Token
Expand All @@ -12,6 +12,10 @@
except ImportError:
from io import BytesIO as StringIO

try:
import regex
except ImportError:
regex = None

class MockFile(StringIO):
def close(self):
Expand Down Expand Up @@ -141,6 +145,7 @@ def test_imports(self):
res = parser.parse("ab")
self.assertEqual(res, Tree('startab', [Tree('expr', ['a', 'b'])]))

@skipIf(regex is None, "'regex' lib not installed")
def test_recursive_pattern(self):
g = """
start: recursive+
Expand Down
4 changes: 2 additions & 2 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2461,7 +2461,7 @@ def match_error(s):
self.assertEqual( match_error("ebc"), 2 )


@unittest.skipIf(not regex or sys.version_info[0] == 2, 'Unicode and Python 2 do not place nicely together.')
@unittest.skipIf(not regex, "regex not installed")
def test_unicode_class(self):
"Tests that character classes from the `regex` module work correctly."
g = _Lark(r"""?start: NAME
Expand All @@ -2471,7 +2471,7 @@ def test_unicode_class(self):

self.assertEqual(g.parse('வணக்கம்'), 'வணக்கம்')

@unittest.skipIf(not regex or sys.version_info[0] == 2, 'Unicode and Python 2 do not place nicely together.')
@unittest.skipIf(not regex, "regex not installed")
def test_unicode_word(self):
"Tests that a persistent bug in the `re` module works when `regex` is enabled."
g = _Lark(r"""?start: NAME
Expand Down

0 comments on commit 1a8c89f

Please sign in to comment.