Skip to content

Commit 89c401f

Browse files
gh-71339: Use new assertion methods in test_functools (GH-128829)
1 parent 887f2bc commit 89c401f

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

Diff for: Lib/test/test_functools.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,11 @@ def test_bound_method_introspection(self):
645645

646646
def test_unbound_method_retrieval(self):
647647
obj = self.A
648-
self.assertFalse(hasattr(obj.both, "__self__"))
649-
self.assertFalse(hasattr(obj.nested, "__self__"))
650-
self.assertFalse(hasattr(obj.over_partial, "__self__"))
651-
self.assertFalse(hasattr(obj.static, "__self__"))
652-
self.assertFalse(hasattr(self.a.static, "__self__"))
648+
self.assertNotHasAttr(obj.both, "__self__")
649+
self.assertNotHasAttr(obj.nested, "__self__")
650+
self.assertNotHasAttr(obj.over_partial, "__self__")
651+
self.assertNotHasAttr(obj.static, "__self__")
652+
self.assertNotHasAttr(self.a.static, "__self__")
653653

654654
def test_descriptors(self):
655655
for obj in [self.A, self.a]:
@@ -791,7 +791,7 @@ def wrapper():
791791
self.assertNotEqual(wrapper.__qualname__, f.__qualname__)
792792
self.assertEqual(wrapper.__doc__, None)
793793
self.assertEqual(wrapper.__annotations__, {})
794-
self.assertFalse(hasattr(wrapper, 'attr'))
794+
self.assertNotHasAttr(wrapper, 'attr')
795795

796796
def test_selective_update(self):
797797
def f():
@@ -840,7 +840,7 @@ def wrapper():
840840
pass
841841
functools.update_wrapper(wrapper, max)
842842
self.assertEqual(wrapper.__name__, 'max')
843-
self.assertTrue(wrapper.__doc__.startswith('max('))
843+
self.assertStartsWith(wrapper.__doc__, 'max(')
844844
self.assertEqual(wrapper.__annotations__, {})
845845

846846
def test_update_type_wrapper(self):
@@ -910,7 +910,7 @@ def wrapper():
910910
self.assertEqual(wrapper.__name__, 'wrapper')
911911
self.assertNotEqual(wrapper.__qualname__, f.__qualname__)
912912
self.assertEqual(wrapper.__doc__, None)
913-
self.assertFalse(hasattr(wrapper, 'attr'))
913+
self.assertNotHasAttr(wrapper, 'attr')
914914

915915
def test_selective_update(self):
916916
def f():
@@ -2666,15 +2666,15 @@ def _(self, arg):
26662666
a.t(0)
26672667
self.assertEqual(a.arg, "int")
26682668
aa = A()
2669-
self.assertFalse(hasattr(aa, 'arg'))
2669+
self.assertNotHasAttr(aa, 'arg')
26702670
a.t('')
26712671
self.assertEqual(a.arg, "str")
26722672
aa = A()
2673-
self.assertFalse(hasattr(aa, 'arg'))
2673+
self.assertNotHasAttr(aa, 'arg')
26742674
a.t(0.0)
26752675
self.assertEqual(a.arg, "base")
26762676
aa = A()
2677-
self.assertFalse(hasattr(aa, 'arg'))
2677+
self.assertNotHasAttr(aa, 'arg')
26782678

26792679
def test_staticmethod_register(self):
26802680
class A:
@@ -3036,16 +3036,16 @@ def i(arg):
30363036
@i.register(42)
30373037
def _(arg):
30383038
return "I annotated with a non-type"
3039-
self.assertTrue(str(exc.exception).startswith(msg_prefix + "42"))
3040-
self.assertTrue(str(exc.exception).endswith(msg_suffix))
3039+
self.assertStartsWith(str(exc.exception), msg_prefix + "42")
3040+
self.assertEndsWith(str(exc.exception), msg_suffix)
30413041
with self.assertRaises(TypeError) as exc:
30423042
@i.register
30433043
def _(arg):
30443044
return "I forgot to annotate"
3045-
self.assertTrue(str(exc.exception).startswith(msg_prefix +
3045+
self.assertStartsWith(str(exc.exception), msg_prefix +
30463046
"<function TestSingleDispatch.test_invalid_registrations.<locals>._"
3047-
))
3048-
self.assertTrue(str(exc.exception).endswith(msg_suffix))
3047+
)
3048+
self.assertEndsWith(str(exc.exception), msg_suffix)
30493049

30503050
with self.assertRaises(TypeError) as exc:
30513051
@i.register
@@ -3055,23 +3055,23 @@ def _(arg: typing.Iterable[str]):
30553055
# types from `typing`. Instead, annotate with regular types
30563056
# or ABCs.
30573057
return "I annotated with a generic collection"
3058-
self.assertTrue(str(exc.exception).startswith(
3058+
self.assertStartsWith(str(exc.exception),
30593059
"Invalid annotation for 'arg'."
3060-
))
3061-
self.assertTrue(str(exc.exception).endswith(
3060+
)
3061+
self.assertEndsWith(str(exc.exception),
30623062
'typing.Iterable[str] is not a class.'
3063-
))
3063+
)
30643064

30653065
with self.assertRaises(TypeError) as exc:
30663066
@i.register
30673067
def _(arg: typing.Union[int, typing.Iterable[str]]):
30683068
return "Invalid Union"
3069-
self.assertTrue(str(exc.exception).startswith(
3069+
self.assertStartsWith(str(exc.exception),
30703070
"Invalid annotation for 'arg'."
3071-
))
3072-
self.assertTrue(str(exc.exception).endswith(
3071+
)
3072+
self.assertEndsWith(str(exc.exception),
30733073
'typing.Union[int, typing.Iterable[str]] not all arguments are classes.'
3074-
))
3074+
)
30753075

30763076
def test_invalid_positional_argument(self):
30773077
@functools.singledispatch

0 commit comments

Comments
 (0)