@@ -5956,7 +5956,7 @@ def __len__(self):
5956
5956
return 0
5957
5957
5958
5958
self .assertEqual (len (MMC ()), 0 )
5959
- assert callable (MMC .update )
5959
+ self . assertTrue ( callable (MMC .update ) )
5960
5960
self .assertIsInstance (MMC (), typing .Mapping )
5961
5961
5962
5962
class MMB (typing .MutableMapping [KT , VT ]):
@@ -6151,8 +6151,8 @@ def foo(a: A) -> Optional[BaseException]:
6151
6151
else :
6152
6152
return a ()
6153
6153
6154
- assert isinstance (foo (KeyboardInterrupt ), KeyboardInterrupt )
6155
- assert foo (None ) is None
6154
+ self . assertIsInstance (foo (KeyboardInterrupt ), KeyboardInterrupt )
6155
+ self . assertIsNone ( foo (None ))
6156
6156
6157
6157
6158
6158
class TestModules (TestCase ):
@@ -6483,6 +6483,10 @@ def test_basics_functional_syntax(self):
6483
6483
self .assertEqual (Emp .__bases__ , (dict ,))
6484
6484
self .assertEqual (Emp .__annotations__ , {'name' : str , 'id' : int })
6485
6485
self .assertEqual (Emp .__total__ , True )
6486
+ self .assertEqual (Emp .__required_keys__ , {'name' , 'id' })
6487
+ self .assertIsInstance (Emp .__required_keys__ , frozenset )
6488
+ self .assertEqual (Emp .__optional_keys__ , set ())
6489
+ self .assertIsInstance (Emp .__optional_keys__ , frozenset )
6486
6490
6487
6491
def test_basics_keywords_syntax (self ):
6488
6492
with self .assertWarns (DeprecationWarning ):
@@ -6585,7 +6589,9 @@ def test_total(self):
6585
6589
self .assertEqual (D (x = 1 ), {'x' : 1 })
6586
6590
self .assertEqual (D .__total__ , False )
6587
6591
self .assertEqual (D .__required_keys__ , frozenset ())
6592
+ self .assertIsInstance (D .__required_keys__ , frozenset )
6588
6593
self .assertEqual (D .__optional_keys__ , {'x' })
6594
+ self .assertIsInstance (D .__optional_keys__ , frozenset )
6589
6595
6590
6596
self .assertEqual (Options (), {})
6591
6597
self .assertEqual (Options (log_level = 2 ), {'log_level' : 2 })
@@ -6597,8 +6603,10 @@ def test_optional_keys(self):
6597
6603
class Point2Dor3D (Point2D , total = False ):
6598
6604
z : int
6599
6605
6600
- assert Point2Dor3D .__required_keys__ == frozenset (['x' , 'y' ])
6601
- assert Point2Dor3D .__optional_keys__ == frozenset (['z' ])
6606
+ self .assertEqual (Point2Dor3D .__required_keys__ , frozenset (['x' , 'y' ]))
6607
+ self .assertIsInstance (Point2Dor3D .__required_keys__ , frozenset )
6608
+ self .assertEqual (Point2Dor3D .__optional_keys__ , frozenset (['z' ]))
6609
+ self .assertIsInstance (Point2Dor3D .__optional_keys__ , frozenset )
6602
6610
6603
6611
def test_keys_inheritance (self ):
6604
6612
class BaseAnimal (TypedDict ):
@@ -6611,26 +6619,26 @@ class Animal(BaseAnimal, total=False):
6611
6619
class Cat (Animal ):
6612
6620
fur_color : str
6613
6621
6614
- assert BaseAnimal .__required_keys__ == frozenset (['name' ])
6615
- assert BaseAnimal .__optional_keys__ == frozenset ([])
6616
- assert BaseAnimal .__annotations__ == {'name' : str }
6622
+ self . assertEqual ( BaseAnimal .__required_keys__ , frozenset (['name' ]) )
6623
+ self . assertEqual ( BaseAnimal .__optional_keys__ , frozenset ([]) )
6624
+ self . assertEqual ( BaseAnimal .__annotations__ , {'name' : str })
6617
6625
6618
- assert Animal .__required_keys__ == frozenset (['name' ])
6619
- assert Animal .__optional_keys__ == frozenset (['tail' , 'voice' ])
6620
- assert Animal .__annotations__ == {
6626
+ self . assertEqual ( Animal .__required_keys__ , frozenset (['name' ]) )
6627
+ self . assertEqual ( Animal .__optional_keys__ , frozenset (['tail' , 'voice' ]) )
6628
+ self . assertEqual ( Animal .__annotations__ , {
6621
6629
'name' : str ,
6622
6630
'tail' : bool ,
6623
6631
'voice' : str ,
6624
- }
6632
+ })
6625
6633
6626
- assert Cat .__required_keys__ == frozenset (['name' , 'fur_color' ])
6627
- assert Cat .__optional_keys__ == frozenset (['tail' , 'voice' ])
6628
- assert Cat .__annotations__ == {
6634
+ self . assertEqual ( Cat .__required_keys__ , frozenset (['name' , 'fur_color' ]) )
6635
+ self . assertEqual ( Cat .__optional_keys__ , frozenset (['tail' , 'voice' ]) )
6636
+ self . assertEqual ( Cat .__annotations__ , {
6629
6637
'fur_color' : str ,
6630
6638
'name' : str ,
6631
6639
'tail' : bool ,
6632
6640
'voice' : str ,
6633
- }
6641
+ })
6634
6642
6635
6643
def test_required_notrequired_keys (self ):
6636
6644
self .assertEqual (NontotalMovie .__required_keys__ ,
@@ -6840,11 +6848,11 @@ class C(B[int]):
6840
6848
self .assertEqual (C .__total__ , True )
6841
6849
self .assertEqual (C .__optional_keys__ , frozenset (['b' ]))
6842
6850
self .assertEqual (C .__required_keys__ , frozenset (['a' , 'c' ]))
6843
- assert C .__annotations__ == {
6851
+ self . assertEqual ( C .__annotations__ , {
6844
6852
'a' : T ,
6845
6853
'b' : KT ,
6846
6854
'c' : int ,
6847
- }
6855
+ })
6848
6856
with self .assertRaises (TypeError ):
6849
6857
C [str ]
6850
6858
@@ -6859,11 +6867,11 @@ class Point3D(Point2DGeneric[T], Generic[T, KT]):
6859
6867
self .assertEqual (Point3D .__total__ , True )
6860
6868
self .assertEqual (Point3D .__optional_keys__ , frozenset ())
6861
6869
self .assertEqual (Point3D .__required_keys__ , frozenset (['a' , 'b' , 'c' ]))
6862
- assert Point3D .__annotations__ == {
6870
+ self . assertEqual ( Point3D .__annotations__ , {
6863
6871
'a' : T ,
6864
6872
'b' : T ,
6865
6873
'c' : KT ,
6866
- }
6874
+ })
6867
6875
self .assertEqual (Point3D [int , str ].__origin__ , Point3D )
6868
6876
6869
6877
with self .assertRaises (TypeError ):
@@ -6890,11 +6898,11 @@ class WithImplicitAny(B):
6890
6898
self .assertEqual (WithImplicitAny .__total__ , True )
6891
6899
self .assertEqual (WithImplicitAny .__optional_keys__ , frozenset (['b' ]))
6892
6900
self .assertEqual (WithImplicitAny .__required_keys__ , frozenset (['a' , 'c' ]))
6893
- assert WithImplicitAny .__annotations__ == {
6901
+ self . assertEqual ( WithImplicitAny .__annotations__ , {
6894
6902
'a' : T ,
6895
6903
'b' : KT ,
6896
6904
'c' : int ,
6897
- }
6905
+ })
6898
6906
with self .assertRaises (TypeError ):
6899
6907
WithImplicitAny [str ]
6900
6908
0 commit comments