cpython: 9623c83ba489 (original) (raw)

Mercurial > cpython

changeset 77825:9623c83ba489

Changed importlib tests to use assertIs, assertIsInstance, etc., instead of just assertTrue.

Eric V. Smith eric@trueblade.com
date Wed, 27 Jun 2012 15:26:26 -0400
parents abcd29c9a791
children f0e58e778215
files Lib/importlib/test/builtin/test_finder.py Lib/importlib/test/builtin/test_loader.py Lib/importlib/test/extension/test_finder.py Lib/importlib/test/extension/test_loader.py Lib/importlib/test/frozen/test_finder.py Lib/importlib/test/frozen/test_loader.py Lib/importlib/test/import_/test_caching.py Lib/importlib/test/import_/test_meta_path.py Lib/importlib/test/import_/test_packages.py Lib/importlib/test/import_/test_path.py Lib/importlib/test/source/test_abc_loader.py Lib/importlib/test/source/test_file_loader.py Lib/importlib/test/source/test_finder.py Lib/importlib/test/test_util.py
diffstat 14 files changed, 58 insertions(+), 58 deletions(-)[+] [-] Lib/importlib/test/builtin/test_finder.py 4 Lib/importlib/test/builtin/test_loader.py 10 Lib/importlib/test/extension/test_finder.py 2 Lib/importlib/test/extension/test_loader.py 8 Lib/importlib/test/frozen/test_finder.py 2 Lib/importlib/test/frozen/test_loader.py 6 Lib/importlib/test/import_/test_caching.py 3 Lib/importlib/test/import_/test_meta_path.py 4 Lib/importlib/test/import_/test_packages.py 22 Lib/importlib/test/import_/test_path.py 12 Lib/importlib/test/source/test_abc_loader.py 21 Lib/importlib/test/source/test_file_loader.py 12 Lib/importlib/test/source/test_finder.py 2 Lib/importlib/test/test_util.py 8

line wrap: on

line diff

--- a/Lib/importlib/test/builtin/test_finder.py +++ b/Lib/importlib/test/builtin/test_finder.py @@ -35,14 +35,14 @@ class FinderTests(abc.FinderTests): def test_failure(self): assert 'importlib' not in sys.builtin_module_names loader = machinery.BuiltinImporter.find_module('importlib')

def test_ignore_path(self): # The value for 'path' should always trigger a failed import. with util.uncache(builtin_util.NAME): loader = machinery.BuiltinImporter.find_module(builtin_util.NAME, ['pkg'])

--- a/Lib/importlib/test/builtin/test_loader.py +++ b/Lib/importlib/test/builtin/test_loader.py @@ -18,10 +18,10 @@ class LoaderTests(abc.LoaderTests): def verify(self, module): """Verify that the module matches against what it should have."""

load_module = staticmethod(lambda name: machinery.BuiltinImporter.load_module(name)) @@ -49,7 +49,7 @@ class LoaderTests(abc.LoaderTests): with util.uncache(builtin_util.NAME): module1 = self.load_module(builtin_util.NAME) module2 = self.load_module(builtin_util.NAME)

def test_unloadable(self): name = 'dssdsdfff' @@ -74,12 +74,12 @@ class InspectLoaderTests(unittest.TestCa def test_get_code(self): # There is no code object. result = machinery.BuiltinImporter.get_code(builtin_util.NAME)

def test_get_source(self): # There is no source. result = machinery.BuiltinImporter.get_source(builtin_util.NAME)

def test_is_package(self): # Cannot be a package.

--- a/Lib/importlib/test/extension/test_finder.py +++ b/Lib/importlib/test/extension/test_finder.py @@ -36,7 +36,7 @@ class FinderTests(abc.FinderTests): pass def test_failure(self):

# XXX Raise an exception if someone tries to use the 'path' argument?

--- a/Lib/importlib/test/extension/test_loader.py +++ b/Lib/importlib/test/extension/test_loader.py @@ -33,9 +33,9 @@ class LoaderTests(abc.LoaderTests): ('file', ext_util.FILEPATH), ('package', '')]: self.assertEqual(getattr(module, attr), value)

def test_package(self): # Extensions are not found in packages. @@ -49,7 +49,7 @@ class LoaderTests(abc.LoaderTests): with util.uncache(ext_util.NAME): module1 = self.load_module(ext_util.NAME) module2 = self.load_module(ext_util.NAME)

def test_state_after_failure(self): # No easy way to trigger a failure after a successful import.

--- a/Lib/importlib/test/frozen/test_finder.py +++ b/Lib/importlib/test/frozen/test_finder.py @@ -35,7 +35,7 @@ class FinderTests(abc.FinderTests): def test_failure(self): loader = self.find('')

def test_main():

--- a/Lib/importlib/test/frozen/test_loader.py +++ b/Lib/importlib/test/frozen/test_loader.py @@ -55,7 +55,7 @@ class LoaderTests(abc.LoaderTests): with util.uncache('hello'), captured_stdout() as stdout: module1 = machinery.FrozenImporter.load_module('hello') module2 = machinery.FrozenImporter.load_module('hello')

@@ -93,7 +93,7 @@ class InspectLoaderTests(unittest.TestCa def test_get_source(self): # Should always return None. result = machinery.FrozenImporter.get_source('hello')

def test_is_package(self): # Should be able to tell what is a package. @@ -101,7 +101,7 @@ class InspectLoaderTests(unittest.TestCa ('phello.spam', False)) for name, is_package in test_for: result = machinery.FrozenImporter.is_package(name)

def test_failure(self): # Raise ImportError for modules that are not frozen.

--- a/Lib/importlib/test/import_/test_caching.py +++ b/Lib/importlib/test/import_/test_caching.py @@ -65,7 +65,8 @@ class UseCache(unittest.TestCase): with util.import_state(meta_path=[importer]): module = import_util.import_('pkg.module') self.assertTrue(hasattr(module, 'module'))

# See test_using_cache_after_loader() for reasoning. @import_util.importlib_only

--- a/Lib/importlib/test/import_/test_meta_path.py +++ b/Lib/importlib/test/import_/test_meta_path.py @@ -82,7 +82,7 @@ class CallSignature(unittest.TestCase): self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 0) self.assertEqual(args[0], mod_name)

def test_with_path(self): # [path set] @@ -102,7 +102,7 @@ class CallSignature(unittest.TestCase): # Assuming all arguments are positional. self.assertTrue(not kwargs) self.assertEqual(args[0], mod_name)

