1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
|
import array
import collections
import contextlib
import dataclasses
import enum
import inspect
import unittest
import warnings
def no_perf(f):
f.no_perf = None
return f
@dataclasses.dataclass
class MyClass:
x: int
y: str
__match_args__ = ("x", "y")
@dataclasses.dataclass
class Point:
x: int
y: int
class TestPatma(unittest.TestCase):
def assert_syntax_error(self, code: str):
with self.assertRaises(SyntaxError):
compile(inspect.cleandoc(code), "<test>", "exec")
def test_patma_000(self):
match 0:
case 0:
x = True
self.assertIs(x, True)
def test_patma_001(self):
match 0:
case 0 if False:
x = False
case 0 if True:
x = True
self.assertIs(x, True)
def test_patma_002(self):
match 0:
case 0:
x = True
case 0:
x = False
self.assertIs(x, True)
def test_patma_003(self):
x = False
match 0:
case 0 | 1 | 2 | 3:
x = True
self.assertIs(x, True)
def test_patma_004(self):
x = False
match 1:
case 0 | 1 | 2 | 3:
x = True
self.assertIs(x, True)
def test_patma_005(self):
x = False
match 2:
case 0 | 1 | 2 | 3:
x = True
self.assertIs(x, True)
def test_patma_006(self):
x = False
match 3:
case 0 | 1 | 2 | 3:
x = True
self.assertIs(x, True)
def test_patma_007(self):
x = False
match 4:
case 0 | 1 | 2 | 3:
x = True
self.assertIs(x, False)
def test_patma_008(self):
x = 0
class A:
y = 1
match x:
case A.y as z:
pass
self.assertEqual(x, 0)
self.assertEqual(A.y, 1)
def test_patma_009(self):
class A:
B = 0
match 0:
case x if x:
z = 0
case _ as y if y == x and y:
z = 1
case A.B:
z = 2
self.assertEqual(A.B, 0)
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertEqual(z, 2)
def test_patma_010(self):
match ():
case []:
x = 0
self.assertEqual(x, 0)
def test_patma_011(self):
match (0, 1, 2):
case [*x]:
y = 0
self.assertEqual(x, [0, 1, 2])
self.assertEqual(y, 0)
def test_patma_012(self):
match (0, 1, 2):
case [0, *x]:
y = 0
self.assertEqual(x, [1, 2])
self.assertEqual(y, 0)
def test_patma_013(self):
match (0, 1, 2):
case [0, 1, *x,]:
y = 0
self.assertEqual(x, [2])
self.assertEqual(y, 0)
def test_patma_014(self):
match (0, 1, 2):
case [0, 1, 2, *x]:
y = 0
self.assertEqual(x, [])
self.assertEqual(y, 0)
def test_patma_015(self):
match (0, 1, 2):
case [*x, 2,]:
y = 0
self.assertEqual(x, [0, 1])
self.assertEqual(y, 0)
def test_patma_016(self):
match (0, 1, 2):
case [*x, 1, 2]:
y = 0
self.assertEqual(x, [0])
self.assertEqual(y, 0)
def test_patma_017(self):
match (0, 1, 2):
case [*x, 0, 1, 2,]:
y = 0
self.assertEqual(x, [])
self.assertEqual(y, 0)
def test_patma_018(self):
match (0, 1, 2):
case [0, *x, 2]:
y = 0
self.assertEqual(x, [1])
self.assertEqual(y, 0)
def test_patma_019(self):
match (0, 1, 2):
case [0, 1, *x, 2,]:
y = 0
self.assertEqual(x, [])
self.assertEqual(y, 0)
def test_patma_020(self):
match (0, 1, 2):
case [0, *x, 1, 2]:
y = 0
self.assertEqual(x, [])
self.assertEqual(y, 0)
def test_patma_021(self):
match (0, 1, 2):
case [*x,]:
y = 0
self.assertEqual(x, [0, 1, 2])
self.assertEqual(y, 0)
def test_patma_022(self):
x = {}
match x:
case {}:
y = 0
self.assertEqual(x, {})
self.assertEqual(y, 0)
def test_patma_023(self):
x = {0: 0}
match x:
case {}:
y = 0
self.assertEqual(x, {0: 0})
self.assertEqual(y, 0)
def test_patma_024(self):
x = {}
y = None
match x:
case {0: 0}:
y = 0
self.assertEqual(x, {})
self.assertIs(y, None)
def test_patma_025(self):
x = {0: 0}
match x:
case {0: (0 | 1 | 2 as z)}:
y = 0
self.assertEqual(x, {0: 0})
self.assertEqual(y, 0)
self.assertEqual(z, 0)
def test_patma_026(self):
x = {0: 1}
match x:
case {0: (0 | 1 | 2 as z)}:
y = 0
self.assertEqual(x, {0: 1})
self.assertEqual(y, 0)
self.assertEqual(z, 1)
def test_patma_027(self):
x = {0: 2}
match x:
case {0: (0 | 1 | 2 as z)}:
y = 0
self.assertEqual(x, {0: 2})
self.assertEqual(y, 0)
self.assertEqual(z, 2)
def test_patma_028(self):
x = {0: 3}
y = None
match x:
case {0: (0 | 1 | 2 as z)}:
y = 0
self.assertEqual(x, {0: 3})
self.assertIs(y, None)
def test_patma_029(self):
x = {}
y = None
match x:
case {0: [1, 2, {}]}:
y = 0
case {0: [1, 2, {}], 1: [[]]}:
y = 1
case []:
y = 2
self.assertEqual(x, {})
self.assertIs(y, None)
def test_patma_030(self):
x = {False: (True, 2.0, {})}
match x:
case {0: [1, 2, {}]}:
y = 0
case {0: [1, 2, {}], 1: [[]]}:
y = 1
case []:
y = 2
self.assertEqual(x, {False: (True, 2.0, {})})
self.assertEqual(y, 0)
def test_patma_031(self):
x = {False: (True, 2.0, {}), 1: [[]], 2: 0}
match x:
case {0: [1, 2, {}]}:
y = 0
case {0: [1, 2, {}], 1: [[]]}:
y = 1
case []:
y = 2
self.assertEqual(x, {False: (True, 2.0, {}), 1: [[]], 2: 0})
self.assertEqual(y, 0)
def test_patma_032(self):
x = {False: (True, 2.0, {}), 1: [[]], 2: 0}
match x:
case {0: [1, 2]}:
y = 0
case {0: [1, 2, {}], 1: [[]]}:
y = 1
case []:
y = 2
self.assertEqual(x, {False: (True, 2.0, {}), 1: [[]], 2: 0})
self.assertEqual(y, 1)
def test_patma_033(self):
x = []
match x:
case {0: [1, 2, {}]}:
y = 0
case {0: [1, 2, {}], 1: [[]]}:
y = 1
case []:
y = 2
self.assertEqual(x, [])
self.assertEqual(y, 2)
def test_patma_034(self):
x = {0: 0}
match x:
case {0: [1, 2, {}]}:
y = 0
case {0: ([1, 2, {}] | False)} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}:
y = 1
case []:
y = 2
self.assertEqual(x, {0: 0})
self.assertEqual(y, 1)
def test_patma_035(self):
x = {0: 0}
match x:
case {0: [1, 2, {}]}:
y = 0
case {0: [1, 2, {}] | True} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}:
y = 1
case []:
y = 2
self.assertEqual(x, {0: 0})
self.assertEqual(y, 1)
def test_patma_036(self):
x = 0
match x:
case 0 | 1 | 2:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_037(self):
x = 1
match x:
case 0 | 1 | 2:
y = 0
self.assertEqual(x, 1)
self.assertEqual(y, 0)
def test_patma_038(self):
x = 2
match x:
case 0 | 1 | 2:
y = 0
self.assertEqual(x, 2)
self.assertEqual(y, 0)
def test_patma_039(self):
x = 3
y = None
match x:
case 0 | 1 | 2:
y = 0
self.assertEqual(x, 3)
self.assertIs(y, None)
def test_patma_040(self):
x = 0
match x:
case (0 as z) | (1 as z) | (2 as z) if z == x % 2:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertEqual(z, 0)
def test_patma_041(self):
x = 1
match x:
case (0 as z) | (1 as z) | (2 as z) if z == x % 2:
y = 0
self.assertEqual(x, 1)
self.assertEqual(y, 0)
self.assertEqual(z, 1)
def test_patma_042(self):
x = 2
y = None
match x:
case (0 as z) | (1 as z) | (2 as z) if z == x % 2:
y = 0
self.assertEqual(x, 2)
self.assertIs(y, None)
self.assertEqual(z, 2)
def test_patma_043(self):
x = 3
y = None
match x:
case (0 as z) | (1 as z) | (2 as z) if z == x % 2:
y = 0
self.assertEqual(x, 3)
self.assertIs(y, None)
def test_patma_044(self):
x = ()
match x:
case []:
y = 0
self.assertEqual(x, ())
self.assertEqual(y, 0)
def test_patma_045(self):
x = ()
match x:
case ():
y = 0
self.assertEqual(x, ())
self.assertEqual(y, 0)
def test_patma_046(self):
x = (0,)
match x:
case [0]:
y = 0
self.assertEqual(x, (0,))
self.assertEqual(y, 0)
def test_patma_047(self):
x = ((),)
match x:
case [[]]:
y = 0
self.assertEqual(x, ((),))
self.assertEqual(y, 0)
def test_patma_048(self):
x = [0, 1]
match x:
case [0, 1] | [1, 0]:
y = 0
self.assertEqual(x, [0, 1])
self.assertEqual(y, 0)
def test_patma_049(self):
x = [1, 0]
match x:
case [0, 1] | [1, 0]:
y = 0
self.assertEqual(x, [1, 0])
self.assertEqual(y, 0)
def test_patma_050(self):
x = [0, 0]
y = None
match x:
case [0, 1] | [1, 0]:
y = 0
self.assertEqual(x, [0, 0])
self.assertIs(y, None)
def test_patma_051(self):
w = None
x = [1, 0]
match x:
case [(0 as w)]:
y = 0
case [z] | [1, (0 | 1 as z)] | [z]:
y = 1
self.assertIs(w, None)
self.assertEqual(x, [1, 0])
self.assertEqual(y, 1)
self.assertEqual(z, 0)
def test_patma_052(self):
x = [1, 0]
match x:
case [0]:
y = 0
case [1, 0] if (x := x[:0]):
y = 1
case [1, 0]:
y = 2
self.assertEqual(x, [])
self.assertEqual(y, 2)
def test_patma_053(self):
x = {0}
y = None
match x:
case [0]:
y = 0
self.assertEqual(x, {0})
self.assertIs(y, None)
def test_patma_054(self):
x = set()
y = None
match x:
case []:
y = 0
self.assertEqual(x, set())
self.assertIs(y, None)
def test_patma_055(self):
x = iter([1, 2, 3])
y = None
match x:
case []:
y = 0
self.assertEqual([*x], [1, 2, 3])
self.assertIs(y, None)
def test_patma_056(self):
x = {}
y = None
match x:
case []:
y = 0
self.assertEqual(x, {})
self.assertIs(y, None)
def test_patma_057(self):
x = {0: False, 1: True}
y = None
match x:
case [0, 1]:
y = 0
self.assertEqual(x, {0: False, 1: True})
self.assertIs(y, None)
def test_patma_058(self):
x = 0
match x:
case 0:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_059(self):
x = 0
y = None
match x:
case False:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, None)
def test_patma_060(self):
x = 0
y = None
match x:
case 1:
y = 0
self.assertEqual(x, 0)
self.assertIs(y, None)
def test_patma_061(self):
x = 0
y = None
match x:
case None:
y = 0
self.assertEqual(x, 0)
self.assertIs(y, None)
def test_patma_062(self):
x = 0
match x:
case 0:
y = 0
case 0:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_063(self):
x = 0
y = None
match x:
case 1:
y = 0
case 1:
y = 1
self.assertEqual(x, 0)
self.assertIs(y, None)
def test_patma_064(self):
x = "x"
match x:
case "x":
y = 0
case "y":
y = 1
self.assertEqual(x, "x")
self.assertEqual(y, 0)
def test_patma_065(self):
x = "x"
match x:
case "y":
y = 0
case "x":
y = 1
self.assertEqual(x, "x")
self.assertEqual(y, 1)
def test_patma_066(self):
x = "x"
match x:
case "":
y = 0
case "x":
y = 1
self.assertEqual(x, "x")
self.assertEqual(y, 1)
def test_patma_067(self):
x = b"x"
match x:
case b"y":
y = 0
case b"x":
y = 1
self.assertEqual(x, b"x")
self.assertEqual(y, 1)
def test_patma_068(self):
x = 0
match x:
case 0 if False:
y = 0
case 0:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 1)
def test_patma_069(self):
x = 0
y = None
match x:
case 0 if 0:
y = 0
case 0 if 0:
y = 1
self.assertEqual(x, 0)
self.assertIs(y, None)
def test_patma_070(self):
x = 0
match x:
case 0 if True:
y = 0
case 0 if True:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_071(self):
x = 0
match x:
case 0 if 1:
y = 0
case 0 if 1:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_072(self):
x = 0
match x:
case 0 if True:
y = 0
case 0 if True:
y = 1
y = 2
self.assertEqual(x, 0)
self.assertEqual(y, 2)
def test_patma_073(self):
x = 0
match x:
case 0 if 0:
y = 0
case 0 if 1:
y = 1
y = 2
self.assertEqual(x, 0)
self.assertEqual(y, 2)
def test_patma_074(self):
x = 0
y = None
match x:
case 0 if not (x := 1):
y = 0
case 1:
y = 1
self.assertEqual(x, 1)
self.assertIs(y, None)
def test_patma_075(self):
x = "x"
match x:
case ["x"]:
y = 0
case "x":
y = 1
self.assertEqual(x, "x")
self.assertEqual(y, 1)
def test_patma_076(self):
x = b"x"
match x:
case [b"x"]:
y = 0
case ["x"]:
y = 1
case [120]:
y = 2
case b"x":
y = 4
self.assertEqual(x, b"x")
self.assertEqual(y, 4)
def test_patma_077(self):
x = bytearray(b"x")
y = None
match x:
case [120]:
y = 0
case 120:
y = 1
self.assertEqual(x, b"x")
self.assertIs(y, None)
def test_patma_078(self):
x = ""
match x:
case []:
y = 0
case [""]:
y = 1
case "":
y = 2
self.assertEqual(x, "")
self.assertEqual(y, 2)
def test_patma_079(self):
x = "xxx"
match x:
case ["x", "x", "x"]:
y = 0
case ["xxx"]:
y = 1
case "xxx":
y = 2
self.assertEqual(x, "xxx")
self.assertEqual(y, 2)
def test_patma_080(self):
x = b"xxx"
match x:
case [120, 120, 120]:
y = 0
case [b"xxx"]:
y = 1
case b"xxx":
y = 2
self.assertEqual(x, b"xxx")
self.assertEqual(y, 2)
def test_patma_081(self):
x = 0
match x:
case 0 if not (x := 1):
y = 0
case (0 as z):
y = 1
self.assertEqual(x, 1)
self.assertEqual(y, 1)
self.assertEqual(z, 0)
def test_patma_082(self):
x = 0
match x:
case (1 as z) if not (x := 1):
y = 0
case 0:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 1)
def test_patma_083(self):
x = 0
match x:
case (0 as z):
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertEqual(z, 0)
def test_patma_084(self):
x = 0
y = None
match x:
case (1 as z):
y = 0
self.assertEqual(x, 0)
self.assertIs(y, None)
def test_patma_085(self):
x = 0
y = None
match x:
case (0 as z) if (w := 0):
y = 0
self.assertEqual(w, 0)
self.assertEqual(x, 0)
self.assertIs(y, None)
self.assertEqual(z, 0)
def test_patma_086(self):
x = 0
match x:
case ((0 as w) as z):
y = 0
self.assertEqual(w, 0)
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertEqual(z, 0)
def test_patma_087(self):
x = 0
match x:
case (0 | 1) | 2:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_088(self):
x = 1
match x:
case (0 | 1) | 2:
y = 0
self.assertEqual(x, 1)
self.assertEqual(y, 0)
def test_patma_089(self):
x = 2
match x:
case (0 | 1) | 2:
y = 0
self.assertEqual(x, 2)
self.assertEqual(y, 0)
def test_patma_090(self):
x = 3
y = None
match x:
case (0 | 1) | 2:
y = 0
self.assertEqual(x, 3)
self.assertIs(y, None)
def test_patma_091(self):
x = 0
match x:
case 0 | (1 | 2):
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_092(self):
x = 1
match x:
case 0 | (1 | 2):
y = 0
self.assertEqual(x, 1)
self.assertEqual(y, 0)
def test_patma_093(self):
x = 2
match x:
case 0 | (1 | 2):
y = 0
self.assertEqual(x, 2)
self.assertEqual(y, 0)
def test_patma_094(self):
x = 3
y = None
match x:
case 0 | (1 | 2):
y = 0
self.assertEqual(x, 3)
self.assertIs(y, None)
def test_patma_095(self):
x = 0
match x:
case -0:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_096(self):
x = 0
match x:
case -0.0:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_097(self):
x = 0
match x:
case -0j:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_098(self):
x = 0
match x:
case -0.0j:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_099(self):
x = -1
match x:
case -1:
y = 0
self.assertEqual(x, -1)
self.assertEqual(y, 0)
def test_patma_100(self):
x = -1.5
match x:
case -1.5:
y = 0
self.assertEqual(x, -1.5)
self.assertEqual(y, 0)
def test_patma_101(self):
x = -1j
match x:
case -1j:
y = 0
self.assertEqual(x, -1j)
self.assertEqual(y, 0)
def test_patma_102(self):
x = -1.5j
match x:
case -1.5j:
y = 0
self.assertEqual(x, -1.5j)
self.assertEqual(y, 0)
def test_patma_103(self):
x = 0
match x:
case 0 + 0j:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_104(self):
x = 0
match x:
case 0 - 0j:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_105(self):
x = 0
match x:
case -0 + 0j:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_106(self):
x = 0
match x:
case -0 - 0j:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_107(self):
x = 0.25 + 1.75j
match x:
case 0.25 + 1.75j:
y = 0
self.assertEqual(x, 0.25 + 1.75j)
self.assertEqual(y, 0)
def test_patma_108(self):
x = 0.25 - 1.75j
match x:
case 0.25 - 1.75j:
y = 0
self.assertEqual(x, 0.25 - 1.75j)
self.assertEqual(y, 0)
def test_patma_109(self):
x = -0.25 + 1.75j
match x:
case -0.25 + 1.75j:
y = 0
self.assertEqual(x, -0.25 + 1.75j)
self.assertEqual(y, 0)
def test_patma_110(self):
x = -0.25 - 1.75j
match x:
case -0.25 - 1.75j:
y = 0
self.assertEqual(x, -0.25 - 1.75j)
self.assertEqual(y, 0)
def test_patma_111(self):
class A:
B = 0
x = 0
match x:
case A.B:
y = 0
self.assertEqual(A.B, 0)
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_112(self):
class A:
class B:
C = 0
x = 0
match x:
case A.B.C:
y = 0
self.assertEqual(A.B.C, 0)
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_113(self):
class A:
class B:
C = 0
D = 1
x = 1
match x:
case A.B.C:
y = 0
case A.B.D:
y = 1
self.assertEqual(A.B.C, 0)
self.assertEqual(A.B.D, 1)
self.assertEqual(x, 1)
self.assertEqual(y, 1)
def test_patma_114(self):
class A:
class B:
class C:
D = 0
x = 0
match x:
case A.B.C.D:
y = 0
self.assertEqual(A.B.C.D, 0)
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_115(self):
class A:
class B:
class C:
D = 0
E = 1
x = 1
match x:
case A.B.C.D:
y = 0
case A.B.C.E:
y = 1
self.assertEqual(A.B.C.D, 0)
self.assertEqual(A.B.C.E, 1)
self.assertEqual(x, 1)
self.assertEqual(y, 1)
def test_patma_116(self):
match = case = 0
match match:
case case:
x = 0
self.assertEqual(match, 0)
self.assertEqual(case, 0)
self.assertEqual(x, 0)
def test_patma_117(self):
match = case = 0
match case:
case match:
x = 0
self.assertEqual(match, 0)
self.assertEqual(case, 0)
self.assertEqual(x, 0)
def test_patma_118(self):
x = []
match x:
case [*_, _]:
y = 0
case []:
y = 1
self.assertEqual(x, [])
self.assertEqual(y, 1)
def test_patma_119(self):
x = collections.defaultdict(int)
match x:
case {0: 0}:
y = 0
case {}:
y = 1
self.assertEqual(x, {})
self.assertEqual(y, 1)
def test_patma_120(self):
x = collections.defaultdict(int)
match x:
case {0: 0}:
y = 0
case {**z}:
y = 1
self.assertEqual(x, {})
self.assertEqual(y, 1)
self.assertEqual(z, {})
def test_patma_121(self):
match ():
case ():
x = 0
self.assertEqual(x, 0)
def test_patma_122(self):
match (0, 1, 2):
case (*x,):
y = 0
self.assertEqual(x, [0, 1, 2])
self.assertEqual(y, 0)
def test_patma_123(self):
match (0, 1, 2):
case 0, *x:
y = 0
self.assertEqual(x, [1, 2])
self.assertEqual(y, 0)
def test_patma_124(self):
match (0, 1, 2):
case (0, 1, *x,):
y = 0
self.assertEqual(x, [2])
self.assertEqual(y, 0)
def test_patma_125(self):
match (0, 1, 2):
case 0, 1, 2, *x:
y = 0
self.assertEqual(x, [])
self.assertEqual(y, 0)
def test_patma_126(self):
match (0, 1, 2):
case *x, 2,:
y = 0
self.assertEqual(x, [0, 1])
self.assertEqual(y, 0)
def test_patma_127(self):
match (0, 1, 2):
case (*x, 1, 2):
y = 0
self.assertEqual(x, [0])
self.assertEqual(y, 0)
def test_patma_128(self):
match (0, 1, 2):
case *x, 0, 1, 2,:
y = 0
self.assertEqual(x, [])
self.assertEqual(y, 0)
def test_patma_129(self):
match (0, 1, 2):
case (0, *x, 2):
y = 0
self.assertEqual(x, [1])
self.assertEqual(y, 0)
def test_patma_130(self):
match (0, 1, 2):
case 0, 1, *x, 2,:
y = 0
self.assertEqual(x, [])
self.assertEqual(y, 0)
def test_patma_131(self):
match (0, 1, 2):
case (0, *x, 1, 2):
y = 0
self.assertEqual(x, [])
self.assertEqual(y, 0)
def test_patma_132(self):
match (0, 1, 2):
case *x,:
y = 0
self.assertEqual(x, [0, 1, 2])
self.assertEqual(y, 0)
def test_patma_133(self):
x = collections.defaultdict(int, {0: 1})
match x:
case {1: 0}:
y = 0
case {0: 0}:
y = 1
case {}:
y = 2
self.assertEqual(x, {0: 1})
self.assertEqual(y, 2)
def test_patma_134(self):
x = collections.defaultdict(int, {0: 1})
match x:
case {1: 0}:
y = 0
case {0: 0}:
y = 1
case {**z}:
y = 2
self.assertEqual(x, {0: 1})
self.assertEqual(y, 2)
self.assertEqual(z, {0: 1})
def test_patma_135(self):
x = collections.defaultdict(int, {0: 1})
match x:
case {1: 0}:
y = 0
case {0: 0}:
y = 1
case {0: _, **z}:
y = 2
self.assertEqual(x, {0: 1})
self.assertEqual(y, 2)
self.assertEqual(z, {})
def test_patma_136(self):
x = {0: 1}
match x:
case {1: 0}:
y = 0
case {0: 0}:
y = 0
case {}:
y = 1
self.assertEqual(x, {0: 1})
self.assertEqual(y, 1)
def test_patma_137(self):
x = {0: 1}
match x:
case {1: 0}:
y = 0
case {0: 0}:
y = 0
case {**z}:
y = 1
self.assertEqual(x, {0: 1})
self.assertEqual(y, 1)
self.assertEqual(z, {0: 1})
def test_patma_138(self):
x = {0: 1}
match x:
case {1: 0}:
y = 0
case {0: 0}:
y = 0
case {0: _, **z}:
y = 1
self.assertEqual(x, {0: 1})
self.assertEqual(y, 1)
self.assertEqual(z, {})
def test_patma_139(self):
x = False
match x:
case bool(z):
y = 0
self.assertIs(x, False)
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_140(self):
x = True
match x:
case bool(z):
y = 0
self.assertIs(x, True)
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_141(self):
x = bytearray()
match x:
case bytearray(z):
y = 0
self.assertEqual(x, bytearray())
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_142(self):
x = b""
match x:
case bytes(z):
y = 0
self.assertEqual(x, b"")
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_143(self):
x = {}
match x:
case dict(z):
y = 0
self.assertEqual(x, {})
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_144(self):
x = 0.0
match x:
case float(z):
y = 0
self.assertEqual(x, 0.0)
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_145(self):
x = frozenset()
match x:
case frozenset(z):
y = 0
self.assertEqual(x, frozenset())
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_146(self):
x = 0
match x:
case int(z):
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_147(self):
x = []
match x:
case list(z):
y = 0
self.assertEqual(x, [])
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_148(self):
x = set()
match x:
case set(z):
y = 0
self.assertEqual(x, set())
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_149(self):
x = ""
match x:
case str(z):
y = 0
self.assertEqual(x, "")
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_150(self):
x = ()
match x:
case tuple(z):
y = 0
self.assertEqual(x, ())
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_151(self):
x = 0
match x,:
case y,:
z = 0
self.assertEqual(x, 0)
self.assertIs(y, x)
self.assertIs(z, 0)
def test_patma_152(self):
w = 0
x = 0
match w, x:
case y, z:
v = 0
self.assertEqual(w, 0)
self.assertEqual(x, 0)
self.assertIs(y, w)
self.assertIs(z, x)
self.assertEqual(v, 0)
def test_patma_153(self):
x = 0
match w := x,:
case y as v,:
z = 0
self.assertEqual(x, 0)
self.assertIs(y, x)
self.assertEqual(z, 0)
self.assertIs(w, x)
self.assertIs(v, y)
def test_patma_154(self):
x = 0
y = None
match x:
case 0 if x:
y = 0
self.assertEqual(x, 0)
self.assertIs(y, None)
def test_patma_155(self):
x = 0
y = None
match x:
case 1e1000:
y = 0
self.assertEqual(x, 0)
self.assertIs(y, None)
def test_patma_156(self):
x = 0
match x:
case z:
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_157(self):
x = 0
y = None
match x:
case _ if x:
y = 0
self.assertEqual(x, 0)
self.assertIs(y, None)
def test_patma_158(self):
x = 0
match x:
case -1e1000:
y = 0
case 0:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 1)
def test_patma_159(self):
x = 0
match x:
case 0 if not x:
y = 0
case 1:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_160(self):
x = 0
z = None
match x:
case 0:
y = 0
case z if x:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertIs(z, None)
def test_patma_161(self):
x = 0
match x:
case 0:
y = 0
case _:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_162(self):
x = 0
match x:
case 1 if x:
y = 0
case 0:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 1)
def test_patma_163(self):
x = 0
y = None
match x:
case 1:
y = 0
case 1 if not x:
y = 1
self.assertEqual(x, 0)
self.assertIs(y, None)
def test_patma_164(self):
x = 0
match x:
case 1:
y = 0
case z:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 1)
self.assertIs(z, x)
def test_patma_165(self):
x = 0
match x:
case 1 if x:
y = 0
case _:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 1)
def test_patma_166(self):
x = 0
match x:
case z if not z:
y = 0
case 0 if x:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_167(self):
x = 0
match x:
case z if not z:
y = 0
case 1:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_168(self):
x = 0
match x:
case z if not x:
y = 0
case z:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_169(self):
x = 0
match x:
case z if not z:
y = 0
case _ if x:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertIs(z, x)
def test_patma_170(self):
x = 0
match x:
case _ if not x:
y = 0
case 0:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_171(self):
x = 0
y = None
match x:
case _ if x:
y = 0
case 1:
y = 1
self.assertEqual(x, 0)
self.assertIs(y, None)
def test_patma_172(self):
x = 0
z = None
match x:
case _ if not x:
y = 0
case z if not x:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertIs(z, None)
def test_patma_173(self):
x = 0
match x:
case _ if not x:
y = 0
case _:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_174(self):
def http_error(status):
match status:
case 400:
return "Bad request"
case 401:
return "Unauthorized"
case 403:
return "Forbidden"
case 404:
return "Not found"
case 418:
return "I'm a teapot"
case _:
return "Something else"
self.assertEqual(http_error(400), "Bad request")
self.assertEqual(http_error(401), "Unauthorized")
self.assertEqual(http_error(403), "Forbidden")
self.assertEqual(http_error(404), "Not found")
self.assertEqual(http_error(418), "I'm a teapot")
self.assertEqual(http_error(123), "Something else")
self.assertEqual(http_error("400"), "Something else")
self.assertEqual(http_error(401 | 403 | 404), "Something else") # 407
def test_patma_175(self):
def http_error(status):
match status:
case 400:
return "Bad request"
case 401 | 403 | 404:
return "Not allowed"
case 418:
return "I'm a teapot"
self.assertEqual(http_error(400), "Bad request")
self.assertEqual(http_error(401), "Not allowed")
self.assertEqual(http_error(403), "Not allowed")
self.assertEqual(http_error(404), "Not allowed")
self.assertEqual(http_error(418), "I'm a teapot")
self.assertIs(http_error(123), None)
self.assertIs(http_error("400"), None)
self.assertIs(http_error(401 | 403 | 404), None) # 407
@no_perf
def test_patma_176(self):
def whereis(point):
match point:
case (0, 0):
return "Origin"
case (0, y):
return f"Y={y}"
case (x, 0):
return f"X={x}"
case (x, y):
return f"X={x}, Y={y}"
case _:
raise ValueError("Not a point")
self.assertEqual(whereis((0, 0)), "Origin")
self.assertEqual(whereis((0, -1.0)), "Y=-1.0")
self.assertEqual(whereis(("X", 0)), "X=X")
self.assertEqual(whereis((None, 1j)), "X=None, Y=1j")
with self.assertRaises(ValueError):
whereis(42)
def test_patma_177(self):
def whereis(point):
match point:
case Point(0, 0):
return "Origin"
case Point(0, y):
return f"Y={y}"
case Point(x, 0):
return f"X={x}"
case Point():
return "Somewhere else"
case _:
return "Not a point"
self.assertEqual(whereis(Point(1, 0)), "X=1")
self.assertEqual(whereis(Point(0, 0)), "Origin")
self.assertEqual(whereis(10), "Not a point")
self.assertEqual(whereis(Point(False, False)), "Origin")
self.assertEqual(whereis(Point(0, -1.0)), "Y=-1.0")
self.assertEqual(whereis(Point("X", 0)), "X=X")
self.assertEqual(whereis(Point(None, 1j)), "Somewhere else")
self.assertEqual(whereis(Point), "Not a point")
self.assertEqual(whereis(42), "Not a point")
def test_patma_178(self):
def whereis(point):
match point:
case Point(1, var):
return var
self.assertEqual(whereis(Point(1, 0)), 0)
self.assertIs(whereis(Point(0, 0)), None)
def test_patma_179(self):
def whereis(point):
match point:
case Point(1, y=var):
return var
self.assertEqual(whereis(Point(1, 0)), 0)
self.assertIs(whereis(Point(0, 0)), None)
def test_patma_180(self):
def whereis(point):
match point:
case Point(x=1, y=var):
return var
self.assertEqual(whereis(Point(1, 0)), 0)
self.assertIs(whereis(Point(0, 0)), None)
def test_patma_181(self):
def whereis(point):
match point:
case Point(y=var, x=1):
return var
self.assertEqual(whereis(Point(1, 0)), 0)
self.assertIs(whereis(Point(0, 0)), None)
def test_patma_182(self):
def whereis(points):
match points:
case []:
return "No points"
case [Point(0, 0)]:
return "The origin"
case [Point(x, y)]:
return f"Single point {x}, {y}"
case [Point(0, y1), Point(0, y2)]:
return f"Two on the Y axis at {y1}, {y2}"
case _:
return "Something else"
self.assertEqual(whereis([]), "No points")
self.assertEqual(whereis([Point(0, 0)]), "The origin")
self.assertEqual(whereis([Point(0, 1)]), "Single point 0, 1")
self.assertEqual(whereis([Point(0, 0), Point(0, 0)]), "Two on the Y axis at 0, 0")
self.assertEqual(whereis([Point(0, 1), Point(0, 1)]), "Two on the Y axis at 1, 1")
self.assertEqual(whereis([Point(0, 0), Point(1, 0)]), "Something else")
self.assertEqual(whereis([Point(0, 0), Point(0, 0), Point(0, 0)]), "Something else")
self.assertEqual(whereis([Point(0, 1), Point(0, 1), Point(0, 1)]), "Something else")
def test_patma_183(self):
def whereis(point):
match point:
case Point(x, y) if x == y:
return f"Y=X at {x}"
case Point(x, y):
return "Not on the diagonal"
self.assertEqual(whereis(Point(0, 0)), "Y=X at 0")
self.assertEqual(whereis(Point(0, False)), "Y=X at 0")
self.assertEqual(whereis(Point(False, 0)), "Y=X at False")
self.assertEqual(whereis(Point(-1 - 1j, -1 - 1j)), "Y=X at (-1-1j)")
self.assertEqual(whereis(Point("X", "X")), "Y=X at X")
self.assertEqual(whereis(Point("X", "x")), "Not on the diagonal")
def test_patma_184(self):
class Seq(collections.abc.Sequence):
__getitem__ = None
def __len__(self):
return 0
match Seq():
case []:
y = 0
self.assertEqual(y, 0)
def test_patma_185(self):
class Seq(collections.abc.Sequence):
__getitem__ = None
def __len__(self):
return 42
match Seq():
case [*_]:
y = 0
self.assertEqual(y, 0)
def test_patma_186(self):
class Seq(collections.abc.Sequence):
def __getitem__(self, i):
return i
def __len__(self):
return 42
match Seq():
case [x, *_, y]:
z = 0
self.assertEqual(x, 0)
self.assertEqual(y, 41)
self.assertEqual(z, 0)
def test_patma_187(self):
w = range(10)
match w:
case [x, y, *rest]:
z = 0
self.assertEqual(w, range(10))
self.assertEqual(x, 0)
self.assertEqual(y, 1)
self.assertEqual(z, 0)
self.assertEqual(rest, list(range(2, 10)))
def test_patma_188(self):
w = range(100)
match w:
case (x, y, *rest):
z = 0
self.assertEqual(w, range(100))
self.assertEqual(x, 0)
self.assertEqual(y, 1)
self.assertEqual(z, 0)
self.assertEqual(rest, list(range(2, 100)))
def test_patma_189(self):
w = range(1000)
match w:
case x, y, *rest:
z = 0
self.assertEqual(w, range(1000))
self.assertEqual(x, 0)
self.assertEqual(y, 1)
self.assertEqual(z, 0)
self.assertEqual(rest, list(range(2, 1000)))
def test_patma_190(self):
w = range(1 << 10)
match w:
case [x, y, *_]:
z = 0
self.assertEqual(w, range(1 << 10))
self.assertEqual(x, 0)
self.assertEqual(y, 1)
self.assertEqual(z, 0)
def test_patma_191(self):
w = range(1 << 20)
match w:
case (x, y, *_):
z = 0
self.assertEqual(w, range(1 << 20))
self.assertEqual(x, 0)
self.assertEqual(y, 1)
self.assertEqual(z, 0)
def test_patma_192(self):
w = range(1 << 30)
match w:
case x, y, *_:
z = 0
self.assertEqual(w, range(1 << 30))
self.assertEqual(x, 0)
self.assertEqual(y, 1)
self.assertEqual(z, 0)
def test_patma_193(self):
x = {"bandwidth": 0, "latency": 1}
match x:
case {"bandwidth": b, "latency": l}:
y = 0
self.assertEqual(x, {"bandwidth": 0, "latency": 1})
self.assertIs(b, x["bandwidth"])
self.assertIs(l, x["latency"])
self.assertEqual(y, 0)
def test_patma_194(self):
x = {"bandwidth": 0, "latency": 1, "key": "value"}
match x:
case {"latency": l, "bandwidth": b}:
y = 0
self.assertEqual(x, {"bandwidth": 0, "latency": 1, "key": "value"})
self.assertIs(l, x["latency"])
self.assertIs(b, x["bandwidth"])
self.assertEqual(y, 0)
def test_patma_195(self):
x = {"bandwidth": 0, "latency": 1, "key": "value"}
match x:
case {"bandwidth": b, "latency": l, **rest}:
y = 0
self.assertEqual(x, {"bandwidth": 0, "latency": 1, "key": "value"})
self.assertIs(b, x["bandwidth"])
self.assertIs(l, x["latency"])
self.assertEqual(rest, {"key": "value"})
self.assertEqual(y, 0)
def test_patma_196(self):
x = {"bandwidth": 0, "latency": 1}
match x:
case {"latency": l, "bandwidth": b, **rest}:
y = 0
self.assertEqual(x, {"bandwidth": 0, "latency": 1})
self.assertIs(l, x["latency"])
self.assertIs(b, x["bandwidth"])
self.assertEqual(rest, {})
self.assertEqual(y, 0)
def test_patma_197(self):
w = [Point(-1, 0), Point(1, 2)]
match w:
case (Point(x1, y1), Point(x2, y2) as p2):
z = 0
self.assertEqual(w, [Point(-1, 0), Point(1, 2)])
self.assertIs(x1, w[0].x)
self.assertIs(y1, w[0].y)
self.assertIs(p2, w[1])
self.assertIs(x2, w[1].x)
self.assertIs(y2, w[1].y)
self.assertIs(z, 0)
def test_patma_198(self):
class Color(enum.Enum):
RED = 0
GREEN = 1
BLUE = 2
def f(color):
match color:
case Color.RED:
return "I see red!"
case Color.GREEN:
return "Grass is green"
case Color.BLUE:
return "I'm feeling the blues :("
self.assertEqual(f(Color.RED), "I see red!")
self.assertEqual(f(Color.GREEN), "Grass is green")
self.assertEqual(f(Color.BLUE), "I'm feeling the blues :(")
self.assertIs(f(Color), None)
self.assertIs(f(0), None)
self.assertIs(f(1), None)
self.assertIs(f(2), None)
self.assertIs(f(3), None)
self.assertIs(f(False), None)
self.assertIs(f(True), None)
self.assertIs(f(2+0j), None)
self.assertIs(f(3.0), None)
def test_patma_199(self):
class Color(int, enum.Enum):
RED = 0
GREEN = 1
BLUE = 2
def f(color):
match color:
case Color.RED:
return "I see red!"
case Color.GREEN:
return "Grass is green"
case Color.BLUE:
return "I'm feeling the blues :("
self.assertEqual(f(Color.RED), "I see red!")
self.assertEqual(f(Color.GREEN), "Grass is green")
self.assertEqual(f(Color.BLUE), "I'm feeling the blues :(")
self.assertIs(f(Color), None)
self.assertEqual(f(0), "I see red!")
self.assertEqual(f(1), "Grass is green")
self.assertEqual(f(2), "I'm feeling the blues :(")
self.assertIs(f(3), None)
self.assertEqual(f(False), "I see red!")
self.assertEqual(f(True), "Grass is green")
self.assertEqual(f(2+0j), "I'm feeling the blues :(")
self.assertIs(f(3.0), None)
def test_patma_200(self):
class Class:
__match_args__ = ("a", "b")
c = Class()
c.a = 0
c.b = 1
match c:
case Class(x, y):
z = 0
self.assertIs(x, c.a)
self.assertIs(y, c.b)
self.assertEqual(z, 0)
def test_patma_201(self):
class Class:
__match_args__ = ("a", "b")
c = Class()
c.a = 0
c.b = 1
match c:
case Class(x, b=y):
z = 0
self.assertIs(x, c.a)
self.assertIs(y, c.b)
self.assertEqual(z, 0)
def test_patma_202(self):
class Parent:
__match_args__ = "a", "b"
class Child(Parent):
__match_args__ = ("c", "d")
c = Child()
c.a = 0
c.b = 1
match c:
case Parent(x, y):
z = 0
self.assertIs(x, c.a)
self.assertIs(y, c.b)
self.assertEqual(z, 0)
def test_patma_203(self):
class Parent:
__match_args__ = ("a", "b")
class Child(Parent):
__match_args__ = "c", "d"
c = Child()
c.a = 0
c.b = 1
match c:
case Parent(x, b=y):
z = 0
self.assertIs(x, c.a)
self.assertIs(y, c.b)
self.assertEqual(z, 0)
def test_patma_204(self):
def f(w):
match w:
case 42:
out = locals()
del out["w"]
return out
self.assertEqual(f(42), {})
self.assertIs(f(0), None)
self.assertEqual(f(42.0), {})
self.assertIs(f("42"), None)
def test_patma_205(self):
def f(w):
match w:
case 42.0:
out = locals()
del out["w"]
return out
self.assertEqual(f(42.0), {})
self.assertEqual(f(42), {})
self.assertIs(f(0.0), None)
self.assertIs(f(0), None)
def test_patma_206(self):
def f(w):
match w:
case 1 | 2 | 3:
out = locals()
del out["w"]
return out
self.assertEqual(f(1), {})
self.assertEqual(f(2), {})
self.assertEqual(f(3), {})
self.assertEqual(f(3.0), {})
self.assertIs(f(0), None)
self.assertIs(f(4), None)
self.assertIs(f("1"), None)
def test_patma_207(self):
def f(w):
match w:
case [1, 2] | [3, 4]:
out = locals()
del out["w"]
return out
self.assertEqual(f([1, 2]), {})
self.assertEqual(f([3, 4]), {})
self.assertIs(f(42), None)
self.assertIs(f([2, 3]), None)
self.assertIs(f([1, 2, 3]), None)
self.assertEqual(f([1, 2.0]), {})
def test_patma_208(self):
def f(w):
match w:
case x:
out = locals()
del out["w"]
return out
self.assertEqual(f(42), {"x": 42})
self.assertEqual(f((1, 2)), {"x": (1, 2)})
self.assertEqual(f(None), {"x": None})
def test_patma_209(self):
def f(w):
match w:
case _:
out = locals()
del out["w"]
return out
self.assertEqual(f(42), {})
self.assertEqual(f(None), {})
self.assertEqual(f((1, 2)), {})
def test_patma_210(self):
def f(w):
match w:
case (x, y, z):
out = locals()
del out["w"]
return out
self.assertEqual(f((1, 2, 3)), {"x": 1, "y": 2, "z": 3})
self.assertIs(f((1, 2)), None)
self.assertIs(f((1, 2, 3, 4)), None)
self.assertIs(f(123), None)
self.assertIs(f("abc"), None)
self.assertIs(f(b"abc"), None)
self.assertEqual(f(array.array("b", b"abc")), {'x': 97, 'y': 98, 'z': 99})
self.assertEqual(f(memoryview(b"abc")), {"x": 97, "y": 98, "z": 99})
self.assertIs(f(bytearray(b"abc")), None)
def test_patma_211(self):
def f(w):
match w:
case {"x": x, "y": "y", "z": z}:
out = locals()
del out["w"]
return out
self.assertEqual(f({"x": "x", "y": "y", "z": "z"}), {"x": "x", "z": "z"})
self.assertEqual(f({"x": "x", "y": "y", "z": "z", "a": "a"}), {"x": "x", "z": "z"})
self.assertIs(f(({"x": "x", "y": "yy", "z": "z", "a": "a"})), None)
self.assertIs(f(({"x": "x", "y": "y"})), None)
def test_patma_212(self):
def f(w):
match w:
case MyClass(int(xx), y="hello"):
out = locals()
del out["w"]
return out
self.assertEqual(f(MyClass(42, "hello")), {"xx": 42})
def test_patma_213(self):
def f(w):
match w:
case (p, q) as x:
out = locals()
del out["w"]
return out
self.assertEqual(f((1, 2)), {"p": 1, "q": 2, "x": (1, 2)})
self.assertEqual(f([1, 2]), {"p": 1, "q": 2, "x": [1, 2]})
self.assertIs(f(12), None)
self.assertIs(f((1, 2, 3)), None)
def test_patma_214(self):
def f():
match 42:
case 42:
return locals()
self.assertEqual(set(f()), set())
def test_patma_215(self):
def f():
match 1:
case 1 | 2 | 3:
return locals()
self.assertEqual(set(f()), set())
def test_patma_216(self):
def f():
match ...:
case _:
return locals()
self.assertEqual(set(f()), set())
def test_patma_217(self):
def f():
match ...:
case abc:
return locals()
self.assertEqual(set(f()), {"abc"})
@no_perf
def test_patma_218(self):
self.assert_syntax_error("""
match ...:
case "a" | a:
pass
""")
@no_perf
def test_patma_219(self):
self.assert_syntax_error("""
match ...:
case a | "a":
pass
""")
def test_patma_220(self):
def f():
match ..., ...:
case a, b:
return locals()
self.assertEqual(set(f()), {"a", "b"})
@no_perf
def test_patma_221(self):
self.assert_syntax_error("""
match ...:
case a, a:
pass
""")
def test_patma_222(self):
def f():
match {"k": ..., "l": ...}:
case {"k": a, "l": b}:
return locals()
self.assertEqual(set(f()), {"a", "b"})
@no_perf
def test_patma_223(self):
self.assert_syntax_error("""
match ...:
case {"k": a, "l": a}:
pass
""")
def test_patma_224(self):
def f():
match MyClass(..., ...):
case MyClass(x, y=y):
return locals()
self.assertEqual(set(f()), {"x", "y"})
@no_perf
def test_patma_225(self):
self.assert_syntax_error("""
match ...:
case MyClass(x, x):
pass
""")
@no_perf
def test_patma_226(self):
self.assert_syntax_error("""
match ...:
case MyClass(x=x, y=x):
pass
""")
@no_perf
def test_patma_227(self):
self.assert_syntax_error("""
match ...:
case MyClass(x, y=x):
pass
""")
def test_patma_228(self):
def f():
match ...:
case b as a:
return locals()
self.assertEqual(set(f()), {"a", "b"})
@no_perf
def test_patma_229(self):
self.assert_syntax_error("""
match ...:
case a as a:
pass
""")
def test_patma_230(self):
def f(x):
match x:
case _:
return 0
self.assertEqual(f(0), 0)
self.assertEqual(f(1), 0)
self.assertEqual(f(2), 0)
self.assertEqual(f(3), 0)
def test_patma_231(self):
def f(x):
match x:
case 0:
return 0
self.assertEqual(f(0), 0)
self.assertIs(f(1), None)
self.assertIs(f(2), None)
self.assertIs(f(3), None)
def test_patma_232(self):
def f(x):
match x:
case 0:
return 0
case _:
return 1
self.assertEqual(f(0), 0)
self.assertEqual(f(1), 1)
self.assertEqual(f(2), 1)
self.assertEqual(f(3), 1)
def test_patma_233(self):
def f(x):
match x:
case 0:
return 0
case 1:
return 1
self.assertEqual(f(0), 0)
self.assertEqual(f(1), 1)
self.assertIs(f(2), None)
self.assertIs(f(3), None)
def test_patma_234(self):
def f(x):
match x:
case 0:
return 0
case 1:
return 1
case _:
return 2
self.assertEqual(f(0), 0)
self.assertEqual(f(1), 1)
self.assertEqual(f(2), 2)
self.assertEqual(f(3), 2)
def test_patma_235(self):
def f(x):
match x:
case 0:
return 0
case 1:
return 1
case 2:
return 2
self.assertEqual(f(0), 0)
self.assertEqual(f(1), 1)
self.assertEqual(f(2), 2)
self.assertIs(f(3), None)
@no_perf
def test_patma_236(self):
self.assert_syntax_error("""
match ...:
case {**rest, "key": value}:
pass
""")
@no_perf
def test_patma_237(self):
self.assert_syntax_error("""
match ...:
case {"first": first, **rest, "last": last}:
pass
""")
@no_perf
def test_patma_238(self):
self.assert_syntax_error("""
match ...:
case *a, b, *c, d, *e:
pass
""")
@no_perf
def test_patma_239(self):
self.assert_syntax_error("""
match ...:
case a, *b, c, *d, e:
pass
""")
@no_perf
def test_patma_240(self):
self.assert_syntax_error("""
match ...:
case 0+0:
pass
""")
@no_perf
def test_patma_241(self):
self.assert_syntax_error("""
match ...:
case f"":
pass
""")
@no_perf
def test_patma_242(self):
self.assert_syntax_error("""
match ...:
case f"{x}":
pass
""")
@no_perf
def test_patma_243(self):
self.assert_syntax_error("""
match 42:
case x:
pass
case y:
pass
""")
@no_perf
def test_patma_244(self):
self.assert_syntax_error("""
match ...:
case {**_}:
pass
""")
@no_perf
def test_patma_245(self):
self.assert_syntax_error("""
match ...:
case 42 as _:
pass
""")
@no_perf
def test_patma_246(self):
class Class:
__match_args__ = None
x = Class()
y = z = None
with self.assertRaises(TypeError):
match x:
case Class(y):
z = 0
self.assertIs(y, None)
self.assertIs(z, None)
@no_perf
def test_patma_247(self):
class Class:
__match_args__ = "XYZ"
x = Class()
y = z = None
with self.assertRaises(TypeError):
match x:
case Class(y):
z = 0
self.assertIs(y, None)
self.assertIs(z, None)
@no_perf
def test_patma_248(self):
class Class:
__match_args__ = (None,)
x = Class()
y = z = None
with self.assertRaises(TypeError):
match x:
case Class(y):
z = 0
self.assertIs(y, None)
self.assertIs(z, None)
@no_perf
def test_patma_249(self):
class Class:
__match_args__ = ()
x = Class()
y = z = None
with self.assertRaises(TypeError):
match x:
case Class(y):
z = 0
self.assertIs(y, None)
self.assertIs(z, None)
@no_perf
def test_patma_250(self):
self.assert_syntax_error("""
match ...:
case Class(a=_, a=_):
pass
""")
@no_perf
def test_patma_251(self):
x = {"a": 0, "b": 1}
w = y = z = None
with self.assertRaises(ValueError):
match x:
case {"a": y, "a": z}:
w = 0
self.assertIs(w, None)
self.assertIs(y, None)
self.assertIs(z, None)
@no_perf
def test_patma_252(self):
class Keys:
KEY = "a"
x = {"a": 0, "b": 1}
w = y = z = None
with self.assertRaises(ValueError):
match x:
case {Keys.KEY: y, "a": z}:
w = 0
self.assertIs(w, None)
self.assertIs(y, None)
self.assertIs(z, None)
@no_perf
def test_patma_253(self):
class Class:
__match_args__ = ("a", "a")
a = None
x = Class()
w = y = z = None
with self.assertRaises(TypeError):
match x:
case Class(y, z):
w = 0
self.assertIs(w, None)
self.assertIs(y, None)
self.assertIs(z, None)
@no_perf
def test_patma_254(self):
class Class:
__match_args__ = ("a",)
a = None
x = Class()
w = y = z = None
with self.assertRaises(TypeError):
match x:
case Class(y, a=z):
w = 0
self.assertIs(w, None)
self.assertIs(y, None)
self.assertIs(z, None)
def test_patma_255(self):
match():
case():
x = 0
self.assertEqual(x, 0)
def test_patma_256(self):
x = 0
match(x):
case(x):
y = 0
self.assertEqual(x, 0)
self.assertEqual(y, 0)
def test_patma_257(self):
x = 0
match x:
case False:
y = 0
case 0:
y = 1
self.assertEqual(x, 0)
self.assertEqual(y, 1)
def test_patma_258(self):
x = 1
match x:
case True:
y = 0
case 1:
y = 1
self.assertEqual(x, 1)
self.assertEqual(y, 1)
def test_patma_259(self):
class Eq:
def __eq__(self, other):
return True
x = eq = Eq()
y = None
match x:
case None:
y = 0
self.assertIs(x, eq)
self.assertEqual(y, None)
def test_patma_260(self):
x = False
match x:
case False:
y = 0
self.assertIs(x, False)
self.assertEqual(y, 0)
def test_patma_261(self):
x = True
match x:
case True:
y = 0
self.assertIs(x, True)
self.assertEqual(y, 0)
def test_patma_262(self):
x = None
match x:
case None:
y = 0
self.assertIs(x, None)
self.assertEqual(y, 0)
def test_patma_263(self):
x = 0
match x:
case (0 as w) as z:
y = 0
self.assertEqual(w, 0)
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertEqual(z, 0)
def test_patma_264(self):
x = 0
match x:
case (0 as w) as z:
y = 0
self.assertEqual(w, 0)
self.assertEqual(x, 0)
self.assertEqual(y, 0)
self.assertEqual(z, 0)
def test_patma_265(self):
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:
y = 0
self.assertEqual(a, 0)
self.assertEqual(b, 0)
self.assertEqual(c, 1)
self.assertEqual(d, 1)
self.assertEqual(e, (0, 1))
self.assertEqual(f, 2)
self.assertEqual(g, 2)
self.assertEqual(h, 3)
self.assertEqual(i, (2, 3))
self.assertEqual(w, (0, 1))
self.assertEqual(x, ((0, 1), (2, 3)))
self.assertEqual(y, 0)
self.assertEqual(z, (2, 3))
@no_perf
def test_patma_266(self):
self.assert_syntax_error("""
match ...:
case _ | _:
pass
""")
@no_perf
def test_patma_267(self):
self.assert_syntax_error("""
match ...:
case (_ as x) | [x]:
pass
""")
@no_perf
def test_patma_268(self):
self.assert_syntax_error("""
match ...:
case _ | _ if condition():
pass
""")
@no_perf
def test_patma_269(self):
self.assert_syntax_error("""
match ...:
case x | [_ as x] if x:
pass
""")
@no_perf
def test_patma_270(self):
self.assert_syntax_error("""
match ...:
case _:
pass
case None:
pass
""")
@no_perf
def test_patma_271(self):
self.assert_syntax_error("""
match ...:
case x:
pass
case [x] if x:
pass
""")
@no_perf
def test_patma_272(self):
self.assert_syntax_error("""
match ...:
case x:
pass
case _:
pass
""")
@no_perf
def test_patma_273(self):
self.assert_syntax_error("""
match ...:
case (None | _) | _:
pass
""")
@no_perf
def test_patma_274(self):
self.assert_syntax_error("""
match ...:
case _ | (True | False):
pass
""")
def test_patma_275(self):
x = collections.UserDict({0: 1, 2: 3})
match x:
case {2: 3}:
y = 0
self.assertEqual(x, {0: 1, 2: 3})
self.assertEqual(y, 0)
def test_patma_276(self):
x = collections.UserDict({0: 1, 2: 3})
match x:
case {2: 3, **z}:
y = 0
self.assertEqual(x, {0: 1, 2: 3})
self.assertEqual(y, 0)
self.assertEqual(z, {0: 1})
def test_patma_277(self):
x = [[{0: 0}]]
match x:
case list([({-0-0j: int(real=0+0j, imag=0-0j) | (1) as z},)]):
y = 0
self.assertEqual(x, [[{0: 0}]])
self.assertEqual(y, 0)
self.assertEqual(z, 0)
def test_patma_278(self):
x = range(3)
match x:
case [y, *_, z]:
w = 0
self.assertEqual(w, 0)
self.assertEqual(x, range(3))
self.assertEqual(y, 0)
self.assertEqual(z, 2)
def test_patma_279(self):
x = range(3)
match x:
case [_, *_, y]:
z = 0
self.assertEqual(x, range(3))
self.assertEqual(y, 2)
self.assertEqual(z, 0)
def test_patma_280(self):
x = range(3)
match x:
case [*_, y]:
z = 0
self.assertEqual(x, range(3))
self.assertEqual(y, 2)
self.assertEqual(z, 0)
@no_perf
def test_patma_281(self):
x = range(10)
y = None
with self.assertRaises(TypeError):
match x:
case range(10):
y = 0
self.assertEqual(x, range(10))
self.assertIs(y, None)
@no_perf
def test_patma_282(self):
class Class:
__match_args__ = ["spam", "eggs"]
spam = 0
eggs = 1
x = Class()
w = y = z = None
with self.assertRaises(TypeError):
match x:
case Class(y, z):
w = 0
self.assertIs(w, None)
self.assertIs(y, None)
self.assertIs(z, None)
@no_perf
def test_patma_283(self):
self.assert_syntax_error("""
match ...:
case {0+0: _}:
pass
""")
@no_perf
def test_patma_284(self):
self.assert_syntax_error("""
match ...:
case {f"": _}:
pass
""")
class PerfPatma(TestPatma):
def assertEqual(*_, **__):
pass
def assertIs(*_, **__):
pass
def assertRaises(*_, **__):
assert False, "this test should be decorated with @no_perf!"
def assertWarns(*_, **__):
assert False, "this test should be decorated with @no_perf!"
def run_perf(self):
attrs = vars(TestPatma).items()
tests = [
attr for name, attr in attrs
if name.startswith("test_") and not hasattr(attr, "no_perf")
]
for _ in range(1 << 8):
for test in tests:
test(self)
@staticmethod
def setUpClass():
raise unittest.SkipTest("performance testing")
"""
sudo ./python -m pyperf system tune && \
./python -m pyperf timeit --rigorous --setup "from test.test_patma import PerfPatma; p = PerfPatma()" "p.run_perf()"; \
sudo ./python -m pyperf system reset
"""
|