summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorEric V. Smith <eric@trueblade.com>2012-06-27 19:26:26 (GMT)
committerEric V. Smith <eric@trueblade.com>2012-06-27 19:26:26 (GMT)
commitfaae3adbb98521d039c574fd3ed417f54a72374d (patch)
treec5d7689408588d896a54dc7dfcf13172a93a1cb4 /Lib/importlib
parent8d37ffa563cf552dd34990bfefd935eef8adfd11 (diff)
downloadcpython-faae3adbb98521d039c574fd3ed417f54a72374d.zip
cpython-faae3adbb98521d039c574fd3ed417f54a72374d.tar.gz
cpython-faae3adbb98521d039c574fd3ed417f54a72374d.tar.bz2
Changed importlib tests to use assertIs, assertIsInstance, etc., instead of just assertTrue.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/test/builtin/test_finder.py4
-rw-r--r--Lib/importlib/test/builtin/test_loader.py10
-rw-r--r--Lib/importlib/test/extension/test_finder.py2
-rw-r--r--Lib/importlib/test/extension/test_loader.py8
-rw-r--r--Lib/importlib/test/frozen/test_finder.py2
-rw-r--r--Lib/importlib/test/frozen/test_loader.py6
-rw-r--r--Lib/importlib/test/import_/test_caching.py3
-rw-r--r--Lib/importlib/test/import_/test_meta_path.py4
-rw-r--r--Lib/importlib/test/import_/test_packages.py22
-rw-r--r--Lib/importlib/test/import_/test_path.py12
-rw-r--r--Lib/importlib/test/source/test_abc_loader.py21
-rw-r--r--Lib/importlib/test/source/test_file_loader.py12
-rw-r--r--Lib/importlib/test/source/test_finder.py2
-rw-r--r--Lib/importlib/test/test_util.py8
14 files changed, 58 insertions, 58 deletions
diff --git a/Lib/importlib/test/builtin/test_finder.py b/Lib/importlib/test/builtin/test_finder.py
index 40f690e..1f6274c 100644
--- 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')
- self.assertTrue(loader is None)
+ self.assertIs(loader, None)
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'])
- self.assertTrue(loader is None)
+ self.assertIs(loader, None)
diff --git a/Lib/importlib/test/builtin/test_loader.py b/Lib/importlib/test/builtin/test_loader.py
index ec126c9..357ec26 100644
--- 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."""
- self.assertTrue(isinstance(module, types.ModuleType))
+ self.assertIsInstance(module, types.ModuleType)
for attr, value in self.verification.items():
self.assertEqual(getattr(module, attr), value)
- self.assertTrue(module.__name__ in sys.modules)
+ self.assertIn(module.__name__, sys.modules)
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)
- self.assertTrue(module1 is module2)
+ self.assertIs(module1, module2)
def test_unloadable(self):
name = 'dssdsdfff'
@@ -74,12 +74,12 @@ class InspectLoaderTests(unittest.TestCase):
def test_get_code(self):
# There is no code object.
result = machinery.BuiltinImporter.get_code(builtin_util.NAME)
- self.assertTrue(result is None)
+ self.assertIs(result, None)
def test_get_source(self):
# There is no source.
result = machinery.BuiltinImporter.get_source(builtin_util.NAME)
- self.assertTrue(result is None)
+ self.assertIs(result, None)
def test_is_package(self):
# Cannot be a package.
diff --git a/Lib/importlib/test/extension/test_finder.py b/Lib/importlib/test/extension/test_finder.py
index 804d862..ef84884 100644
--- 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):
- 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?
diff --git a/Lib/importlib/test/extension/test_loader.py b/Lib/importlib/test/extension/test_loader.py
index 4f486ce..917843f 100644
--- 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)
- self.assertTrue(ext_util.NAME in sys.modules)
- self.assertTrue(isinstance(module.__loader__,
- machinery.ExtensionFileLoader))
+ self.assertIn(ext_util.NAME, sys.modules)
+ self.assertIsInstance(module.__loader__,
+ machinery.ExtensionFileLoader)
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)
- self.assertTrue(module1 is module2)
+ self.assertIs(module1, module2)
def test_state_after_failure(self):
# No easy way to trigger a failure after a successful import.
diff --git a/Lib/importlib/test/frozen/test_finder.py b/Lib/importlib/test/frozen/test_finder.py
index db88379..a51d939 100644
--- 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('<not real>')
- self.assertTrue(loader is None)
+ self.assertIs(loader, None)
def test_main():
diff --git a/Lib/importlib/test/frozen/test_loader.py b/Lib/importlib/test/frozen/test_loader.py
index 6819a09..87a479a 100644
--- 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__')
- self.assertTrue(module1 is module2)
+ self.assertIs(module1, module2)
self.assertEqual(stdout.getvalue(),
'Hello world!\nHello world!\n')
@@ -93,7 +93,7 @@ class InspectLoaderTests(unittest.TestCase):
def test_get_source(self):
# Should always return None.
result = machinery.FrozenImporter.get_source('__hello__')
- self.assertTrue(result is None)
+ self.assertIs(result, None)
def test_is_package(self):
# Should be able to tell what is a package.
@@ -101,7 +101,7 @@ class InspectLoaderTests(unittest.TestCase):
('__phello__.spam', False))
for name, is_package in test_for:
result = machinery.FrozenImporter.is_package(name)
- self.assertTrue(bool(result) == is_package)
+ self.assertEqual(bool(result), is_package)
def test_failure(self):
# Raise ImportError for modules that are not frozen.
diff --git a/Lib/importlib/test/import_/test_caching.py b/Lib/importlib/test/import_/test_caching.py
index 3baff55..bf68027 100644
--- 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'))
- 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.
@import_util.importlib_only
diff --git a/Lib/importlib/test/import_/test_meta_path.py b/Lib/importlib/test/import_/test_meta_path.py
index 2f65af9..7f6d6da 100644
--- 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)
- self.assertTrue(args[1] is None)
+ self.assertIs(args[1], None)
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)
- self.assertTrue(args[1] is path)
+ self.assertIs(args[1], path)
diff --git a/Lib/importlib/test/import_/test_packages.py b/Lib/importlib/test/import_/test_packages.py
index 931494d..bfa18dc 100644
--- a/Lib/importlib/test/import_/test_packages.py
+++ b/Lib/importlib/test/import_/test_packages.py
@@ -14,7 +14,7 @@ class ParentModuleTests(unittest.TestCase):
with util.mock_modules('pkg.__init__', 'pkg.module') as mock:
with util.import_state(meta_path=[mock]):
module = import_util.import_('pkg.module')
- self.assertTrue('pkg' in sys.modules)
+ self.assertIn('pkg', sys.modules)
def test_bad_parent(self):
with util.mock_modules('pkg.module') as mock:
@@ -33,12 +33,12 @@ class ParentModuleTests(unittest.TestCase):
with util.import_state(meta_path=[mock]):
with self.assertRaises(ZeroDivisionError):
import_util.import_('pkg')
- self.assertFalse('pkg' in sys.modules)
- self.assertTrue('pkg.module' in sys.modules)
+ self.assertNotIn('pkg', sys.modules)
+ self.assertIn('pkg.module', sys.modules)
with self.assertRaises(ZeroDivisionError):
import_util.import_('pkg.module')
- self.assertFalse('pkg' in sys.modules)
- self.assertTrue('pkg.module' in sys.modules)
+ self.assertNotIn('pkg', sys.modules)
+ self.assertIn('pkg.module', sys.modules)
def test_raising_parent_after_relative_importing_child(self):
def __init__():
@@ -52,12 +52,12 @@ class ParentModuleTests(unittest.TestCase):
# This raises ImportError on the "from . import module"
# line, not sure why.
import_util.import_('pkg')
- self.assertFalse('pkg' in sys.modules)
+ self.assertNotIn('pkg', sys.modules)
with self.assertRaises((ZeroDivisionError, ImportError)):
import_util.import_('pkg.module')
- self.assertFalse('pkg' in sys.modules)
+ self.assertNotIn('pkg', sys.modules)
# 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 __init__():
@@ -72,12 +72,12 @@ class ParentModuleTests(unittest.TestCase):
# This raises ImportError on the "from ..subpkg import module"
# line, not sure why.
import_util.import_('pkg.subpkg')
- self.assertFalse('pkg.subpkg' in sys.modules)
+ self.assertNotIn('pkg.subpkg', sys.modules)
with self.assertRaises((ZeroDivisionError, ImportError)):
import_util.import_('pkg.subpkg.module')
- self.assertFalse('pkg.subpkg' in sys.modules)
+ self.assertNotIn('pkg.subpkg', sys.modules)
# XXX False
- #self.assertTrue('pkg.subpkg.module' in sys.modules)
+ #self.assertIn('pkg.subpkg.module', sys.modules)
def test_module_not_package(self):
# Try to import a submodule from a non-package should raise ImportError.
diff --git a/Lib/importlib/test/import_/test_path.py b/Lib/importlib/test/import_/test_path.py
index 723f5b5..b8aeab1 100644
--- 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 = '<test module>'
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):
# 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)
- self.assertTrue(loader is importer)
+ self.assertIs(loader, importer)
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])
- self.assertTrue(loader is importer)
+ self.assertIs(loader, importer)
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])
- self.assertTrue(loader is importer)
- self.assertTrue(path in sys.path_importer_cache)
- self.assertTrue(sys.path_importer_cache[path] is importer)
+ self.assertIs(loader, importer)
+ self.assertIn(path, sys.path_importer_cache)
+ self.assertIs(sys.path_importer_cache[path], importer)
def test_empty_path_hooks(self):
# Test that if sys.path_hooks is empty a warning is raised,
diff --git a/Lib/importlib/test/source/test_abc_loader.py b/Lib/importlib/test/source/test_abc_loader.py
index fc98b93..27babb9 100644
--- 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.LoaderTests):
mock = self.mocker({name: path})
with util.uncache(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__='',
__loader__=mock)
self.assertTrue(not hasattr(module, '__path__'))
@@ -233,7 +233,7 @@ class PyLoaderTests(testing_abc.LoaderTests):
mock = self.mocker({name: path})
with util.uncache(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,
__path__=[os.path.dirname(path)], __package__=name,
__loader__=mock)
@@ -259,8 +259,8 @@ class PyLoaderTests(testing_abc.LoaderTests):
with util.uncache(name):
sys.modules[name] = module
loaded_module = mock.load_module(name)
- self.assertTrue(loaded_module is module)
- self.assertTrue(sys.modules[name] is module)
+ self.assertIs(loaded_module, module)
+ self.assertIs(sys.modules[name], module)
return mock, name
def test_state_after_failure(self):
@@ -273,7 +273,7 @@ class PyLoaderTests(testing_abc.LoaderTests):
sys.modules[name] = module
with self.assertRaises(ZeroDivisionError):
mock.load_module(name)
- self.assertTrue(sys.modules[name] is module)
+ self.assertIs(sys.modules[name], module)
self.assertTrue(hasattr(module, 'blah'))
return mock
@@ -284,7 +284,7 @@ class PyLoaderTests(testing_abc.LoaderTests):
with util.uncache(name):
with self.assertRaises(ZeroDivisionError):
mock.load_module(name)
- self.assertTrue(name not in sys.modules)
+ self.assertNotIn(name, sys.modules)
return mock
@@ -414,8 +414,7 @@ class SkipWritingBytecodeTests(unittest.TestCase):
sys.dont_write_bytecode = dont_write_bytecode
with util.uncache(name):
mock.load_module(name)
- self.assertTrue((name in mock.module_bytecode) is not
- dont_write_bytecode)
+ self.assertIsNot(name in mock.module_bytecode, dont_write_bytecode)
def test_no_bytecode_written(self):
self.run_test(True)
@@ -440,7 +439,7 @@ class RegeneratedBytecodeTests(unittest.TestCase):
'magic': bad_magic}})
with util.uncache(name):
mock.load_module(name)
- self.assertTrue(name in mock.module_bytecode)
+ self.assertIn(name, mock.module_bytecode)
magic = mock.module_bytecode[name][:4]
self.assertEqual(magic, imp.get_magic())
@@ -453,7 +452,7 @@ class RegeneratedBytecodeTests(unittest.TestCase):
{name: {'path': 'path/to/mod.bytecode', 'mtime': old_mtime}})
with util.uncache(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])
self.assertEqual(mtime, PyPycLoaderMock.default_mtime)
@@ -621,7 +620,7 @@ class SourceOnlyLoaderTests(SourceLoaderTestHarness):
module = self.loader.load_module(self.name)
self.verify_module(module)
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):
# __package__ needs to be set, while __path__ is set on if the module
diff --git a/Lib/importlib/test/source/test_file_loader.py b/Lib/importlib/test/source/test_file_loader.py
index ffa0c24..236abfb 100644
--- 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')
- self.assertTrue('_temp' in sys.modules)
+ self.assertIn('_temp', sys.modules)
check = {'__name__': '_temp', '__file__': mapping['_temp'],
'__package__': ''}
for attr, value in check.items():
@@ -75,7 +75,7 @@ class SimpleTest(unittest.TestCase):
loader = _bootstrap.SourceFileLoader('_pkg',
mapping['_pkg.__init__'])
module = loader.load_module('_pkg')
- self.assertTrue('_pkg' in sys.modules)
+ self.assertIn('_pkg', sys.modules)
check = {'__name__': '_pkg', '__file__': mapping['_pkg.__init__'],
'__path__': [os.path.dirname(mapping['_pkg.__init__'])],
'__package__': '_pkg'}
@@ -88,7 +88,7 @@ class SimpleTest(unittest.TestCase):
loader = _bootstrap.SourceFileLoader('_pkg.mod',
mapping['_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'],
'__package__': '_pkg'}
for attr, value in check.items():
@@ -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')
- self.assertTrue('testing_var' in module.__dict__,
+ self.assertIn('testing_var', module.__dict__,
"'testing_var' not in "
"{0}".format(list(module.__dict__.keys())))
self.assertEqual(module, sys.modules['_temp'])
@@ -139,7 +139,7 @@ class SimpleTest(unittest.TestCase):
loader = _bootstrap.SourceFileLoader('_temp', mapping['_temp'])
with self.assertRaises(SyntaxError):
loader.load_module('_temp')
- self.assertTrue('_temp' not in sys.modules)
+ self.assertNotIn('_temp', sys.modules)
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)
- self.assertTrue(module_name in sys.modules)
+ self.assertIn(module_name, sys.modules)
def manipulate_bytecode(self, name, mapping, manipulator, *,
del_source=False):
diff --git a/Lib/importlib/test/source/test_finder.py b/Lib/importlib/test/source/test_finder.py
index b22c103..e1ef938 100644
--- 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')
- self.assertTrue(nothing is None)
+ self.assertIs(nothing, None)
def test_empty_string_for_dir(self):
# The empty string from sys.path means to search in the cwd.
diff --git a/Lib/importlib/test/test_util.py b/Lib/importlib/test/test_util.py
index e477f17..efc8977 100644
--- a/Lib/importlib/test/test_util.py
+++ b/Lib/importlib/test/test_util.py
@@ -29,8 +29,8 @@ class ModuleForLoaderTests(unittest.TestCase):
module_name = 'a.b.c'
with test_util.uncache(module_name):
module = self.return_module(module_name)
- self.assertTrue(module_name in sys.modules)
- self.assertTrue(isinstance(module, types.ModuleType))
+ self.assertIn(module_name, sys.modules)
+ self.assertIsInstance(module, types.ModuleType)
self.assertEqual(module.__name__, module_name)
def test_reload(self):
@@ -48,7 +48,7 @@ class ModuleForLoaderTests(unittest.TestCase):
name = 'a.b.c'
with test_util.uncache(name):
self.raise_exception(name)
- self.assertTrue(name not in sys.modules)
+ self.assertNotIn(name, sys.modules)
def test_reload_failure(self):
# Test that a failure on reload leaves the module in-place.
@@ -77,7 +77,7 @@ class ModuleForLoaderTests(unittest.TestCase):
self.assertFalse(module)
sys.modules[name] = module
given = self.return_module(name)
- self.assertTrue(given is module)
+ self.assertIs(given, module)
def test_attributes_set(self):
# __name__, __loader__, and __package__ should be set (when