--- a/Lib/importlib/test/import_/test_packages.py +++ b/Lib/importlib/test/import_/test_packages.py @@ -14,7 +14,7 @@ class ParentModuleTests(unittest.TestCas with util.mock_modules('pkg.init', 'pkg.module') as mock: with util.import_state(meta_path=[mock]): module = import_util.import_('pkg.module')

def test_bad_parent(self): with util.mock_modules('pkg.module') as mock: @@ -33,12 +33,12 @@ class ParentModuleTests(unittest.TestCas with util.import_state(meta_path=[mock]): with self.assertRaises(ZeroDivisionError): import_util.import_('pkg')

def test_raising_parent_after_relative_importing_child(self): def init(): @@ -52,12 +52,12 @@ class ParentModuleTests(unittest.TestCas # This raises ImportError on the "from . import module" # line, not sure why. import_util.import_('pkg')

def test_raising_parent_after_double_relative_importing_child(self): def init(): @@ -72,12 +72,12 @@ class ParentModuleTests(unittest.TestCas # This raises ImportError on the "from ..subpkg import module" # line, not sure why. import_util.import_('pkg.subpkg')

def test_module_not_package(self): # Try to import a submodule from a non-package should raise ImportError.

--- a/Lib/importlib/test/import_/test_path.py +++ b/Lib/importlib/test/import_/test_path.py @@ -20,7 +20,7 @@ class FinderTests(unittest.TestCase): # Test None returned upon not finding a suitable finder. module = '' with util.import_state():

def test_sys_path(self): # Test that sys.path is used when 'path' is None. @@ -31,7 +31,7 @@ class FinderTests(unittest.TestCase): with util.import_state(path_importer_cache={path: importer}, path=[path]): loader = machinery.PathFinder.find_module(module)

def test_path(self): # Test that 'path' is used when set. @@ -41,7 +41,7 @@ class FinderTests(unittest.TestCase): importer = util.mock_modules(module) with util.import_state(path_importer_cache={path: importer}): loader = machinery.PathFinder.find_module(module, [path])

def test_empty_list(self): # An empty list should not count as asking for sys.path. @@ -61,9 +61,9 @@ class FinderTests(unittest.TestCase): hook = import_util.mock_path_hook(path, importer=importer) with util.import_state(path_hooks=[hook]): loader = machinery.PathFinder.find_module(module, [path])

def test_empty_path_hooks(self): # Test that if sys.path_hooks is empty a warning is raised,

--- a/Lib/importlib/test/source/test_abc_loader.py +++ b/Lib/importlib/test/source/test_abc_loader.py @@ -221,7 +221,7 @@ class PyLoaderTests(testing_abc.LoaderTe mock = self.mocker({name: path}) with util.uncache(name): module = mock.load_module(name)

@@ -233,7 +233,7 @@ class PyLoaderTests(testing_abc.LoaderTe mock = self.mocker({name: path}) with util.uncache(name): module = mock.load_module(name)

@@ -259,8 +259,8 @@ class PyLoaderTests(testing_abc.LoaderTe with util.uncache(name): sys.modules[name] = module loaded_module = mock.load_module(name)

def test_state_after_failure(self): @@ -273,7 +273,7 @@ class PyLoaderTests(testing_abc.LoaderTe sys.modules[name] = module with self.assertRaises(ZeroDivisionError): mock.load_module(name)

@@ -284,7 +284,7 @@ class PyLoaderTests(testing_abc.LoaderTe with util.uncache(name): with self.assertRaises(ZeroDivisionError): mock.load_module(name)

@@ -414,8 +414,7 @@ class SkipWritingBytecodeTests(unittest. sys.dont_write_bytecode = dont_write_bytecode with util.uncache(name): mock.load_module(name)

def test_no_bytecode_written(self): self.run_test(True) @@ -440,7 +439,7 @@ class RegeneratedBytecodeTests(unittest. 'magic': bad_magic}}) with util.uncache(name): mock.load_module(name)

@@ -453,7 +452,7 @@ class RegeneratedBytecodeTests(unittest. {name: {'path': 'path/to/mod.bytecode', 'mtime': old_mtime}}) with util.uncache(name): mock.load_module(name)

@@ -621,7 +620,7 @@ class SourceOnlyLoaderTests(SourceLoader module = self.loader.load_module(self.name) self.verify_module(module) self.assertEqual(module.path, [os.path.dirname(self.path)])

def test_package_settings(self): # package needs to be set, while path is set on if the module

--- a/Lib/importlib/test/source/test_file_loader.py +++ b/Lib/importlib/test/source/test_file_loader.py @@ -64,7 +64,7 @@ class SimpleTest(unittest.TestCase): with source_util.create_modules('_temp') as mapping: loader = _bootstrap.SourceFileLoader('_temp', mapping['_temp']) module = loader.load_module('_temp')

@@ -75,7 +75,7 @@ class SimpleTest(unittest.TestCase): loader = _bootstrap.SourceFileLoader('_pkg', mapping['_pkg.init']) module = loader.load_module('_pkg')

@@ -88,7 +88,7 @@ class SimpleTest(unittest.TestCase): loader = _bootstrap.SourceFileLoader('_pkg.mod', mapping['_pkg.mod']) module = loader.load_module('_pkg.mod')

@@ -107,7 +107,7 @@ class SimpleTest(unittest.TestCase): with open(mapping['_temp'], 'w') as file: file.write("testing_var = 42\n") module = loader.load_module('_temp')

@@ -139,7 +139,7 @@ class SimpleTest(unittest.TestCase): loader = _bootstrap.SourceFileLoader('_temp', mapping['_temp']) with self.assertRaises(SyntaxError): loader.load_module('_temp')

def test_file_from_empty_string_dir(self): # Loading a module found from an empty string entry on sys.path should @@ -189,7 +189,7 @@ class BadBytecodeTest(unittest.TestCase) def import_(self, file, module_name): loader = self.loader(module_name, file) module = loader.load_module(module_name)

def manipulate_bytecode(self, name, mapping, manipulator, *, del_source=False):

--- a/Lib/importlib/test/source/test_finder.py +++ b/Lib/importlib/test/source/test_finder.py @@ -115,7 +115,7 @@ class FinderTests(abc.FinderTests): def test_failure(self): with source_util.create_modules('blah') as mapping: nothing = self.import_(mapping['.root'], 'sdfsadsadf')

def test_empty_string_for_dir(self): # The empty string from sys.path means to search in the cwd.

--- a/Lib/importlib/test/test_util.py +++ b/Lib/importlib/test/test_util.py @@ -29,8 +29,8 @@ class ModuleForLoaderTests(unittest.Test module_name = 'a.b.c' with test_util.uncache(module_name): module = self.return_module(module_name)

def test_reload(self): @@ -48,7 +48,7 @@ class ModuleForLoaderTests(unittest.Test name = 'a.b.c' with test_util.uncache(name): self.raise_exception(name)

def test_reload_failure(self): # Test that a failure on reload leaves the module in-place. @@ -77,7 +77,7 @@ class ModuleForLoaderTests(unittest.Test self.assertFalse(module) sys.modules[name] = module given = self.return_module(name)

def test_attributes_set(self): # name, loader, and package should be set (when