[Python-checkins] [3.12] Remove raw asserts in test_typing.py (GH-104951) (#104978)
AlexWaygood
webhook-mailer at python.org
Fri May 26 10:35:42 EDT 2023
https://github.com/python/cpython/commit/01af2b0e516608c831f4c6837087479f45368d21
commit: 01af2b0e516608c831f4c6837087479f45368d21
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: AlexWaygood <Alex.Waygood at Gmail.com>
date: 2023-05-26T14:35:35Z
summary:
[3.12] Remove raw asserts in test_typing.py (GH-104951) (#104978)
Remove raw asserts in test_typing.py (GH-104951)
(cherry picked from commit 2cb445635e99d4401949cabebd373288cfdd0138)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra at gmail.com>
files:
M Lib/test/test_typing.py
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index c8bf94307c80..ae9878f872fd 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -6474,7 +6474,7 @@ def __len__(self):
return 0
self.assertEqual(len(MMC()), 0)
- assert callable(MMC.update)
+ self.assertTrue(callable(MMC.update))
self.assertIsInstance(MMC(), typing.Mapping)
class MMB(typing.MutableMapping[KT, VT]):
@@ -6669,8 +6669,8 @@ def foo(a: A) -> Optional[BaseException]:
else:
return a()
- assert isinstance(foo(KeyboardInterrupt), KeyboardInterrupt)
- assert foo(None) is None
+ self.assertIsInstance(foo(KeyboardInterrupt), KeyboardInterrupt)
+ self.assertIsNone(foo(None))
class TestModules(TestCase):
@@ -7017,6 +7017,10 @@ def test_basics_functional_syntax(self):
self.assertEqual(Emp.__bases__, (dict,))
self.assertEqual(Emp.__annotations__, {'name': str, 'id': int})
self.assertEqual(Emp.__total__, True)
+ self.assertEqual(Emp.__required_keys__, {'name', 'id'})
+ self.assertIsInstance(Emp.__required_keys__, frozenset)
+ self.assertEqual(Emp.__optional_keys__, set())
+ self.assertIsInstance(Emp.__optional_keys__, frozenset)
def test_basics_keywords_syntax(self):
with self.assertWarns(DeprecationWarning):
@@ -7119,7 +7123,9 @@ def test_total(self):
self.assertEqual(D(x=1), {'x': 1})
self.assertEqual(D.__total__, False)
self.assertEqual(D.__required_keys__, frozenset())
+ self.assertIsInstance(D.__required_keys__, frozenset)
self.assertEqual(D.__optional_keys__, {'x'})
+ self.assertIsInstance(D.__optional_keys__, frozenset)
self.assertEqual(Options(), {})
self.assertEqual(Options(log_level=2), {'log_level': 2})
@@ -7131,8 +7137,10 @@ def test_optional_keys(self):
class Point2Dor3D(Point2D, total=False):
z: int
- assert Point2Dor3D.__required_keys__ == frozenset(['x', 'y'])
- assert Point2Dor3D.__optional_keys__ == frozenset(['z'])
+ self.assertEqual(Point2Dor3D.__required_keys__, frozenset(['x', 'y']))
+ self.assertIsInstance(Point2Dor3D.__required_keys__, frozenset)
+ self.assertEqual(Point2Dor3D.__optional_keys__, frozenset(['z']))
+ self.assertIsInstance(Point2Dor3D.__optional_keys__, frozenset)
def test_keys_inheritance(self):
class BaseAnimal(TypedDict):
@@ -7145,26 +7153,26 @@ class Animal(BaseAnimal, total=False):
class Cat(Animal):
fur_color: str
- assert BaseAnimal.__required_keys__ == frozenset(['name'])
- assert BaseAnimal.__optional_keys__ == frozenset([])
- assert BaseAnimal.__annotations__ == {'name': str}
+ self.assertEqual(BaseAnimal.__required_keys__, frozenset(['name']))
+ self.assertEqual(BaseAnimal.__optional_keys__, frozenset([]))
+ self.assertEqual(BaseAnimal.__annotations__, {'name': str})
- assert Animal.__required_keys__ == frozenset(['name'])
- assert Animal.__optional_keys__ == frozenset(['tail', 'voice'])
- assert Animal.__annotations__ == {
+ self.assertEqual(Animal.__required_keys__, frozenset(['name']))
+ self.assertEqual(Animal.__optional_keys__, frozenset(['tail', 'voice']))
+ self.assertEqual(Animal.__annotations__, {
'name': str,
'tail': bool,
'voice': str,
- }
+ })
- assert Cat.__required_keys__ == frozenset(['name', 'fur_color'])
- assert Cat.__optional_keys__ == frozenset(['tail', 'voice'])
- assert Cat.__annotations__ == {
+ self.assertEqual(Cat.__required_keys__, frozenset(['name', 'fur_color']))
+ self.assertEqual(Cat.__optional_keys__, frozenset(['tail', 'voice']))
+ self.assertEqual(Cat.__annotations__, {
'fur_color': str,
'name': str,
'tail': bool,
'voice': str,
- }
+ })
def test_required_notrequired_keys(self):
self.assertEqual(NontotalMovie.__required_keys__,
@@ -7394,11 +7402,11 @@ class C(B[int]):
self.assertEqual(C.__total__, True)
self.assertEqual(C.__optional_keys__, frozenset(['b']))
self.assertEqual(C.__required_keys__, frozenset(['a', 'c']))
- assert C.__annotations__ == {
+ self.assertEqual(C.__annotations__, {
'a': T,
'b': KT,
'c': int,
- }
+ })
with self.assertRaises(TypeError):
C[str]
@@ -7413,11 +7421,11 @@ class Point3D(Point2DGeneric[T], Generic[T, KT]):
self.assertEqual(Point3D.__total__, True)
self.assertEqual(Point3D.__optional_keys__, frozenset())
self.assertEqual(Point3D.__required_keys__, frozenset(['a', 'b', 'c']))
- assert Point3D.__annotations__ == {
+ self.assertEqual(Point3D.__annotations__, {
'a': T,
'b': T,
'c': KT,
- }
+ })
self.assertEqual(Point3D[int, str].__origin__, Point3D)
with self.assertRaises(TypeError):
@@ -7444,11 +7452,11 @@ class WithImplicitAny(B):
self.assertEqual(WithImplicitAny.__total__, True)
self.assertEqual(WithImplicitAny.__optional_keys__, frozenset(['b']))
self.assertEqual(WithImplicitAny.__required_keys__, frozenset(['a', 'c']))
- assert WithImplicitAny.__annotations__ == {
+ self.assertEqual(WithImplicitAny.__annotations__, {
'a': T,
'b': KT,
'c': int,
- }
+ })
with self.assertRaises(TypeError):
WithImplicitAny[str]
More information about the Python-checkins
mailing list