@@ -6474,7 +6474,7 @@ def __len__(self):
6474
6474
return 0
6475
6475
6476
6476
self .assertEqual (len (MMC ()), 0 )
6477
- assert callable (MMC .update )
6477
+ self . assertTrue ( callable (MMC .update ) )
6478
6478
self .assertIsInstance (MMC (), typing .Mapping )
6479
6479
6480
6480
class MMB (typing .MutableMapping [KT , VT ]):
@@ -6669,8 +6669,8 @@ def foo(a: A) -> Optional[BaseException]:
6669
6669
else :
6670
6670
return a ()
6671
6671
6672
- assert isinstance (foo (KeyboardInterrupt ), KeyboardInterrupt )
6673
- assert foo (None ) is None
6672
+ self . assertIsInstance (foo (KeyboardInterrupt ), KeyboardInterrupt )
6673
+ self . assertIsNone ( foo (None ))
6674
6674
6675
6675
6676
6676
class TestModules (TestCase ):
@@ -7017,6 +7017,10 @@ def test_basics_functional_syntax(self):
7017
7017
self .assertEqual (Emp .__bases__ , (dict ,))
7018
7018
self .assertEqual (Emp .__annotations__ , {'name' : str , 'id' : int })
7019
7019
self .assertEqual (Emp .__total__ , True )
7020
+ self .assertEqual (Emp .__required_keys__ , {'name' , 'id' })
7021
+ self .assertIsInstance (Emp .__required_keys__ , frozenset )
7022
+ self .assertEqual (Emp .__optional_keys__ , set ())
7023
+ self .assertIsInstance (Emp .__optional_keys__ , frozenset )
7020
7024
7021
7025
def test_basics_keywords_syntax (self ):
7022
7026
with self .assertWarns (DeprecationWarning ):
@@ -7119,7 +7123,9 @@ def test_total(self):
7119
7123
self .assertEqual (D (x = 1 ), {'x' : 1 })
7120
7124
self .assertEqual (D .__total__ , False )
7121
7125
self .assertEqual (D .__required_keys__ , frozenset ())
7126
+ self .assertIsInstance (D .__required_keys__ , frozenset )
7122
7127
self .assertEqual (D .__optional_keys__ , {'x' })
7128
+ self .assertIsInstance (D .__optional_keys__ , frozenset )
7123
7129
7124
7130
self .assertEqual (Options (), {})
7125
7131
self .assertEqual (Options (log_level = 2 ), {'log_level' : 2 })
@@ -7131,8 +7137,10 @@ def test_optional_keys(self):
7131
7137
class Point2Dor3D (Point2D , total = False ):
7132
7138
z : int
7133
7139
7134
- assert Point2Dor3D .__required_keys__ == frozenset (['x' , 'y' ])
7135
- assert Point2Dor3D .__optional_keys__ == frozenset (['z' ])
7140
+ self .assertEqual (Point2Dor3D .__required_keys__ , frozenset (['x' , 'y' ]))
7141
+ self .assertIsInstance (Point2Dor3D .__required_keys__ , frozenset )
7142
+ self .assertEqual (Point2Dor3D .__optional_keys__ , frozenset (['z' ]))
7143
+ self .assertIsInstance (Point2Dor3D .__optional_keys__ , frozenset )
7136
7144
7137
7145
def test_keys_inheritance (self ):
7138
7146
class BaseAnimal (TypedDict ):
@@ -7145,26 +7153,26 @@ class Animal(BaseAnimal, total=False):
7145
7153
class Cat (Animal ):
7146
7154
fur_color : str
7147
7155
7148
- assert BaseAnimal .__required_keys__ == frozenset (['name' ])
7149
- assert BaseAnimal .__optional_keys__ == frozenset ([])
7150
- assert BaseAnimal .__annotations__ == {'name' : str }
7156
+ self . assertEqual ( BaseAnimal .__required_keys__ , frozenset (['name' ]) )
7157
+ self . assertEqual ( BaseAnimal .__optional_keys__ , frozenset ([]) )
7158
+ self . assertEqual ( BaseAnimal .__annotations__ , {'name' : str })
7151
7159
7152
- assert Animal .__required_keys__ == frozenset (['name' ])
7153
- assert Animal .__optional_keys__ == frozenset (['tail' , 'voice' ])
7154
- assert Animal .__annotations__ == {
7160
+ self . assertEqual ( Animal .__required_keys__ , frozenset (['name' ]) )
7161
+ self . assertEqual ( Animal .__optional_keys__ , frozenset (['tail' , 'voice' ]) )
7162
+ self . assertEqual ( Animal .__annotations__ , {
7155
7163
'name' : str ,
7156
7164
'tail' : bool ,
7157
7165
'voice' : str ,
7158
- }
7166
+ })
7159
7167
7160
- assert Cat .__required_keys__ == frozenset (['name' , 'fur_color' ])
7161
- assert Cat .__optional_keys__ == frozenset (['tail' , 'voice' ])
7162
- assert Cat .__annotations__ == {
7168
+ self . assertEqual ( Cat .__required_keys__ , frozenset (['name' , 'fur_color' ]) )
7169
+ self . assertEqual ( Cat .__optional_keys__ , frozenset (['tail' , 'voice' ]) )
7170
+ self . assertEqual ( Cat .__annotations__ , {
7163
7171
'fur_color' : str ,
7164
7172
'name' : str ,
7165
7173
'tail' : bool ,
7166
7174
'voice' : str ,
7167
- }
7175
+ })
7168
7176
7169
7177
def test_required_notrequired_keys (self ):
7170
7178
self .assertEqual (NontotalMovie .__required_keys__ ,
@@ -7394,11 +7402,11 @@ class C(B[int]):
7394
7402
self .assertEqual (C .__total__ , True )
7395
7403
self .assertEqual (C .__optional_keys__ , frozenset (['b' ]))
7396
7404
self .assertEqual (C .__required_keys__ , frozenset (['a' , 'c' ]))
7397
- assert C .__annotations__ == {
7405
+ self . assertEqual ( C .__annotations__ , {
7398
7406
'a' : T ,
7399
7407
'b' : KT ,
7400
7408
'c' : int ,
7401
- }
7409
+ })
7402
7410
with self .assertRaises (TypeError ):
7403
7411
C [str ]
7404
7412
@@ -7413,11 +7421,11 @@ class Point3D(Point2DGeneric[T], Generic[T, KT]):
7413
7421
self .assertEqual (Point3D .__total__ , True )
7414
7422
self .assertEqual (Point3D .__optional_keys__ , frozenset ())
7415
7423
self .assertEqual (Point3D .__required_keys__ , frozenset (['a' , 'b' , 'c' ]))
7416
- assert Point3D .__annotations__ == {
7424
+ self . assertEqual ( Point3D .__annotations__ , {
7417
7425
'a' : T ,
7418
7426
'b' : T ,
7419
7427
'c' : KT ,
7420
- }
7428
+ })
7421
7429
self .assertEqual (Point3D [int , str ].__origin__ , Point3D )
7422
7430
7423
7431
with self .assertRaises (TypeError ):
@@ -7444,11 +7452,11 @@ class WithImplicitAny(B):
7444
7452
self .assertEqual (WithImplicitAny .__total__ , True )
7445
7453
self .assertEqual (WithImplicitAny .__optional_keys__ , frozenset (['b' ]))
7446
7454
self .assertEqual (WithImplicitAny .__required_keys__ , frozenset (['a' , 'c' ]))
7447
- assert WithImplicitAny .__annotations__ == {
7455
+ self . assertEqual ( WithImplicitAny .__annotations__ , {
7448
7456
'a' : T ,
7449
7457
'b' : KT ,
7450
7458
'c' : int ,
7451
- }
7459
+ })
7452
7460
with self .assertRaises (TypeError ):
7453
7461
WithImplicitAny [str ]
7454
7462
0 commit comments