diff options
Diffstat (limited to 'tests/run/test_patma.py')
-rw-r--r-- | tests/run/test_patma.py | 445 |
1 files changed, 242 insertions, 203 deletions
diff --git a/tests/run/test_patma.py b/tests/run/test_patma.py index 570986452..ee13b2fbc 100644 --- a/tests/run/test_patma.py +++ b/tests/run/test_patma.py @@ -1,43 +1,21 @@ -### COPIED FROM CPython 3.9 +### COPIED FROM CPython 3.12 alpha (July 2022) ### Original part after ############ # cython: language_level=3 # new code import cython -from Cython.Compiler.Main import compile as cython_compile, CompileError -from Cython.Build.Inline import cython_inline -import contextlib -from tempfile import NamedTemporaryFile - -@contextlib.contextmanager -def hidden_stderr(): - try: - from StringIO import StringIO - except ImportError: - from io import StringIO - - old_stderr = sys.stderr - try: - sys.stderr = StringIO() - yield - finally: - sys.stderr = old_stderr - -def _compile(code): - with NamedTemporaryFile(suffix='.py') as f: - f.write(code.encode('utf8')) - f.flush() - - with hidden_stderr(): - result = cython_compile(f.name, language_level=3) - return result +from Cython.TestUtils import py_parse_code + if cython.compiled: def compile(code, name, what): assert what == 'exec' - result = _compile(code) - if not result.c_file: - raise SyntaxError('unexpected EOF') # compile is only used for testing errors + py_parse_code(code) + + +def disable(func): + pass + ############## SLIGHTLY MODIFIED ORIGINAL CODE import array @@ -61,9 +39,47 @@ else: y: int # TestCompiler removed - it's very CPython-specific -# TestTracing also removed - doesn't seem like a core test +# TestTracing also mainly removed - doesn't seem like a core test +# except for one test that seems misplaced in CPython (which is below) + +class TestTracing(unittest.TestCase): + if sys.version_info < (3, 4): + class SubTestClass(object): + def __enter__(self): + return self + def __exit__(self, exc_type, exc_value, traceback): + return + def __call__(self, *args): + return self + subTest = SubTestClass() + + def test_parser_deeply_nested_patterns(self): + # Deeply nested patterns can cause exponential backtracking when parsing. + # See CPython gh-93671 for more information. + # + # DW: Cython note - this doesn't break the parser but may cause a + # RecursionError later in the code-generation. I don't believe that's + # easily avoidable with the way Cython visitors currently work + + levels = 100 + + patterns = [ + "A" + "(" * levels + ")" * levels, + "{1:" * levels + "1" + "}" * levels, + "[" * levels + "1" + "]" * levels, + ] -# FIXME - return all the "return"s added to cause code to be dropped + for pattern in patterns: + with self.subTest(pattern): + code = inspect.cleandoc(""" + match None: + case {}: + pass + """.format(pattern)) + compile(code, "<string>", "exec") + + +# FIXME - remove all the "return"s added to cause code to be dropped ############## ORIGINAL PART FROM CPYTHON @@ -71,7 +87,7 @@ class TestInheritance(unittest.TestCase): @staticmethod def check_sequence_then_mapping(x): - return + return # disabled match x: case [*_]: return "seq" @@ -80,7 +96,7 @@ class TestInheritance(unittest.TestCase): @staticmethod def check_mapping_then_sequence(x): - return + return # disabled match x: case {}: return "map" @@ -88,7 +104,7 @@ class TestInheritance(unittest.TestCase): return "seq" def test_multiple_inheritance_mapping(self): - return + return # disabled class C: pass class M1(collections.UserDict, collections.abc.Sequence): @@ -109,7 +125,7 @@ class TestInheritance(unittest.TestCase): self.assertEqual(self.check_mapping_then_sequence(M4()), "map") def test_multiple_inheritance_sequence(self): - return + return # disabled class C: pass class S1(collections.UserList, collections.abc.Mapping): @@ -130,7 +146,7 @@ class TestInheritance(unittest.TestCase): self.assertEqual(self.check_mapping_then_sequence(S4()), "seq") def test_late_registration_mapping(self): - return + return # disabled class Parent: pass class ChildPre(Parent): @@ -154,7 +170,7 @@ class TestInheritance(unittest.TestCase): self.assertEqual(self.check_mapping_then_sequence(GrandchildPost()), "map") def test_late_registration_sequence(self): - return + return # disabled class Parent: pass class ChildPre(Parent): @@ -248,7 +264,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(A.y, 1) def test_patma_009(self): - return + return # disabled class A: B = 0 match 0: @@ -264,14 +280,14 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 2) def test_patma_010(self): - return + return # disabled match (): case []: x = 0 self.assertEqual(x, 0) def test_patma_011(self): - return + return # disabled match (0, 1, 2): case [*x]: y = 0 @@ -279,7 +295,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_012(self): - return + return # disabled match (0, 1, 2): case [0, *x]: y = 0 @@ -287,7 +303,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_013(self): - return + return # disabled match (0, 1, 2): case [0, 1, *x,]: y = 0 @@ -295,7 +311,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_014(self): - return + return # disabled match (0, 1, 2): case [0, 1, 2, *x]: y = 0 @@ -303,7 +319,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_015(self): - return + return # disabled match (0, 1, 2): case [*x, 2,]: y = 0 @@ -311,7 +327,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_016(self): - return + return # disabled match (0, 1, 2): case [*x, 1, 2]: y = 0 @@ -319,7 +335,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_017(self): - return + return # disabled match (0, 1, 2): case [*x, 0, 1, 2,]: y = 0 @@ -327,7 +343,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_018(self): - return + return # disabled match (0, 1, 2): case [0, *x, 2]: y = 0 @@ -335,7 +351,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_019(self): - return + return # disabled match (0, 1, 2): case [0, 1, *x, 2,]: y = 0 @@ -343,7 +359,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_020(self): - return + return # disabled match (0, 1, 2): case [0, *x, 1, 2]: y = 0 @@ -351,7 +367,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_021(self): - return + return # disabled match (0, 1, 2): case [*x,]: y = 0 @@ -359,7 +375,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_022(self): - return + return # disabled x = {} match x: case {}: @@ -368,7 +384,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_023(self): - return + return # disabled x = {0: 0} match x: case {}: @@ -377,7 +393,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_024(self): - return + return # disabled x = {} y = None match x: @@ -387,7 +403,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_025(self): - return + return # disabled x = {0: 0} match x: case {0: (0 | 1 | 2 as z)}: @@ -397,7 +413,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_026(self): - return + return # disabled x = {0: 1} match x: case {0: (0 | 1 | 2 as z)}: @@ -407,7 +423,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 1) def test_patma_027(self): - return + return # disabled x = {0: 2} match x: case {0: (0 | 1 | 2 as z)}: @@ -417,7 +433,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 2) def test_patma_028(self): - return + return # disabled x = {0: 3} y = None match x: @@ -427,7 +443,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_029(self): - return + return # disabled x = {} y = None match x: @@ -441,7 +457,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_030(self): - return + return # disabled x = {False: (True, 2.0, {})} match x: case {0: [1, 2, {}]}: @@ -454,7 +470,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_031(self): - return + return # disabled x = {False: (True, 2.0, {}), 1: [[]], 2: 0} match x: case {0: [1, 2, {}]}: @@ -467,7 +483,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_032(self): - return + return # disabled x = {False: (True, 2.0, {}), 1: [[]], 2: 0} match x: case {0: [1, 2]}: @@ -480,7 +496,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 1) def test_patma_033(self): - return + return # disabled x = [] match x: case {0: [1, 2, {}]}: @@ -493,7 +509,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 2) def test_patma_034(self): - return + return # disabled x = {0: 0} match x: case {0: [1, 2, {}]}: @@ -506,7 +522,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 1) def test_patma_035(self): - return + return # disabled x = {0: 0} match x: case {0: [1, 2, {}]}: @@ -552,7 +568,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_040(self): - return + return # disabled x = 0 match x: case (0 as z) | (1 as z) | (2 as z) if z == x % 2: @@ -562,7 +578,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_041(self): - return + return # disabled x = 1 match x: case (0 as z) | (1 as z) | (2 as z) if z == x % 2: @@ -572,7 +588,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 1) def test_patma_042(self): - return + return # disabled x = 2 y = None match x: @@ -583,7 +599,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 2) def test_patma_043(self): - return + return # disabled x = 3 y = None match x: @@ -593,7 +609,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_044(self): - return + return # disabled x = () match x: case []: @@ -602,7 +618,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_045(self): - return + return # disabled x = () match x: case (): @@ -611,7 +627,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_046(self): - return + return # disabled x = (0,) match x: case [0]: @@ -620,7 +636,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_047(self): - return + return # disabled x = ((),) match x: case [[]]: @@ -629,7 +645,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_048(self): - return + return # disabled x = [0, 1] match x: case [0, 1] | [1, 0]: @@ -638,7 +654,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_049(self): - return + return # disabled x = [1, 0] match x: case [0, 1] | [1, 0]: @@ -647,7 +663,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_050(self): - return + return # disabled x = [0, 0] y = None match x: @@ -657,7 +673,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_051(self): - return + return # disabled w = None x = [1, 0] match x: @@ -671,7 +687,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_052(self): - return + return # disabled x = [1, 0] match x: case [0]: @@ -684,7 +700,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 2) def test_patma_053(self): - return + return # disabled x = {0} y = None match x: @@ -694,7 +710,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_054(self): - return + return # disabled x = set() y = None match x: @@ -704,7 +720,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_055(self): - return + return # disabled x = iter([1, 2, 3]) y = None match x: @@ -714,7 +730,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_056(self): - return + return # disabled x = {} y = None match x: @@ -724,7 +740,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_057(self): - return + return # disabled x = {0: False, 1: True} y = None match x: @@ -904,7 +920,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_075(self): - return + return # disabled x = "x" match x: case ["x"]: @@ -915,7 +931,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 1) def test_patma_076(self): - return + return # disabled x = b"x" match x: case [b"x"]: @@ -930,7 +946,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 4) def test_patma_077(self): - return + return # disabled x = bytearray(b"x") y = None match x: @@ -942,7 +958,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_078(self): - return + return # disabled x = "" match x: case []: @@ -955,7 +971,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 2) def test_patma_079(self): - return + return # disabled x = "xxx" match x: case ["x", "x", "x"]: @@ -968,7 +984,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 2) def test_patma_080(self): - return + return # disabled x = b"xxx" match x: case [120, 120, 120]: @@ -981,7 +997,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 2) def test_patma_081(self): - return + return # disabled x = 0 match x: case 0 if not (x := 1): @@ -993,7 +1009,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_082(self): - return + return # disabled x = 0 match x: case (1 as z) if not (x := 1): @@ -1022,7 +1038,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_085(self): - return + return # disabled x = 0 y = None match x: @@ -1044,7 +1060,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_087(self): - return + return # disabled x = 0 match x: case (0 | 1) | 2: @@ -1053,7 +1069,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_088(self): - return + return # disabled x = 1 match x: case (0 | 1) | 2: @@ -1062,7 +1078,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_089(self): - return + return # disabled x = 2 match x: case (0 | 1) | 2: @@ -1071,7 +1087,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_090(self): - return + return # disabled x = 3 y = None match x: @@ -1081,7 +1097,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_091(self): - return + return # disabled x = 0 match x: case 0 | (1 | 2): @@ -1090,7 +1106,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_092(self): - return + return # disabled x = 1 match x: case 0 | (1 | 2): @@ -1099,7 +1115,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_093(self): - return + return # disabled x = 2 match x: case 0 | (1 | 2): @@ -1108,7 +1124,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_094(self): - return + return # disabled x = 3 y = None match x: @@ -1333,7 +1349,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(x, 0) def test_patma_118(self): - return + return # disabled x = [] match x: case [*_, _]: @@ -1344,7 +1360,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 1) def test_patma_119(self): - return + return # disabled x = collections.defaultdict(int) match x: case {0: 0}: @@ -1355,7 +1371,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 1) def test_patma_120(self): - return + return # disabled x = collections.defaultdict(int) match x: case {0: 0}: @@ -1367,14 +1383,14 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, {}) def test_patma_121(self): - return + return # disabled match (): case (): x = 0 self.assertEqual(x, 0) def test_patma_122(self): - return + return # disabled match (0, 1, 2): case (*x,): y = 0 @@ -1382,7 +1398,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_123(self): - return + return # disabled match (0, 1, 2): case 0, *x: y = 0 @@ -1390,7 +1406,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_124(self): - return + return # disabled match (0, 1, 2): case (0, 1, *x,): y = 0 @@ -1398,7 +1414,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_125(self): - return + return # disabled match (0, 1, 2): case 0, 1, 2, *x: y = 0 @@ -1406,7 +1422,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_126(self): - return + return # disabled match (0, 1, 2): case *x, 2,: y = 0 @@ -1414,7 +1430,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_127(self): - return + return # disabled match (0, 1, 2): case (*x, 1, 2): y = 0 @@ -1422,7 +1438,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_128(self): - return + return # disabled match (0, 1, 2): case *x, 0, 1, 2,: y = 0 @@ -1430,7 +1446,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_129(self): - return + return # disabled match (0, 1, 2): case (0, *x, 2): y = 0 @@ -1438,7 +1454,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_130(self): - return + return # disabled match (0, 1, 2): case 0, 1, *x, 2,: y = 0 @@ -1446,7 +1462,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_131(self): - return + return # disabled match (0, 1, 2): case (0, *x, 1, 2): y = 0 @@ -1454,7 +1470,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_132(self): - return + return # disabled match (0, 1, 2): case *x,: y = 0 @@ -1462,7 +1478,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_133(self): - return + return # disabled x = collections.defaultdict(int, {0: 1}) match x: case {1: 0}: @@ -1475,7 +1491,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 2) def test_patma_134(self): - return + return # disabled x = collections.defaultdict(int, {0: 1}) match x: case {1: 0}: @@ -1489,7 +1505,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, {0: 1}) def test_patma_135(self): - return + return # disabled x = collections.defaultdict(int, {0: 1}) match x: case {1: 0}: @@ -1503,7 +1519,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, {}) def test_patma_136(self): - return + return # disabled x = {0: 1} match x: case {1: 0}: @@ -1516,7 +1532,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 1) def test_patma_137(self): - return + return # disabled x = {0: 1} match x: case {1: 0}: @@ -1530,7 +1546,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, {0: 1}) def test_patma_138(self): - return + return # disabled x = {0: 1} match x: case {1: 0}: @@ -1544,7 +1560,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, {}) def test_patma_139(self): - return + return # disabled x = False match x: case bool(z): @@ -1554,7 +1570,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_140(self): - return + return # disabled x = True match x: case bool(z): @@ -1564,7 +1580,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_141(self): - return + return # disabled x = bytearray() match x: case bytearray(z): @@ -1574,7 +1590,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_142(self): - return + return # disabled x = b"" match x: case bytes(z): @@ -1584,7 +1600,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_143(self): - return + return # disabled x = {} match x: case dict(z): @@ -1594,7 +1610,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_144(self): - return + return # disabled x = 0.0 match x: case float(z): @@ -1604,7 +1620,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_145(self): - return + return # disabled x = frozenset() match x: case frozenset(z): @@ -1614,7 +1630,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_146(self): - return + return # disabled x = 0 match x: case int(z): @@ -1624,7 +1640,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_147(self): - return + return # disabled x = [] match x: case list(z): @@ -1634,7 +1650,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_148(self): - return + return # disabled x = set() match x: case set(z): @@ -1644,7 +1660,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_149(self): - return + return # disabled x = "" match x: case str(z): @@ -1654,7 +1670,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_150(self): - return + return # disabled x = () match x: case tuple(z): @@ -1664,7 +1680,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_151(self): - return + return # disabled x = 0 match x,: case y,: @@ -1674,7 +1690,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, 0) def test_patma_152(self): - return + return # disabled w = 0 x = 0 match w, x: @@ -1687,7 +1703,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(v, 0) def test_patma_153(self): - return + return # disabled x = 0 match w := x,: case y as v,: @@ -1726,7 +1742,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_157(self): - return + return # disabled x = 0 y = None match x: @@ -1756,7 +1772,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_160(self): - return + return # disabled x = 0 z = None match x: @@ -1821,7 +1837,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 1) def test_patma_166(self): - return + return # disabled x = 0 match x: case z if not z: @@ -1833,7 +1849,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_167(self): - return + return # disabled x = 0 match x: case z if not z: @@ -1845,7 +1861,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_168(self): - return + return # disabled x = 0 match x: case z if not x: @@ -1857,7 +1873,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_169(self): - return + return # disabled x = 0 match x: case z if not z: @@ -1869,7 +1885,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, x) def test_patma_170(self): - return + return # disabled x = 0 match x: case _ if not x: @@ -1880,7 +1896,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_171(self): - return + return # disabled x = 0 y = None match x: @@ -1892,7 +1908,7 @@ class TestPatma(unittest.TestCase): self.assertIs(y, None) def test_patma_172(self): - return + return # disabled x = 0 z = None match x: @@ -1905,7 +1921,7 @@ class TestPatma(unittest.TestCase): self.assertIs(z, None) def test_patma_173(self): - return + return # disabled x = 0 match x: case _ if not x: @@ -1958,7 +1974,7 @@ class TestPatma(unittest.TestCase): self.assertIs(http_error(401 | 403 | 404), None) # 407 def test_patma_176(self): - return + return # disabled def whereis(point): match point: case (0, 0): @@ -1978,7 +1994,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(whereis(42), "Not a point") def test_patma_177(self): - return + return # disabled def whereis(point): match point: case Point(0, 0): @@ -2002,7 +2018,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(whereis(42), "Not a point") def test_patma_178(self): - return + return # disabled def whereis(point): match point: case Point(1, var): @@ -2011,7 +2027,7 @@ class TestPatma(unittest.TestCase): self.assertIs(whereis(Point(0, 0)), None) def test_patma_179(self): - return + return # disabled def whereis(point): match point: case Point(1, y=var): @@ -2020,7 +2036,7 @@ class TestPatma(unittest.TestCase): self.assertIs(whereis(Point(0, 0)), None) def test_patma_180(self): - return + return # disabled def whereis(point): match point: case Point(x=1, y=var): @@ -2029,7 +2045,7 @@ class TestPatma(unittest.TestCase): self.assertIs(whereis(Point(0, 0)), None) def test_patma_181(self): - return + return # disabled def whereis(point): match point: case Point(y=var, x=1): @@ -2038,7 +2054,7 @@ class TestPatma(unittest.TestCase): self.assertIs(whereis(Point(0, 0)), None) def test_patma_182(self): - return + return # disabled def whereis(points): match points: case []: @@ -2061,7 +2077,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(whereis([Point(0, 1), Point(0, 1), Point(0, 1)]), "Something else") def test_patma_183(self): - return + return # disabled def whereis(point): match point: case Point(x, y) if x == y: @@ -2076,7 +2092,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(whereis(Point("X", "x")), "Not on the diagonal") def test_patma_184(self): - return + return # disabled class Seq(collections.abc.Sequence): __getitem__ = None def __len__(self): @@ -2087,7 +2103,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_185(self): - return + return # disabled class Seq(collections.abc.Sequence): __getitem__ = None def __len__(self): @@ -2098,7 +2114,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_186(self): - return + return # disabled class Seq(collections.abc.Sequence): def __getitem__(self, i): return i @@ -2112,7 +2128,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_187(self): - return + return # disabled w = range(10) match w: case [x, y, *rest]: @@ -2124,7 +2140,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(rest, list(range(2, 10))) def test_patma_188(self): - return + return # disabled w = range(100) match w: case (x, y, *rest): @@ -2136,7 +2152,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(rest, list(range(2, 100))) def test_patma_189(self): - return + return # disabled w = range(1000) match w: case x, y, *rest: @@ -2148,7 +2164,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(rest, list(range(2, 1000))) def test_patma_190(self): - return + return # disabled w = range(1 << 10) match w: case [x, y, *_]: @@ -2159,7 +2175,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_191(self): - return + return # disabled w = range(1 << 20) match w: case (x, y, *_): @@ -2170,7 +2186,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_192(self): - return + return # disabled w = range(1 << 30) match w: case x, y, *_: @@ -2181,7 +2197,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_193(self): - return + return # disabled x = {"bandwidth": 0, "latency": 1} match x: case {"bandwidth": b, "latency": l}: @@ -2192,7 +2208,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_194(self): - return + return # disabled x = {"bandwidth": 0, "latency": 1, "key": "value"} match x: case {"latency": l, "bandwidth": b}: @@ -2203,7 +2219,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_195(self): - return + return # disabled x = {"bandwidth": 0, "latency": 1, "key": "value"} match x: case {"bandwidth": b, "latency": l, **rest}: @@ -2215,7 +2231,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_196(self): - return + return # disabled x = {"bandwidth": 0, "latency": 1} match x: case {"latency": l, "bandwidth": b, **rest}: @@ -2227,7 +2243,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_197(self): - return + return # disabled w = [Point(-1, 0), Point(1, 2)] match w: case (Point(x1, y1), Point(x2, y2) as p2): @@ -2293,7 +2309,7 @@ class TestPatma(unittest.TestCase): self.assertIs(f(3.0), None) def test_patma_200(self): - return + return # disabled class Class: __match_args__ = ("a", "b") c = Class() @@ -2307,7 +2323,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_201(self): - return + return # disabled class Class: __match_args__ = ("a", "b") c = Class() @@ -2321,7 +2337,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_202(self): - return + return # disabled class Parent: __match_args__ = "a", "b" class Child(Parent): @@ -2337,7 +2353,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_203(self): - return + return # disabled class Parent: __match_args__ = ("a", "b") class Child(Parent): @@ -2392,7 +2408,7 @@ class TestPatma(unittest.TestCase): self.assertIs(f("1"), None) def test_patma_207(self): - return + return # disabled def f(w): match w: case [1, 2] | [3, 4]: @@ -2429,7 +2445,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(f((1, 2)), {}) def test_patma_210(self): - return + return # disabled def f(w): match w: case (x, y, z): @@ -2447,7 +2463,7 @@ class TestPatma(unittest.TestCase): self.assertIs(f(bytearray(b"abc")), None) def test_patma_211(self): - return + return # disabled def f(w): match w: case {"x": x, "y": "y", "z": z}: @@ -2460,7 +2476,7 @@ class TestPatma(unittest.TestCase): self.assertIs(f(({"x": "x", "y": "y"})), None) def test_patma_212(self): - return + return # disabled def f(w): match w: case Point(int(xx), y="hello"): @@ -2470,7 +2486,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(f(Point(42, "hello")), {"xx": 42}) def test_patma_213(self): - return + return # disabled def f(w): match w: case (p, q) as x: @@ -2511,7 +2527,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(set(f()), {"abc"}) def test_patma_218(self): - return + return # disabled def f(): match ..., ...: case a, b: @@ -2519,7 +2535,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(set(f()), {"a", "b"}) def test_patma_219(self): - return + return # disabled def f(): match {"k": ..., "l": ...}: case {"k": a, "l": b}: @@ -2527,7 +2543,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(set(f()), {"a", "b"}) def test_patma_220(self): - return + return # disabled def f(): match Point(..., ...): case Point(x, y=y): @@ -2614,14 +2630,14 @@ class TestPatma(unittest.TestCase): self.assertIs(f(3), None) def test_patma_228(self): - return + return # disabled match(): case(): x = 0 self.assertEqual(x, 0) def test_patma_229(self): - return + return # disabled x = 0 match(x): case(x): @@ -2706,7 +2722,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_238(self): - return + return # disabled x = ((0, 1), (2, 3)) match x: case ((a as b, c as d) as e) as w, ((f as g, h) as i) as z: @@ -2726,7 +2742,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, (2, 3)) def test_patma_239(self): - return + return # disabled x = collections.UserDict({0: 1, 2: 3}) match x: case {2: 3}: @@ -2735,7 +2751,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 0) def test_patma_240(self): - return + return # disabled x = collections.UserDict({0: 1, 2: 3}) match x: case {2: 3, **z}: @@ -2745,7 +2761,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, {0: 1}) def test_patma_241(self): - return + return # disabled x = [[{0: 0}]] match x: case list([({-0-0j: int(real=0+0j, imag=0-0j) | (1) as z},)]): @@ -2755,7 +2771,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_242(self): - return + return # disabled x = range(3) match x: case [y, *_, z]: @@ -2766,7 +2782,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 2) def test_patma_243(self): - return + return # disabled x = range(3) match x: case [_, *_, y]: @@ -2776,7 +2792,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_244(self): - return + return # disabled x = range(3) match x: case [*_, y]: @@ -2786,7 +2802,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_245(self): - return + return # disabled x = {"y": 1} match x: case {"y": (0 as y) | (1 as y)}: @@ -2796,7 +2812,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(z, 0) def test_patma_246(self): - return + return # disabled def f(x): match x: case ((a, b, c, d, e, f, g, h, i, 9) | @@ -2821,7 +2837,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(f(range(10, 20)), alts[4]) def test_patma_247(self): - return + return # disabled def f(x): match x: case [y, (a, b, c, d, e, f, g, h, i, 9) | @@ -2846,7 +2862,7 @@ class TestPatma(unittest.TestCase): self.assertEqual(f((False, range(10, 20), True)), alts[4]) def test_patma_248(self): - return + return # disabled class C(dict): @staticmethod def get(key, default=None): @@ -2859,6 +2875,21 @@ class TestPatma(unittest.TestCase): self.assertEqual(y, 'bar') + def test_patma_249(self): + return # disabled + class C: + __attr = "eggs" # mangled to _C__attr + _Outer__attr = "bacon" + class Outer: + def f(self, x): + match x: + # looks up __attr, not _C__attr or _Outer__attr + case C(__attr=y): + return y + c = C() + setattr(c, "__attr", "spam") # setattr is needed because we're in a class scope + self.assertEqual(Outer().f(c), "spam") + class TestSyntaxErrors(unittest.TestCase): @@ -2881,6 +2912,7 @@ class TestSyntaxErrors(unittest.TestCase): """) + @disable # validation will be added when class patterns are added def test_attribute_name_repeated_in_class_pattern(self): self.assert_syntax_error(""" match ...: @@ -2979,6 +3011,7 @@ class TestSyntaxErrors(unittest.TestCase): pass """) + @disable # will be implemented as part of sequence patterns def test_multiple_starred_names_in_sequence_pattern_0(self): self.assert_syntax_error(""" match ...: @@ -2986,6 +3019,7 @@ class TestSyntaxErrors(unittest.TestCase): pass """) + @disable # will be implemented as part of sequence patterns def test_multiple_starred_names_in_sequence_pattern_1(self): self.assert_syntax_error(""" match ...: @@ -3120,6 +3154,7 @@ class TestSyntaxErrors(unittest.TestCase): pass """) + @disable # validation will be added when class patterns are added def test_mapping_pattern_duplicate_key(self): self.assert_syntax_error(""" match ...: @@ -3127,6 +3162,7 @@ class TestSyntaxErrors(unittest.TestCase): pass """) + @disable # validation will be added when class patterns are added def test_mapping_pattern_duplicate_key_edge_case0(self): self.assert_syntax_error(""" match ...: @@ -3134,6 +3170,7 @@ class TestSyntaxErrors(unittest.TestCase): pass """) + @disable # validation will be added when class patterns are added def test_mapping_pattern_duplicate_key_edge_case1(self): self.assert_syntax_error(""" match ...: @@ -3141,6 +3178,7 @@ class TestSyntaxErrors(unittest.TestCase): pass """) + @disable # validation will be added when class patterns are added def test_mapping_pattern_duplicate_key_edge_case2(self): self.assert_syntax_error(""" match ...: @@ -3148,6 +3186,7 @@ class TestSyntaxErrors(unittest.TestCase): pass """) + @disable # validation will be added when class patterns are added def test_mapping_pattern_duplicate_key_edge_case3(self): self.assert_syntax_error(""" match ...: @@ -3158,7 +3197,7 @@ class TestSyntaxErrors(unittest.TestCase): class TestTypeErrors(unittest.TestCase): def test_accepts_positional_subpatterns_0(self): - return + return # disabled class Class: __match_args__ = () x = Class() @@ -3171,7 +3210,7 @@ class TestTypeErrors(unittest.TestCase): self.assertIs(z, None) def test_accepts_positional_subpatterns_1(self): - return + return # disabled x = range(10) y = None with self.assertRaises(TypeError): @@ -3182,7 +3221,7 @@ class TestTypeErrors(unittest.TestCase): self.assertIs(y, None) def test_got_multiple_subpatterns_for_attribute_0(self): - return + return # disabled class Class: __match_args__ = ("a", "a") a = None @@ -3197,7 +3236,7 @@ class TestTypeErrors(unittest.TestCase): self.assertIs(z, None) def test_got_multiple_subpatterns_for_attribute_1(self): - return + return # disabled class Class: __match_args__ = ("a",) a = None @@ -3212,7 +3251,7 @@ class TestTypeErrors(unittest.TestCase): self.assertIs(z, None) def test_match_args_elements_must_be_strings(self): - return + return # disabled class Class: __match_args__ = (None,) x = Class() @@ -3225,7 +3264,7 @@ class TestTypeErrors(unittest.TestCase): self.assertIs(z, None) def test_match_args_must_be_a_tuple_0(self): - return + return # disabled class Class: __match_args__ = None x = Class() @@ -3238,7 +3277,7 @@ class TestTypeErrors(unittest.TestCase): self.assertIs(z, None) def test_match_args_must_be_a_tuple_1(self): - return + return # disabled class Class: __match_args__ = "XYZ" x = Class() @@ -3251,7 +3290,7 @@ class TestTypeErrors(unittest.TestCase): self.assertIs(z, None) def test_match_args_must_be_a_tuple_2(self): - return + return # disabled class Class: __match_args__ = ["spam", "eggs"] spam = 0 @@ -3270,7 +3309,7 @@ class TestTypeErrors(unittest.TestCase): class TestValueErrors(unittest.TestCase): def test_mapping_pattern_checks_duplicate_key_1(self): - return + return # disabled class Keys: KEY = "a" x = {"a": 0, "b": 1} |