Skip to content

Commit 1a8c89f

Browse files
authored
Merge pull request #1122 from lark-parser/tests_small_fixes
Tests: Small fixes
2 parents 0e9edd1 + e739c8b commit 1a8c89f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

tests/test_cache.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import absolute_import
22

33
import logging
4-
from unittest import TestCase, main
4+
from unittest import TestCase, main, skipIf
55

66
from lark import Lark, Tree, Transformer
77
from lark.lexer import Lexer, Token
@@ -12,6 +12,10 @@
1212
except ImportError:
1313
from io import BytesIO as StringIO
1414

15+
try:
16+
import regex
17+
except ImportError:
18+
regex = None
1519

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

148+
@skipIf(regex is None, "'regex' lib not installed")
144149
def test_recursive_pattern(self):
145150
g = """
146151
start: recursive+

tests/test_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,7 +2461,7 @@ def match_error(s):
24612461
self.assertEqual( match_error("ebc"), 2 )
24622462

24632463

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

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

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

0 commit comments

Comments
 (0)