@@ -115,18 +115,18 @@ def test_errors(self):
115
115
116
116
def test_can_subclass (self ):
117
117
class Mock (Any ): pass
118
- self .assertTrue ( issubclass ( Mock , Any ) )
118
+ self .assertIsSubclass ( Mock , Any )
119
119
self .assertIsInstance (Mock (), Mock )
120
120
121
121
class Something : pass
122
- self .assertFalse ( issubclass ( Something , Any ) )
122
+ self .assertNotIsSubclass ( Something , Any )
123
123
self .assertNotIsInstance (Something (), Mock )
124
124
125
125
class MockSomething (Something , Mock ): pass
126
- self .assertTrue ( issubclass ( MockSomething , Any ) )
127
- self .assertTrue ( issubclass ( MockSomething , MockSomething ) )
128
- self .assertTrue ( issubclass ( MockSomething , Something ) )
129
- self .assertTrue ( issubclass ( MockSomething , Mock ) )
126
+ self .assertIsSubclass ( MockSomething , Any )
127
+ self .assertIsSubclass ( MockSomething , MockSomething )
128
+ self .assertIsSubclass ( MockSomething , Something )
129
+ self .assertIsSubclass ( MockSomething , Mock )
130
130
ms = MockSomething ()
131
131
self .assertIsInstance (ms , MockSomething )
132
132
self .assertIsInstance (ms , Something )
@@ -1997,11 +1997,11 @@ def test_basics(self):
1997
1997
self .assertNotEqual (u , Union )
1998
1998
1999
1999
def test_union_isinstance (self ):
2000
- self .assertTrue ( isinstance ( 42 , Union [int , str ]) )
2001
- self .assertTrue ( isinstance ( 'abc' , Union [int , str ]) )
2002
- self .assertFalse ( isinstance ( 3.14 , Union [int , str ]) )
2003
- self .assertTrue ( isinstance ( 42 , Union [int , list [int ]]) )
2004
- self .assertTrue ( isinstance ( 42 , Union [int , Any ]) )
2000
+ self .assertIsInstance ( 42 , Union [int , str ])
2001
+ self .assertIsInstance ( 'abc' , Union [int , str ])
2002
+ self .assertNotIsInstance ( 3.14 , Union [int , str ])
2003
+ self .assertIsInstance ( 42 , Union [int , list [int ]])
2004
+ self .assertIsInstance ( 42 , Union [int , Any ])
2005
2005
2006
2006
def test_union_isinstance_type_error (self ):
2007
2007
with self .assertRaises (TypeError ):
@@ -2018,9 +2018,9 @@ def test_union_isinstance_type_error(self):
2018
2018
isinstance (42 , Union [Any , str ])
2019
2019
2020
2020
def test_optional_isinstance (self ):
2021
- self .assertTrue ( isinstance ( 42 , Optional [int ]) )
2022
- self .assertTrue ( isinstance ( None , Optional [int ]) )
2023
- self .assertFalse ( isinstance ( 'abc' , Optional [int ]) )
2021
+ self .assertIsInstance ( 42 , Optional [int ])
2022
+ self .assertIsInstance ( None , Optional [int ])
2023
+ self .assertNotIsInstance ( 'abc' , Optional [int ])
2024
2024
2025
2025
def test_optional_isinstance_type_error (self ):
2026
2026
with self .assertRaises (TypeError ):
@@ -2033,14 +2033,14 @@ def test_optional_isinstance_type_error(self):
2033
2033
isinstance (None , Optional [Any ])
2034
2034
2035
2035
def test_union_issubclass (self ):
2036
- self .assertTrue ( issubclass ( int , Union [int , str ]) )
2037
- self .assertTrue ( issubclass ( str , Union [int , str ]) )
2038
- self .assertFalse ( issubclass ( float , Union [int , str ]) )
2039
- self .assertTrue ( issubclass ( int , Union [int , list [int ]]) )
2040
- self .assertTrue ( issubclass ( int , Union [int , Any ]) )
2041
- self .assertFalse ( issubclass ( int , Union [str , Any ]) )
2042
- self .assertTrue ( issubclass ( int , Union [Any , int ]) )
2043
- self .assertFalse ( issubclass ( int , Union [Any , str ]) )
2036
+ self .assertIsSubclass ( int , Union [int , str ])
2037
+ self .assertIsSubclass ( str , Union [int , str ])
2038
+ self .assertNotIsSubclass ( float , Union [int , str ])
2039
+ self .assertIsSubclass ( int , Union [int , list [int ]])
2040
+ self .assertIsSubclass ( int , Union [int , Any ])
2041
+ self .assertNotIsSubclass ( int , Union [str , Any ])
2042
+ self .assertIsSubclass ( int , Union [Any , int ])
2043
+ self .assertNotIsSubclass ( int , Union [Any , str ])
2044
2044
2045
2045
def test_union_issubclass_type_error (self ):
2046
2046
with self .assertRaises (TypeError ):
@@ -2057,12 +2057,12 @@ def test_union_issubclass_type_error(self):
2057
2057
issubclass (int , Union [list [int ], str ])
2058
2058
2059
2059
def test_optional_issubclass (self ):
2060
- self .assertTrue ( issubclass ( int , Optional [int ]) )
2061
- self .assertTrue ( issubclass ( type (None ), Optional [int ]) )
2062
- self .assertFalse ( issubclass ( str , Optional [int ]) )
2063
- self .assertTrue ( issubclass ( Any , Optional [Any ]) )
2064
- self .assertTrue ( issubclass ( type (None ), Optional [Any ]) )
2065
- self .assertFalse ( issubclass ( int , Optional [Any ]) )
2060
+ self .assertIsSubclass ( int , Optional [int ])
2061
+ self .assertIsSubclass ( type (None ), Optional [int ])
2062
+ self .assertNotIsSubclass ( str , Optional [int ])
2063
+ self .assertIsSubclass ( Any , Optional [Any ])
2064
+ self .assertIsSubclass ( type (None ), Optional [Any ])
2065
+ self .assertNotIsSubclass ( int , Optional [Any ])
2066
2066
2067
2067
def test_optional_issubclass_type_error (self ):
2068
2068
with self .assertRaises (TypeError ):
@@ -4050,8 +4050,8 @@ def test_generic_protocols_repr(self):
4050
4050
4051
4051
class P (Protocol [T , S ]): pass
4052
4052
4053
- self .assertTrue (repr (P [T , S ]). endswith ( 'P[~T, ~S]' ) )
4054
- self .assertTrue (repr (P [int , str ]). endswith ( 'P[int, str]' ) )
4053
+ self .assertEndsWith (repr (P [T , S ]), 'P[~T, ~S]' )
4054
+ self .assertEndsWith (repr (P [int , str ]), 'P[int, str]' )
4055
4055
4056
4056
def test_generic_protocols_eq (self ):
4057
4057
T = TypeVar ('T' )
@@ -4641,8 +4641,7 @@ class C(Generic[T]):
4641
4641
self .assertNotEqual (Z , Y [int ])
4642
4642
self .assertNotEqual (Z , Y [T ])
4643
4643
4644
- self .assertTrue (str (Z ).endswith (
4645
- '.C[typing.Tuple[str, int]]' ))
4644
+ self .assertEndsWith (str (Z ), '.C[typing.Tuple[str, int]]' )
4646
4645
4647
4646
def test_new_repr (self ):
4648
4647
T = TypeVar ('T' )
@@ -4870,12 +4869,12 @@ class A(Generic[T]):
4870
4869
self .assertNotEqual (typing .FrozenSet [A [str ]],
4871
4870
typing .FrozenSet [mod_generics_cache .B .A [str ]])
4872
4871
4873
- self .assertTrue (repr (Tuple [A [str ]]). endswith ( '<locals>.A[str]]' ) )
4874
- self .assertTrue (repr (Tuple [B .A [str ]]). endswith ( '<locals>.B.A[str]]' ) )
4875
- self .assertTrue (repr (Tuple [mod_generics_cache .A [str ]])
4876
- . endswith ( 'mod_generics_cache.A[str]]' ) )
4877
- self .assertTrue (repr (Tuple [mod_generics_cache .B .A [str ]])
4878
- . endswith ( 'mod_generics_cache.B.A[str]]' ) )
4872
+ self .assertEndsWith (repr (Tuple [A [str ]]), '<locals>.A[str]]' )
4873
+ self .assertEndsWith (repr (Tuple [B .A [str ]]), '<locals>.B.A[str]]' )
4874
+ self .assertEndsWith (repr (Tuple [mod_generics_cache .A [str ]]),
4875
+ 'mod_generics_cache.A[str]]' )
4876
+ self .assertEndsWith (repr (Tuple [mod_generics_cache .B .A [str ]]),
4877
+ 'mod_generics_cache.B.A[str]]' )
4879
4878
4880
4879
def test_extended_generic_rules_eq (self ):
4881
4880
T = TypeVar ('T' )
@@ -5817,7 +5816,7 @@ def __call__(self, *args, **kwargs):
5817
5816
@Wrapper
5818
5817
def wrapped (): ...
5819
5818
self .assertIsInstance (wrapped , Wrapper )
5820
- self .assertIs ( False , hasattr ( wrapped , "__final__" ) )
5819
+ self .assertNotHasAttr ( wrapped , "__final__" )
5821
5820
5822
5821
class Meta (type ):
5823
5822
@property
@@ -5829,7 +5828,7 @@ class WithMeta(metaclass=Meta): ...
5829
5828
# Builtin classes throw TypeError if you try to set an
5830
5829
# attribute.
5831
5830
final (int )
5832
- self .assertIs ( False , hasattr ( int , "__final__" ) )
5831
+ self .assertNotHasAttr ( int , "__final__" )
5833
5832
5834
5833
# Make sure it works with common builtin decorators
5835
5834
class Methods :
@@ -5910,19 +5909,19 @@ def static_method_bad_order():
5910
5909
self .assertEqual (Derived .class_method_good_order (), 42 )
5911
5910
self .assertIs (True , Derived .class_method_good_order .__override__ )
5912
5911
self .assertEqual (Derived .class_method_bad_order (), 42 )
5913
- self .assertIs ( False , hasattr ( Derived .class_method_bad_order , "__override__" ) )
5912
+ self .assertNotHasAttr ( Derived .class_method_bad_order , "__override__" )
5914
5913
5915
5914
self .assertEqual (Derived .static_method_good_order (), 42 )
5916
5915
self .assertIs (True , Derived .static_method_good_order .__override__ )
5917
5916
self .assertEqual (Derived .static_method_bad_order (), 42 )
5918
- self .assertIs ( False , hasattr ( Derived .static_method_bad_order , "__override__" ) )
5917
+ self .assertNotHasAttr ( Derived .static_method_bad_order , "__override__" )
5919
5918
5920
5919
# Base object is not changed:
5921
- self .assertIs ( False , hasattr ( Base .normal_method , "__override__" ) )
5922
- self .assertIs ( False , hasattr ( Base .class_method_good_order , "__override__" ) )
5923
- self .assertIs ( False , hasattr ( Base .class_method_bad_order , "__override__" ) )
5924
- self .assertIs ( False , hasattr ( Base .static_method_good_order , "__override__" ) )
5925
- self .assertIs ( False , hasattr ( Base .static_method_bad_order , "__override__" ) )
5920
+ self .assertNotHasAttr ( Base .normal_method , "__override__" )
5921
+ self .assertNotHasAttr ( Base .class_method_good_order , "__override__" )
5922
+ self .assertNotHasAttr ( Base .class_method_bad_order , "__override__" )
5923
+ self .assertNotHasAttr ( Base .static_method_good_order , "__override__" )
5924
+ self .assertNotHasAttr ( Base .static_method_bad_order , "__override__" )
5926
5925
5927
5926
def test_property (self ):
5928
5927
class Base :
@@ -5947,8 +5946,8 @@ def wrong(self) -> int:
5947
5946
self .assertEqual (instance .correct , 2 )
5948
5947
self .assertTrue (Child .correct .fget .__override__ )
5949
5948
self .assertEqual (instance .wrong , 2 )
5950
- self .assertFalse ( hasattr ( Child .wrong , "__override__" ) )
5951
- self .assertFalse ( hasattr ( Child .wrong .fset , "__override__" ) )
5949
+ self .assertNotHasAttr ( Child .wrong , "__override__" )
5950
+ self .assertNotHasAttr ( Child .wrong .fset , "__override__" )
5952
5951
5953
5952
def test_silent_failure (self ):
5954
5953
class CustomProp :
@@ -5965,7 +5964,7 @@ def some(self):
5965
5964
return 1
5966
5965
5967
5966
self .assertEqual (WithOverride .some , 1 )
5968
- self .assertFalse ( hasattr ( WithOverride .some , "__override__" ) )
5967
+ self .assertNotHasAttr ( WithOverride .some , "__override__" )
5969
5968
5970
5969
def test_multiple_decorators (self ):
5971
5970
def with_wraps (f ): # similar to `lru_cache` definition
@@ -10474,7 +10473,7 @@ def test_special_attrs2(self):
10474
10473
# to the variable name to which it is assigned". Thus, providing
10475
10474
# __qualname__ is unnecessary.
10476
10475
self .assertEqual (SpecialAttrsT .__name__ , 'SpecialAttrsT' )
10477
- self .assertFalse ( hasattr ( SpecialAttrsT , '__qualname__' ) )
10476
+ self .assertNotHasAttr ( SpecialAttrsT , '__qualname__' )
10478
10477
self .assertEqual (SpecialAttrsT .__module__ , __name__ )
10479
10478
# Module-level type variables are picklable.
10480
10479
for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
@@ -10483,7 +10482,7 @@ def test_special_attrs2(self):
10483
10482
self .assertIs (SpecialAttrsT , loaded )
10484
10483
10485
10484
self .assertEqual (SpecialAttrsP .__name__ , 'SpecialAttrsP' )
10486
- self .assertFalse ( hasattr ( SpecialAttrsP , '__qualname__' ) )
10485
+ self .assertNotHasAttr ( SpecialAttrsP , '__qualname__' )
10487
10486
self .assertEqual (SpecialAttrsP .__module__ , __name__ )
10488
10487
# Module-level ParamSpecs are picklable.
10489
10488
for proto in range (pickle .HIGHEST_PROTOCOL + 1 ):
0 commit comments