Skip to content

Commit 2c4e7a6

Browse files
committed
Skip pattern-matching test on Python < 3.10
1 parent 2f5861c commit 2c4e7a6

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

tests/test_pattern_matching.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
import textwrap
13
import unittest
24

35
from immutables.map import Map as PyMap
@@ -7,14 +9,25 @@ class BaseMapTest:
79

810
Map = None
911

12+
@unittest.skipIf(
13+
sys.version_info < (3, 10),
14+
"pattern matching is not supported in this Python version",
15+
)
1016
def test_map_can_be_matched(self):
11-
match self.Map(a=1, b=2): # noqa: E999
12-
case {"a": 1 as matched}:
13-
matched = matched
14-
case _:
15-
assert False
16-
17-
assert matched == 1
17+
locals_ = dict(locals())
18+
exec(
19+
textwrap.dedent("""\
20+
match self.Map(a=1, b=2): # noqa: E999
21+
case {"a": 1 as matched}:
22+
matched = matched
23+
case _:
24+
assert False
25+
26+
self.assertEqual(matched, 1)
27+
"""),
28+
globals(),
29+
locals_,
30+
)
1831

1932

2033
class PyMapTest(BaseMapTest, unittest.TestCase):

0 commit comments

Comments
 (0)