mirror of
https://github.com/python/cpython.git
synced 2025-09-08 01:41:19 +00:00
gh-71339: Add additional assertion methods for unittest (GH-128707)
Add the following methods: * assertHasAttr() and assertNotHasAttr() * assertIsSubclass() and assertNotIsSubclass() * assertStartsWith() and assertNotStartsWith() * assertEndsWith() and assertNotEndsWith() Also improve error messages for assertIsInstance() and assertNotIsInstance().
This commit is contained in:
parent
41f73501ec
commit
06cad77a5b
20 changed files with 555 additions and 100 deletions
|
@ -59,20 +59,6 @@ CANNOT_SUBCLASS_INSTANCE = 'Cannot subclass an instance of %s'
|
|||
|
||||
class BaseTestCase(TestCase):
|
||||
|
||||
def assertIsSubclass(self, cls, class_or_tuple, msg=None):
|
||||
if not issubclass(cls, class_or_tuple):
|
||||
message = '%r is not a subclass of %r' % (cls, class_or_tuple)
|
||||
if msg is not None:
|
||||
message += ' : %s' % msg
|
||||
raise self.failureException(message)
|
||||
|
||||
def assertNotIsSubclass(self, cls, class_or_tuple, msg=None):
|
||||
if issubclass(cls, class_or_tuple):
|
||||
message = '%r is a subclass of %r' % (cls, class_or_tuple)
|
||||
if msg is not None:
|
||||
message += ' : %s' % msg
|
||||
raise self.failureException(message)
|
||||
|
||||
def clear_caches(self):
|
||||
for f in typing._cleanups:
|
||||
f()
|
||||
|
@ -1252,10 +1238,6 @@ class UnpackTests(BaseTestCase):
|
|||
|
||||
class TypeVarTupleTests(BaseTestCase):
|
||||
|
||||
def assertEndsWith(self, string, tail):
|
||||
if not string.endswith(tail):
|
||||
self.fail(f"String {string!r} does not end with {tail!r}")
|
||||
|
||||
def test_name(self):
|
||||
Ts = TypeVarTuple('Ts')
|
||||
self.assertEqual(Ts.__name__, 'Ts')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue