gh-71339: Use new assertion methods in test_import and test_importlib (GH-129052)

This commit is contained in:
Serhiy Storchaka 2025-01-21 11:24:19 +02:00 committed by GitHub
parent da310d209a
commit f7cc7d296c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 51 additions and 54 deletions

View file

@ -43,14 +43,12 @@ class InheritanceTests:
def test_subclasses(self):
# Test that the expected subclasses inherit.
for subclass in self.subclasses:
self.assertTrue(issubclass(subclass, self.__test),
"{0} is not a subclass of {1}".format(subclass, self.__test))
self.assertIsSubclass(subclass, self.__test)
def test_superclasses(self):
# Test that the class inherits from the expected superclasses.
for superclass in self.superclasses:
self.assertTrue(issubclass(self.__test, superclass),
"{0} is not a superclass of {1}".format(superclass, self.__test))
self.assertIsSubclass(self.__test, superclass)
class MetaPathFinder(InheritanceTests):
@ -424,14 +422,14 @@ class InspectLoaderSourceToCodeTests:
# Since compile() can handle strings, so should source_to_code().
source = 'attr = 42'
module = self.source_to_module(source)
self.assertTrue(hasattr(module, 'attr'))
self.assertHasAttr(module, 'attr')
self.assertEqual(module.attr, 42)
def test_source_to_code_bytes(self):
# Since compile() can handle bytes, so should source_to_code().
source = b'attr = 42'
module = self.source_to_module(source)
self.assertTrue(hasattr(module, 'attr'))
self.assertHasAttr(module, 'attr')
self.assertEqual(module.attr, 42)
def test_source_to_code_path(self):
@ -765,7 +763,7 @@ class SourceOnlyLoaderTests(SourceLoaderTestHarness):
warnings.simplefilter('ignore', DeprecationWarning)
module = self.loader.load_module(self.name)
self.verify_module(module)
self.assertFalse(hasattr(module, '__path__'))
self.assertNotHasAttr(module, '__path__')
def test_get_source_encoding(self):
# Source is considered encoded in UTF-8 by default unless otherwise