https://github.com/python/cpython/commit/89c401fb9a612b9618bd513508e67dededb0f031
commit: 89c401fb9a612b9618bd513508e67dededb0f031
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2025-01-20T11:17:04+02:00
summary:
gh-71339: Use new assertion methods in test_functools (GH-128829)
files:
M Lib/test/test_functools.py
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 32224866082824..4beb4380c3ad6b 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -645,11 +645,11 @@ def test_bound_method_introspection(self):
def test_unbound_method_retrieval(self):
obj = self.A
- self.assertFalse(hasattr(obj.both, "__self__"))
- self.assertFalse(hasattr(obj.nested, "__self__"))
- self.assertFalse(hasattr(obj.over_partial, "__self__"))
- self.assertFalse(hasattr(obj.static, "__self__"))
- self.assertFalse(hasattr(self.a.static, "__self__"))
+ self.assertNotHasAttr(obj.both, "__self__")
+ self.assertNotHasAttr(obj.nested, "__self__")
+ self.assertNotHasAttr(obj.over_partial, "__self__")
+ self.assertNotHasAttr(obj.static, "__self__")
+ self.assertNotHasAttr(self.a.static, "__self__")
def test_descriptors(self):
for obj in [self.A, self.a]:
@@ -791,7 +791,7 @@ def wrapper():
self.assertNotEqual(wrapper.__qualname__, f.__qualname__)
self.assertEqual(wrapper.__doc__, None)
self.assertEqual(wrapper.__annotations__, {})
- self.assertFalse(hasattr(wrapper, 'attr'))
+ self.assertNotHasAttr(wrapper, 'attr')
def test_selective_update(self):
def f():
@@ -840,7 +840,7 @@ def wrapper():
pass
functools.update_wrapper(wrapper, max)
self.assertEqual(wrapper.__name__, 'max')
- self.assertTrue(wrapper.__doc__.startswith('max('))
+ self.assertStartsWith(wrapper.__doc__, 'max(')
self.assertEqual(wrapper.__annotations__, {})
def test_update_type_wrapper(self):
@@ -910,7 +910,7 @@ def wrapper():
self.assertEqual(wrapper.__name__, 'wrapper')
self.assertNotEqual(wrapper.__qualname__, f.__qualname__)
self.assertEqual(wrapper.__doc__, None)
- self.assertFalse(hasattr(wrapper, 'attr'))
+ self.assertNotHasAttr(wrapper, 'attr')
def test_selective_update(self):
def f():
@@ -2666,15 +2666,15 @@ def _(self, arg):
a.t(0)
self.assertEqual(a.arg, "int")
aa = A()
- self.assertFalse(hasattr(aa, 'arg'))
+ self.assertNotHasAttr(aa, 'arg')
a.t('')
self.assertEqual(a.arg, "str")
aa = A()
- self.assertFalse(hasattr(aa, 'arg'))
+ self.assertNotHasAttr(aa, 'arg')
a.t(0.0)
self.assertEqual(a.arg, "base")
aa = A()
- self.assertFalse(hasattr(aa, 'arg'))
+ self.assertNotHasAttr(aa, 'arg')
def test_staticmethod_register(self):
class A:
@@ -3036,16 +3036,16 @@ def i(arg):
@i.register(42)
def _(arg):
return "I annotated with a non-type"
- self.assertTrue(str(exc.exception).startswith(msg_prefix + "42"))
- self.assertTrue(str(exc.exception).endswith(msg_suffix))
+ self.assertStartsWith(str(exc.exception), msg_prefix + "42")
+ self.assertEndsWith(str(exc.exception), msg_suffix)
with self.assertRaises(TypeError) as exc:
@i.register
def _(arg):
return "I forgot to annotate"
- self.assertTrue(str(exc.exception).startswith(msg_prefix +
+ self.assertStartsWith(str(exc.exception), msg_prefix +
"<function
TestSingleDispatch.test_invalid_registrations.<locals>._"
- ))
- self.assertTrue(str(exc.exception).endswith(msg_suffix))
+ )
+ self.assertEndsWith(str(exc.exception), msg_suffix)
with self.assertRaises(TypeError) as exc:
@i.register
@@ -3055,23 +3055,23 @@ def _(arg: typing.Iterable[str]):
# types from `typing`. Instead, annotate with regular types
# or ABCs.
return "I annotated with a generic collection"
- self.assertTrue(str(exc.exception).startswith(
+ self.assertStartsWith(str(exc.exception),
"Invalid annotation for 'arg'."
- ))
- self.assertTrue(str(exc.exception).endswith(
+ )
+ self.assertEndsWith(str(exc.exception),
'typing.Iterable[str] is not a class.'
- ))
+ )
with self.assertRaises(TypeError) as exc:
@i.register
def _(arg: typing.Union[int, typing.Iterable[str]]):
return "Invalid Union"
- self.assertTrue(str(exc.exception).startswith(
+ self.assertStartsWith(str(exc.exception),
"Invalid annotation for 'arg'."
- ))
- self.assertTrue(str(exc.exception).endswith(
+ )
+ self.assertEndsWith(str(exc.exception),
'typing.Union[int, typing.Iterable[str]] not all arguments are
classes.'
- ))
+ )
def test_invalid_positional_argument(self):
@functools.singledispatch
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]