Skip to content

Commit 8ccc73b

Browse files
simplified tests and added 2 additional no match tests
1 parent 0a1dc96 commit 8ccc73b

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
@@ -2895,64 +2895,82 @@ class B(A): ...
28952895

28962896
def test_patma_union_type(self):
28972897
IntOrStr = int | str
2898-
x = 0
2899-
match x:
2898+
w = None
2899+
match 0:
29002900
case IntOrStr():
2901-
x = 1
2902-
self.assertEqual(x, 1)
2901+
w = 0
2902+
self.assertEqual(w, 0)
2903+
2904+
def test_patma_union_no_match(self):
2905+
StrOrBytes = str | bytes
2906+
w = None
2907+
match 0:
2908+
case StrOrBytes():
2909+
w = 0
2910+
self.assertIsNone(w)
29032911

29042912
def test_union_type_positional_subpattern(self):
29052913
IntOrStr = int | str
2906-
x = 1
29072914
w = None
2908-
match x:
2915+
match 0:
29092916
case IntOrStr(y):
29102917
w = y
2911-
self.assertEqual(w, 1)
2918+
self.assertEqual(w, 0)
29122919

29132920
def test_union_type_keyword_subpattern(self):
29142921
EitherPoint = Point | Point3D
29152922
p = Point(x=1, y=2)
29162923
w = None
29172924
match p:
29182925
case EitherPoint(x=1, y=2):
2919-
w = 1
2920-
self.assertEqual(w, 1)
2926+
w = 0
2927+
self.assertEqual(w, 0)
29212928

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

29302930
def test_patma_union_arg(self):
29312931
p = Point(x=1, y=2)
29322932
IntOrStr = int | str
29332933
w = None
29342934
match p:
29352935
case Point(IntOrStr(), IntOrStr()):
2936-
w = 1
2937-
self.assertEqual(w, 1)
2936+
w = 0
2937+
self.assertEqual(w, 0)
29382938

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

29482966
def test_union_type_match_second_member(self):
29492967
EitherPoint = Point | Point3D
29502968
p = Point3D(x=1, y=2, z=3)
29512969
w = None
29522970
match p:
29532971
case EitherPoint(x=1, y=2, z=3):
2954-
w = 1
2955-
self.assertEqual(w, 1)
2972+
w = 0
2973+
self.assertEqual(w, 0)
29562974

29572975

29582976

0 commit comments

Comments
 (0)