mirror of
https://github.com/python/cpython.git
synced 2025-10-30 13:11:29 +00:00
Changed importlib tests to use assertIs, assertIsInstance, etc., instead of just assertTrue.
This commit is contained in:
parent
8d37ffa563
commit
faae3adbb9
14 changed files with 58 additions and 58 deletions
|
|
@ -35,14 +35,14 @@ def test_package_over_module(self):
|
||||||
def test_failure(self):
|
def test_failure(self):
|
||||||
assert 'importlib' not in sys.builtin_module_names
|
assert 'importlib' not in sys.builtin_module_names
|
||||||
loader = machinery.BuiltinImporter.find_module('importlib')
|
loader = machinery.BuiltinImporter.find_module('importlib')
|
||||||
self.assertTrue(loader is None)
|
self.assertIs(loader, None)
|
||||||
|
|
||||||
def test_ignore_path(self):
|
def test_ignore_path(self):
|
||||||
# The value for 'path' should always trigger a failed import.
|
# The value for 'path' should always trigger a failed import.
|
||||||
with util.uncache(builtin_util.NAME):
|
with util.uncache(builtin_util.NAME):
|
||||||
loader = machinery.BuiltinImporter.find_module(builtin_util.NAME,
|
loader = machinery.BuiltinImporter.find_module(builtin_util.NAME,
|
||||||
['pkg'])
|
['pkg'])
|
||||||
self.assertTrue(loader is None)
|
self.assertIs(loader, None)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,10 @@ class LoaderTests(abc.LoaderTests):
|
||||||
|
|
||||||
def verify(self, module):
|
def verify(self, module):
|
||||||
"""Verify that the module matches against what it should have."""
|
"""Verify that the module matches against what it should have."""
|
||||||
self.assertTrue(isinstance(module, types.ModuleType))
|
self.assertIsInstance(module, types.ModuleType)
|
||||||
for attr, value in self.verification.items():
|
for attr, value in self.verification.items():
|
||||||
self.assertEqual(getattr(module, attr), value)
|
self.assertEqual(getattr(module, attr), value)
|
||||||
self.assertTrue(module.__name__ in sys.modules)
|
self.assertIn(module.__name__, sys.modules)
|
||||||
|
|
||||||
load_module = staticmethod(lambda name:
|
load_module = staticmethod(lambda name:
|
||||||
machinery.BuiltinImporter.load_module(name))
|
machinery.BuiltinImporter.load_module(name))
|
||||||
|
|
@ -49,7 +49,7 @@ def test_module_reuse(self):
|
||||||
with util.uncache(builtin_util.NAME):
|
with util.uncache(builtin_util.NAME):
|
||||||
module1 = self.load_module(builtin_util.NAME)
|
module1 = self.load_module(builtin_util.NAME)
|
||||||
module2 = self.load_module(builtin_util.NAME)
|
module2 = self.load_module(builtin_util.NAME)
|
||||||
self.assertTrue(module1 is module2)
|
self.assertIs(module1, module2)
|
||||||
|
|
||||||
def test_unloadable(self):
|
def test_unloadable(self):
|
||||||
name = 'dssdsdfff'
|
name = 'dssdsdfff'
|
||||||
|
|
@ -74,12 +74,12 @@ class InspectLoaderTests(unittest.TestCase):
|
||||||
def test_get_code(self):
|
def test_get_code(self):
|
||||||
# There is no code object.
|
# There is no code object.
|
||||||
result = machinery.BuiltinImporter.get_code(builtin_util.NAME)
|
result = machinery.BuiltinImporter.get_code(builtin_util.NAME)
|
||||||
self.assertTrue(result is None)
|
self.assertIs(result, None)
|
||||||
|
|
||||||
def test_get_source(self):
|
def test_get_source(self):
|
||||||
# There is no source.
|
# There is no source.
|
||||||
result = machinery.BuiltinImporter.get_source(builtin_util.NAME)
|
result = machinery.BuiltinImporter.get_source(builtin_util.NAME)
|
||||||
self.assertTrue(result is None)
|
self.assertIs(result, None)
|
||||||
|
|
||||||
def test_is_package(self):
|
def test_is_package(self):
|
||||||
# Cannot be a package.
|
# Cannot be a package.
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ def test_package_over_module(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_failure(self):
|
def test_failure(self):
|
||||||
self.assertTrue(self.find_module('asdfjkl;') is None)
|
self.assertIs(self.find_module('asdfjkl;'), None)
|
||||||
|
|
||||||
# XXX Raise an exception if someone tries to use the 'path' argument?
|
# XXX Raise an exception if someone tries to use the 'path' argument?
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,9 @@ def test_module(self):
|
||||||
('__file__', ext_util.FILEPATH),
|
('__file__', ext_util.FILEPATH),
|
||||||
('__package__', '')]:
|
('__package__', '')]:
|
||||||
self.assertEqual(getattr(module, attr), value)
|
self.assertEqual(getattr(module, attr), value)
|
||||||
self.assertTrue(ext_util.NAME in sys.modules)
|
self.assertIn(ext_util.NAME, sys.modules)
|
||||||
self.assertTrue(isinstance(module.__loader__,
|
self.assertIsInstance(module.__loader__,
|
||||||
machinery.ExtensionFileLoader))
|
machinery.ExtensionFileLoader)
|
||||||
|
|
||||||
def test_package(self):
|
def test_package(self):
|
||||||
# Extensions are not found in packages.
|
# Extensions are not found in packages.
|
||||||
|
|
@ -49,7 +49,7 @@ def test_module_reuse(self):
|
||||||
with util.uncache(ext_util.NAME):
|
with util.uncache(ext_util.NAME):
|
||||||
module1 = self.load_module(ext_util.NAME)
|
module1 = self.load_module(ext_util.NAME)
|
||||||
module2 = self.load_module(ext_util.NAME)
|
module2 = self.load_module(ext_util.NAME)
|
||||||
self.assertTrue(module1 is module2)
|
self.assertIs(module1, module2)
|
||||||
|
|
||||||
def test_state_after_failure(self):
|
def test_state_after_failure(self):
|
||||||
# No easy way to trigger a failure after a successful import.
|
# No easy way to trigger a failure after a successful import.
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ def test_package_over_module(self):
|
||||||
|
|
||||||
def test_failure(self):
|
def test_failure(self):
|
||||||
loader = self.find('<not real>')
|
loader = self.find('<not real>')
|
||||||
self.assertTrue(loader is None)
|
self.assertIs(loader, None)
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ def test_module_reuse(self):
|
||||||
with util.uncache('__hello__'), captured_stdout() as stdout:
|
with util.uncache('__hello__'), captured_stdout() as stdout:
|
||||||
module1 = machinery.FrozenImporter.load_module('__hello__')
|
module1 = machinery.FrozenImporter.load_module('__hello__')
|
||||||
module2 = machinery.FrozenImporter.load_module('__hello__')
|
module2 = machinery.FrozenImporter.load_module('__hello__')
|
||||||
self.assertTrue(module1 is module2)
|
self.assertIs(module1, module2)
|
||||||
self.assertEqual(stdout.getvalue(),
|
self.assertEqual(stdout.getvalue(),
|
||||||
'Hello world!\nHello world!\n')
|
'Hello world!\nHello world!\n')
|
||||||
|
|
||||||
|
|
@ -93,7 +93,7 @@ def test_get_code(self):
|
||||||
def test_get_source(self):
|
def test_get_source(self):
|
||||||
# Should always return None.
|
# Should always return None.
|
||||||
result = machinery.FrozenImporter.get_source('__hello__')
|
result = machinery.FrozenImporter.get_source('__hello__')
|
||||||
self.assertTrue(result is None)
|
self.assertIs(result, None)
|
||||||
|
|
||||||
def test_is_package(self):
|
def test_is_package(self):
|
||||||
# Should be able to tell what is a package.
|
# Should be able to tell what is a package.
|
||||||
|
|
@ -101,7 +101,7 @@ def test_is_package(self):
|
||||||
('__phello__.spam', False))
|
('__phello__.spam', False))
|
||||||
for name, is_package in test_for:
|
for name, is_package in test_for:
|
||||||
result = machinery.FrozenImporter.is_package(name)
|
result = machinery.FrozenImporter.is_package(name)
|
||||||
self.assertTrue(bool(result) == is_package)
|
self.assertEqual(bool(result), is_package)
|
||||||
|
|
||||||
def test_failure(self):
|
def test_failure(self):
|
||||||
# Raise ImportError for modules that are not frozen.
|
# Raise ImportError for modules that are not frozen.
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,8 @@ def test_using_cache_for_assigning_to_attribute(self):
|
||||||
with util.import_state(meta_path=[importer]):
|
with util.import_state(meta_path=[importer]):
|
||||||
module = import_util.import_('pkg.module')
|
module = import_util.import_('pkg.module')
|
||||||
self.assertTrue(hasattr(module, 'module'))
|
self.assertTrue(hasattr(module, 'module'))
|
||||||
self.assertTrue(id(module.module), id(sys.modules['pkg.module']))
|
self.assertEqual(id(module.module),
|
||||||
|
id(sys.modules['pkg.module']))
|
||||||
|
|
||||||
# See test_using_cache_after_loader() for reasoning.
|
# See test_using_cache_after_loader() for reasoning.
|
||||||
@import_util.importlib_only
|
@import_util.importlib_only
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ def test_no_path(self):
|
||||||
self.assertEqual(len(args), 2)
|
self.assertEqual(len(args), 2)
|
||||||
self.assertEqual(len(kwargs), 0)
|
self.assertEqual(len(kwargs), 0)
|
||||||
self.assertEqual(args[0], mod_name)
|
self.assertEqual(args[0], mod_name)
|
||||||
self.assertTrue(args[1] is None)
|
self.assertIs(args[1], None)
|
||||||
|
|
||||||
def test_with_path(self):
|
def test_with_path(self):
|
||||||
# [path set]
|
# [path set]
|
||||||
|
|
@ -102,7 +102,7 @@ def test_with_path(self):
|
||||||
# Assuming all arguments are positional.
|
# Assuming all arguments are positional.
|
||||||
self.assertTrue(not kwargs)
|
self.assertTrue(not kwargs)
|
||||||
self.assertEqual(args[0], mod_name)
|
self.assertEqual(args[0], mod_name)
|
||||||
self.assertTrue(args[1] is path)
|
self.assertIs(args[1], path)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ def test_import_parent(self):
|
||||||
with util.mock_modules('pkg.__init__', 'pkg.module') as mock:
|
with util.mock_modules('pkg.__init__', 'pkg.module') as mock:
|
||||||
with util.import_state(meta_path=[mock]):
|
with util.import_state(meta_path=[mock]):
|
||||||
module = import_util.import_('pkg.module')
|
module = import_util.import_('pkg.module')
|
||||||
self.assertTrue('pkg' in sys.modules)
|
self.assertIn('pkg', sys.modules)
|
||||||
|
|
||||||
def test_bad_parent(self):
|
def test_bad_parent(self):
|
||||||
with util.mock_modules('pkg.module') as mock:
|
with util.mock_modules('pkg.module') as mock:
|
||||||
|
|
@ -33,12 +33,12 @@ def __init__():
|
||||||
with util.import_state(meta_path=[mock]):
|
with util.import_state(meta_path=[mock]):
|
||||||
with self.assertRaises(ZeroDivisionError):
|
with self.assertRaises(ZeroDivisionError):
|
||||||
import_util.import_('pkg')
|
import_util.import_('pkg')
|
||||||
self.assertFalse('pkg' in sys.modules)
|
self.assertNotIn('pkg', sys.modules)
|
||||||
self.assertTrue('pkg.module' in sys.modules)
|
self.assertIn('pkg.module', sys.modules)
|
||||||
with self.assertRaises(ZeroDivisionError):
|
with self.assertRaises(ZeroDivisionError):
|
||||||
import_util.import_('pkg.module')
|
import_util.import_('pkg.module')
|
||||||
self.assertFalse('pkg' in sys.modules)
|
self.assertNotIn('pkg', sys.modules)
|
||||||
self.assertTrue('pkg.module' in sys.modules)
|
self.assertIn('pkg.module', sys.modules)
|
||||||
|
|
||||||
def test_raising_parent_after_relative_importing_child(self):
|
def test_raising_parent_after_relative_importing_child(self):
|
||||||
def __init__():
|
def __init__():
|
||||||
|
|
@ -52,12 +52,12 @@ def __init__():
|
||||||
# This raises ImportError on the "from . import module"
|
# This raises ImportError on the "from . import module"
|
||||||
# line, not sure why.
|
# line, not sure why.
|
||||||
import_util.import_('pkg')
|
import_util.import_('pkg')
|
||||||
self.assertFalse('pkg' in sys.modules)
|
self.assertNotIn('pkg', sys.modules)
|
||||||
with self.assertRaises((ZeroDivisionError, ImportError)):
|
with self.assertRaises((ZeroDivisionError, ImportError)):
|
||||||
import_util.import_('pkg.module')
|
import_util.import_('pkg.module')
|
||||||
self.assertFalse('pkg' in sys.modules)
|
self.assertNotIn('pkg', sys.modules)
|
||||||
# XXX False
|
# XXX False
|
||||||
#self.assertTrue('pkg.module' in sys.modules)
|
#self.assertIn('pkg.module', sys.modules)
|
||||||
|
|
||||||
def test_raising_parent_after_double_relative_importing_child(self):
|
def test_raising_parent_after_double_relative_importing_child(self):
|
||||||
def __init__():
|
def __init__():
|
||||||
|
|
@ -72,12 +72,12 @@ def __init__():
|
||||||
# This raises ImportError on the "from ..subpkg import module"
|
# This raises ImportError on the "from ..subpkg import module"
|
||||||
# line, not sure why.
|
# line, not sure why.
|
||||||
import_util.import_('pkg.subpkg')
|
import_util.import_('pkg.subpkg')
|
||||||
self.assertFalse('pkg.subpkg' in sys.modules)
|
self.assertNotIn('pkg.subpkg', sys.modules)
|
||||||
with self.assertRaises((ZeroDivisionError, ImportError)):
|
with self.assertRaises((ZeroDivisionError, ImportError)):
|
||||||
import_util.import_('pkg.subpkg.module')
|
import_util.import_('pkg.subpkg.module')
|
||||||
self.assertFalse('pkg.subpkg' in sys.modules)
|
self.assertNotIn('pkg.subpkg', sys.modules)
|
||||||
# XXX False
|
# XXX False
|
||||||
#self.assertTrue('pkg.subpkg.module' in sys.modules)
|
#self.assertIn('pkg.subpkg.module', sys.modules)
|
||||||
|
|
||||||
def test_module_not_package(self):
|
def test_module_not_package(self):
|
||||||
# Try to import a submodule from a non-package should raise ImportError.
|
# Try to import a submodule from a non-package should raise ImportError.
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ def test_failure(self):
|
||||||
# Test None returned upon not finding a suitable finder.
|
# Test None returned upon not finding a suitable finder.
|
||||||
module = '<test module>'
|
module = '<test module>'
|
||||||
with util.import_state():
|
with util.import_state():
|
||||||
self.assertTrue(machinery.PathFinder.find_module(module) is None)
|
self.assertIs(machinery.PathFinder.find_module(module), None)
|
||||||
|
|
||||||
def test_sys_path(self):
|
def test_sys_path(self):
|
||||||
# Test that sys.path is used when 'path' is None.
|
# Test that sys.path is used when 'path' is None.
|
||||||
|
|
@ -31,7 +31,7 @@ def test_sys_path(self):
|
||||||
with util.import_state(path_importer_cache={path: importer},
|
with util.import_state(path_importer_cache={path: importer},
|
||||||
path=[path]):
|
path=[path]):
|
||||||
loader = machinery.PathFinder.find_module(module)
|
loader = machinery.PathFinder.find_module(module)
|
||||||
self.assertTrue(loader is importer)
|
self.assertIs(loader, importer)
|
||||||
|
|
||||||
def test_path(self):
|
def test_path(self):
|
||||||
# Test that 'path' is used when set.
|
# Test that 'path' is used when set.
|
||||||
|
|
@ -41,7 +41,7 @@ def test_path(self):
|
||||||
importer = util.mock_modules(module)
|
importer = util.mock_modules(module)
|
||||||
with util.import_state(path_importer_cache={path: importer}):
|
with util.import_state(path_importer_cache={path: importer}):
|
||||||
loader = machinery.PathFinder.find_module(module, [path])
|
loader = machinery.PathFinder.find_module(module, [path])
|
||||||
self.assertTrue(loader is importer)
|
self.assertIs(loader, importer)
|
||||||
|
|
||||||
def test_empty_list(self):
|
def test_empty_list(self):
|
||||||
# An empty list should not count as asking for sys.path.
|
# An empty list should not count as asking for sys.path.
|
||||||
|
|
@ -61,9 +61,9 @@ def test_path_hooks(self):
|
||||||
hook = import_util.mock_path_hook(path, importer=importer)
|
hook = import_util.mock_path_hook(path, importer=importer)
|
||||||
with util.import_state(path_hooks=[hook]):
|
with util.import_state(path_hooks=[hook]):
|
||||||
loader = machinery.PathFinder.find_module(module, [path])
|
loader = machinery.PathFinder.find_module(module, [path])
|
||||||
self.assertTrue(loader is importer)
|
self.assertIs(loader, importer)
|
||||||
self.assertTrue(path in sys.path_importer_cache)
|
self.assertIn(path, sys.path_importer_cache)
|
||||||
self.assertTrue(sys.path_importer_cache[path] is importer)
|
self.assertIs(sys.path_importer_cache[path], importer)
|
||||||
|
|
||||||
def test_empty_path_hooks(self):
|
def test_empty_path_hooks(self):
|
||||||
# Test that if sys.path_hooks is empty a warning is raised,
|
# Test that if sys.path_hooks is empty a warning is raised,
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ def test_module(self):
|
||||||
mock = self.mocker({name: path})
|
mock = self.mocker({name: path})
|
||||||
with util.uncache(name):
|
with util.uncache(name):
|
||||||
module = mock.load_module(name)
|
module = mock.load_module(name)
|
||||||
self.assertTrue(name in sys.modules)
|
self.assertIn(name, sys.modules)
|
||||||
self.eq_attrs(module, __name__=name, __file__=path, __package__='',
|
self.eq_attrs(module, __name__=name, __file__=path, __package__='',
|
||||||
__loader__=mock)
|
__loader__=mock)
|
||||||
self.assertTrue(not hasattr(module, '__path__'))
|
self.assertTrue(not hasattr(module, '__path__'))
|
||||||
|
|
@ -233,7 +233,7 @@ def test_package(self):
|
||||||
mock = self.mocker({name: path})
|
mock = self.mocker({name: path})
|
||||||
with util.uncache(name):
|
with util.uncache(name):
|
||||||
module = mock.load_module(name)
|
module = mock.load_module(name)
|
||||||
self.assertTrue(name in sys.modules)
|
self.assertIn(name, sys.modules)
|
||||||
self.eq_attrs(module, __name__=name, __file__=path,
|
self.eq_attrs(module, __name__=name, __file__=path,
|
||||||
__path__=[os.path.dirname(path)], __package__=name,
|
__path__=[os.path.dirname(path)], __package__=name,
|
||||||
__loader__=mock)
|
__loader__=mock)
|
||||||
|
|
@ -259,8 +259,8 @@ def test_module_reuse(self):
|
||||||
with util.uncache(name):
|
with util.uncache(name):
|
||||||
sys.modules[name] = module
|
sys.modules[name] = module
|
||||||
loaded_module = mock.load_module(name)
|
loaded_module = mock.load_module(name)
|
||||||
self.assertTrue(loaded_module is module)
|
self.assertIs(loaded_module, module)
|
||||||
self.assertTrue(sys.modules[name] is module)
|
self.assertIs(sys.modules[name], module)
|
||||||
return mock, name
|
return mock, name
|
||||||
|
|
||||||
def test_state_after_failure(self):
|
def test_state_after_failure(self):
|
||||||
|
|
@ -273,7 +273,7 @@ def test_state_after_failure(self):
|
||||||
sys.modules[name] = module
|
sys.modules[name] = module
|
||||||
with self.assertRaises(ZeroDivisionError):
|
with self.assertRaises(ZeroDivisionError):
|
||||||
mock.load_module(name)
|
mock.load_module(name)
|
||||||
self.assertTrue(sys.modules[name] is module)
|
self.assertIs(sys.modules[name], module)
|
||||||
self.assertTrue(hasattr(module, 'blah'))
|
self.assertTrue(hasattr(module, 'blah'))
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
|
@ -284,7 +284,7 @@ def test_unloadable(self):
|
||||||
with util.uncache(name):
|
with util.uncache(name):
|
||||||
with self.assertRaises(ZeroDivisionError):
|
with self.assertRaises(ZeroDivisionError):
|
||||||
mock.load_module(name)
|
mock.load_module(name)
|
||||||
self.assertTrue(name not in sys.modules)
|
self.assertNotIn(name, sys.modules)
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -414,8 +414,7 @@ def run_test(self, dont_write_bytecode):
|
||||||
sys.dont_write_bytecode = dont_write_bytecode
|
sys.dont_write_bytecode = dont_write_bytecode
|
||||||
with util.uncache(name):
|
with util.uncache(name):
|
||||||
mock.load_module(name)
|
mock.load_module(name)
|
||||||
self.assertTrue((name in mock.module_bytecode) is not
|
self.assertIsNot(name in mock.module_bytecode, dont_write_bytecode)
|
||||||
dont_write_bytecode)
|
|
||||||
|
|
||||||
def test_no_bytecode_written(self):
|
def test_no_bytecode_written(self):
|
||||||
self.run_test(True)
|
self.run_test(True)
|
||||||
|
|
@ -440,7 +439,7 @@ def test_different_magic(self):
|
||||||
'magic': bad_magic}})
|
'magic': bad_magic}})
|
||||||
with util.uncache(name):
|
with util.uncache(name):
|
||||||
mock.load_module(name)
|
mock.load_module(name)
|
||||||
self.assertTrue(name in mock.module_bytecode)
|
self.assertIn(name, mock.module_bytecode)
|
||||||
magic = mock.module_bytecode[name][:4]
|
magic = mock.module_bytecode[name][:4]
|
||||||
self.assertEqual(magic, imp.get_magic())
|
self.assertEqual(magic, imp.get_magic())
|
||||||
|
|
||||||
|
|
@ -453,7 +452,7 @@ def test_old_mtime(self):
|
||||||
{name: {'path': 'path/to/mod.bytecode', 'mtime': old_mtime}})
|
{name: {'path': 'path/to/mod.bytecode', 'mtime': old_mtime}})
|
||||||
with util.uncache(name):
|
with util.uncache(name):
|
||||||
mock.load_module(name)
|
mock.load_module(name)
|
||||||
self.assertTrue(name in mock.module_bytecode)
|
self.assertIn(name, mock.module_bytecode)
|
||||||
mtime = importlib._r_long(mock.module_bytecode[name][4:8])
|
mtime = importlib._r_long(mock.module_bytecode[name][4:8])
|
||||||
self.assertEqual(mtime, PyPycLoaderMock.default_mtime)
|
self.assertEqual(mtime, PyPycLoaderMock.default_mtime)
|
||||||
|
|
||||||
|
|
@ -621,7 +620,7 @@ def test_load_module(self):
|
||||||
module = self.loader.load_module(self.name)
|
module = self.loader.load_module(self.name)
|
||||||
self.verify_module(module)
|
self.verify_module(module)
|
||||||
self.assertEqual(module.__path__, [os.path.dirname(self.path)])
|
self.assertEqual(module.__path__, [os.path.dirname(self.path)])
|
||||||
self.assertTrue(self.name in sys.modules)
|
self.assertIn(self.name, sys.modules)
|
||||||
|
|
||||||
def test_package_settings(self):
|
def test_package_settings(self):
|
||||||
# __package__ needs to be set, while __path__ is set on if the module
|
# __package__ needs to be set, while __path__ is set on if the module
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ def test_module(self):
|
||||||
with source_util.create_modules('_temp') as mapping:
|
with source_util.create_modules('_temp') as mapping:
|
||||||
loader = _bootstrap.SourceFileLoader('_temp', mapping['_temp'])
|
loader = _bootstrap.SourceFileLoader('_temp', mapping['_temp'])
|
||||||
module = loader.load_module('_temp')
|
module = loader.load_module('_temp')
|
||||||
self.assertTrue('_temp' in sys.modules)
|
self.assertIn('_temp', sys.modules)
|
||||||
check = {'__name__': '_temp', '__file__': mapping['_temp'],
|
check = {'__name__': '_temp', '__file__': mapping['_temp'],
|
||||||
'__package__': ''}
|
'__package__': ''}
|
||||||
for attr, value in check.items():
|
for attr, value in check.items():
|
||||||
|
|
@ -75,7 +75,7 @@ def test_package(self):
|
||||||
loader = _bootstrap.SourceFileLoader('_pkg',
|
loader = _bootstrap.SourceFileLoader('_pkg',
|
||||||
mapping['_pkg.__init__'])
|
mapping['_pkg.__init__'])
|
||||||
module = loader.load_module('_pkg')
|
module = loader.load_module('_pkg')
|
||||||
self.assertTrue('_pkg' in sys.modules)
|
self.assertIn('_pkg', sys.modules)
|
||||||
check = {'__name__': '_pkg', '__file__': mapping['_pkg.__init__'],
|
check = {'__name__': '_pkg', '__file__': mapping['_pkg.__init__'],
|
||||||
'__path__': [os.path.dirname(mapping['_pkg.__init__'])],
|
'__path__': [os.path.dirname(mapping['_pkg.__init__'])],
|
||||||
'__package__': '_pkg'}
|
'__package__': '_pkg'}
|
||||||
|
|
@ -88,7 +88,7 @@ def test_lacking_parent(self):
|
||||||
loader = _bootstrap.SourceFileLoader('_pkg.mod',
|
loader = _bootstrap.SourceFileLoader('_pkg.mod',
|
||||||
mapping['_pkg.mod'])
|
mapping['_pkg.mod'])
|
||||||
module = loader.load_module('_pkg.mod')
|
module = loader.load_module('_pkg.mod')
|
||||||
self.assertTrue('_pkg.mod' in sys.modules)
|
self.assertIn('_pkg.mod', sys.modules)
|
||||||
check = {'__name__': '_pkg.mod', '__file__': mapping['_pkg.mod'],
|
check = {'__name__': '_pkg.mod', '__file__': mapping['_pkg.mod'],
|
||||||
'__package__': '_pkg'}
|
'__package__': '_pkg'}
|
||||||
for attr, value in check.items():
|
for attr, value in check.items():
|
||||||
|
|
@ -107,7 +107,7 @@ def test_module_reuse(self):
|
||||||
with open(mapping['_temp'], 'w') as file:
|
with open(mapping['_temp'], 'w') as file:
|
||||||
file.write("testing_var = 42\n")
|
file.write("testing_var = 42\n")
|
||||||
module = loader.load_module('_temp')
|
module = loader.load_module('_temp')
|
||||||
self.assertTrue('testing_var' in module.__dict__,
|
self.assertIn('testing_var', module.__dict__,
|
||||||
"'testing_var' not in "
|
"'testing_var' not in "
|
||||||
"{0}".format(list(module.__dict__.keys())))
|
"{0}".format(list(module.__dict__.keys())))
|
||||||
self.assertEqual(module, sys.modules['_temp'])
|
self.assertEqual(module, sys.modules['_temp'])
|
||||||
|
|
@ -139,7 +139,7 @@ def test_bad_syntax(self):
|
||||||
loader = _bootstrap.SourceFileLoader('_temp', mapping['_temp'])
|
loader = _bootstrap.SourceFileLoader('_temp', mapping['_temp'])
|
||||||
with self.assertRaises(SyntaxError):
|
with self.assertRaises(SyntaxError):
|
||||||
loader.load_module('_temp')
|
loader.load_module('_temp')
|
||||||
self.assertTrue('_temp' not in sys.modules)
|
self.assertNotIn('_temp', sys.modules)
|
||||||
|
|
||||||
def test_file_from_empty_string_dir(self):
|
def test_file_from_empty_string_dir(self):
|
||||||
# Loading a module found from an empty string entry on sys.path should
|
# 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):
|
def import_(self, file, module_name):
|
||||||
loader = self.loader(module_name, file)
|
loader = self.loader(module_name, file)
|
||||||
module = loader.load_module(module_name)
|
module = loader.load_module(module_name)
|
||||||
self.assertTrue(module_name in sys.modules)
|
self.assertIn(module_name, sys.modules)
|
||||||
|
|
||||||
def manipulate_bytecode(self, name, mapping, manipulator, *,
|
def manipulate_bytecode(self, name, mapping, manipulator, *,
|
||||||
del_source=False):
|
del_source=False):
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ def test_package_over_module(self):
|
||||||
def test_failure(self):
|
def test_failure(self):
|
||||||
with source_util.create_modules('blah') as mapping:
|
with source_util.create_modules('blah') as mapping:
|
||||||
nothing = self.import_(mapping['.root'], 'sdfsadsadf')
|
nothing = self.import_(mapping['.root'], 'sdfsadsadf')
|
||||||
self.assertTrue(nothing is None)
|
self.assertIs(nothing, None)
|
||||||
|
|
||||||
def test_empty_string_for_dir(self):
|
def test_empty_string_for_dir(self):
|
||||||
# The empty string from sys.path means to search in the cwd.
|
# The empty string from sys.path means to search in the cwd.
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ def test_new_module(self):
|
||||||
module_name = 'a.b.c'
|
module_name = 'a.b.c'
|
||||||
with test_util.uncache(module_name):
|
with test_util.uncache(module_name):
|
||||||
module = self.return_module(module_name)
|
module = self.return_module(module_name)
|
||||||
self.assertTrue(module_name in sys.modules)
|
self.assertIn(module_name, sys.modules)
|
||||||
self.assertTrue(isinstance(module, types.ModuleType))
|
self.assertIsInstance(module, types.ModuleType)
|
||||||
self.assertEqual(module.__name__, module_name)
|
self.assertEqual(module.__name__, module_name)
|
||||||
|
|
||||||
def test_reload(self):
|
def test_reload(self):
|
||||||
|
|
@ -48,7 +48,7 @@ def test_new_module_failure(self):
|
||||||
name = 'a.b.c'
|
name = 'a.b.c'
|
||||||
with test_util.uncache(name):
|
with test_util.uncache(name):
|
||||||
self.raise_exception(name)
|
self.raise_exception(name)
|
||||||
self.assertTrue(name not in sys.modules)
|
self.assertNotIn(name, sys.modules)
|
||||||
|
|
||||||
def test_reload_failure(self):
|
def test_reload_failure(self):
|
||||||
# Test that a failure on reload leaves the module in-place.
|
# Test that a failure on reload leaves the module in-place.
|
||||||
|
|
@ -77,7 +77,7 @@ def __bool__(self): return False
|
||||||
self.assertFalse(module)
|
self.assertFalse(module)
|
||||||
sys.modules[name] = module
|
sys.modules[name] = module
|
||||||
given = self.return_module(name)
|
given = self.return_module(name)
|
||||||
self.assertTrue(given is module)
|
self.assertIs(given, module)
|
||||||
|
|
||||||
def test_attributes_set(self):
|
def test_attributes_set(self):
|
||||||
# __name__, __loader__, and __package__ should be set (when
|
# __name__, __loader__, and __package__ should be set (when
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue