Skip to content

Commit 1b32cc9

Browse files
simplified tests and added 2 additional no match tests
1 parent eee5ab3 commit 1b32cc9

File tree

1 file changed

+40
-22
lines changed

1 file changed

+40
-22
lines changed

Lib/test/test_patma.py

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,64 +2897,82 @@ class B(A): ...
28972897

28982898
def test_patma_union_type(self):
28992899
IntOrStr = int | str
2900-
x = 0
2901-
match x:
2900+
w = None
2901+
match 0:
29022902
case IntOrStr():
2903-
x = 1
2904-
self.assertEqual(x, 1)
2903+
w = 0
2904+
self.assertEqual(w, 0)
2905+
2906+
def test_patma_union_no_match(self):
2907+
StrOrBytes = str | bytes
2908+
w = None
2909+
match 0:
2910+
case StrOrBytes():
2911+
w = 0
2912+
self.assertIsNone(w)
29052913

29062914
def test_union_type_positional_subpattern(self):
29072915
IntOrStr = int | str
2908-
x = 1
29092916
w = None
2910-
match x:
2917+
match 0:
29112918
case IntOrStr(y):
29122919
w = y
2913-
self.assertEqual(w, 1)
2920+
self.assertEqual(w, 0)
29142921

29152922
def test_union_type_keyword_subpattern(self):
29162923
EitherPoint = Point | Point3D
29172924
p = Point(x=1, y=2)
29182925
w = None
29192926
match p:
29202927
case EitherPoint(x=1, y=2):
2921-
w = 1
2922-
self.assertEqual(w, 1)
2928+
w = 0
2929+
self.assertEqual(w, 0)
29232930

2924-
def test_patma_union_no_match(self):
2925-
IntOrStr = int | str
2926-
x = None
2927-
match x:
2928-
case IntOrStr():
2929-
x = 1
2930-
self.assertIsNone(x)
29312931

29322932
def test_patma_union_arg(self):
29332933
p = Point(x=1, y=2)
29342934
IntOrStr = int | str
29352935
w = None
29362936
match p:
29372937
case Point(IntOrStr(), IntOrStr()):
2938-
w = 1
2939-
self.assertEqual(w, 1)
2938+
w = 0
2939+
self.assertEqual(w, 0)
29402940

29412941
def test_patma_union_kwarg(self):
29422942
p = Point(x=1, y=2)
29432943
IntOrStr = int | str
29442944
w = None
29452945
match p:
29462946
case Point(x=IntOrStr(), y=IntOrStr()):
2947-
w = 1
2948-
self.assertEqual(w, 1)
2947+
w = 0
2948+
self.assertEqual(w, 0)
2949+
2950+
def test_patma_union_arg_no_match(self):
2951+
p = Point(x=1, y=2)
2952+
StrOrBytes = str | bytes
2953+
w = None
2954+
match p:
2955+
case Point(StrOrBytes(), StrOrBytes()):
2956+
w = 0
2957+
self.assertIsNone(w)
2958+
2959+
def test_patma_union_kwarg_no_match(self):
2960+
p = Point(x=1, y=2)
2961+
StrOrBytes = str | bytes
2962+
w = None
2963+
match p:
2964+
case Point(x=StrOrBytes(), y=StrOrBytes()):
2965+
w = 0
2966+
self.assertIsNone(w)
29492967

29502968
def test_union_type_match_second_member(self):
29512969
EitherPoint = Point | Point3D
29522970
p = Point3D(x=1, y=2, z=3)
29532971
w = None
29542972
match p:
29552973
case EitherPoint(x=1, y=2, z=3):
2956-
w = 1
2957-
self.assertEqual(w, 1)
2974+
w = 0
2975+
self.assertEqual(w, 0)
29582976

29592977

29602978

0 commit comments

Comments
 (0)