diff options
author | Brett Cannon <bcannon@gmail.com> | 2009-05-11 01:47:11 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2009-05-11 01:47:11 (GMT) |
commit | 1262e7c7468b6a92a680161c322a0234b526e3db (patch) | |
tree | 810d23e94fd2bf85148588e3ec22caf1b0cf79dd /Lib/importlib/test | |
parent | cc3b8d6883f52391c59f59e82bfa1840e2847d90 (diff) | |
download | cpython-1262e7c7468b6a92a680161c322a0234b526e3db.zip cpython-1262e7c7468b6a92a680161c322a0234b526e3db.tar.gz cpython-1262e7c7468b6a92a680161c322a0234b526e3db.tar.bz2 |
Tests for case-senstivity were not being skipped for darwin when installed on a
case-sensitive filesystems -- which is not the default case. Along the way also
fixed the skipping of tests when sys.dont_write_bytecode is true.
Closes issue #5442 again.
Diffstat (limited to 'Lib/importlib/test')
-rw-r--r-- | Lib/importlib/test/extension/test_case_sensitivity.py | 4 | ||||
-rw-r--r-- | Lib/importlib/test/source/test_abc_loader.py | 16 | ||||
-rw-r--r-- | Lib/importlib/test/source/test_case_sensitivity.py | 14 | ||||
-rw-r--r-- | Lib/importlib/test/source/test_file_loader.py | 4 | ||||
-rw-r--r-- | Lib/importlib/test/source/util.py | 27 | ||||
-rw-r--r-- | Lib/importlib/test/util.py | 17 |
6 files changed, 37 insertions, 45 deletions
diff --git a/Lib/importlib/test/extension/test_case_sensitivity.py b/Lib/importlib/test/extension/test_case_sensitivity.py index 2ccec89..3865539 100644 --- a/Lib/importlib/test/extension/test_case_sensitivity.py +++ b/Lib/importlib/test/extension/test_case_sensitivity.py @@ -20,13 +20,13 @@ class ExtensionModuleCaseSensitivityTest(unittest.TestCase): with support.EnvironmentVarGuard() as env: env.unset('PYTHONCASEOK') loader = self.find_module() - self.assert_(loader is None) + self.assertIsNone(loader) def test_case_insensitivity(self): with support.EnvironmentVarGuard() as env: env.set('PYTHONCASEOK', '1') loader = self.find_module() - self.assert_(hasattr(loader, 'load_module')) + self.assertTrue(hasattr(loader, 'load_module')) diff --git a/Lib/importlib/test/source/test_abc_loader.py b/Lib/importlib/test/source/test_abc_loader.py index fc11e65..b95db04 100644 --- a/Lib/importlib/test/source/test_abc_loader.py +++ b/Lib/importlib/test/source/test_abc_loader.py @@ -157,10 +157,10 @@ class PyLoaderTests(testing_abc.LoaderTests): mock = self.mocker({name: path}) with util.uncache(name): module = mock.load_module(name) - self.assert_(name in sys.modules) + self.assertIn(name, sys.modules) self.eq_attrs(module, __name__=name, __file__=path, __package__='pkg', __loader__=mock) - self.assert_(not hasattr(module, '__path__')) + self.assertFalse(hasattr(module, '__path__')) return mock, name def test_module_reuse(self): @@ -247,16 +247,16 @@ class PyPycLoaderTests(PyLoaderTests): mocker = PyPycLoaderMock - @source_util.writes_bytecode + @source_util.writes_bytecode_files def verify_bytecode(self, mock, name): assert name in mock.module_paths - self.assert_(name in mock.module_bytecode) + self.assertIn(name, mock.module_bytecode) magic = mock.module_bytecode[name][:4] self.assertEqual(magic, imp.get_magic()) mtime = importlib._r_long(mock.module_bytecode[name][4:8]) self.assertEqual(mtime, 1) bc = mock.module_bytecode[name][8:] - + self.assertEqual(bc, mock.compile_bc(name)) def test_module(self): mock, name = super().test_module() @@ -286,7 +286,7 @@ class SkipWritingBytecodeTests(unittest.TestCase): """Test that bytecode is properly handled based on sys.dont_write_bytecode.""" - @source_util.writes_bytecode + @source_util.writes_bytecode_files def run_test(self, dont_write_bytecode): name = 'mod' mock = PyPycLoaderMock({name: os.path.join('path', 'to', 'mod')}) @@ -307,7 +307,7 @@ class RegeneratedBytecodeTests(unittest.TestCase): """Test that bytecode is regenerated as expected.""" - @source_util.writes_bytecode + @source_util.writes_bytecode_files def test_different_magic(self): # A different magic number should lead to new bytecode. name = 'mod' @@ -323,7 +323,7 @@ class RegeneratedBytecodeTests(unittest.TestCase): magic = mock.module_bytecode[name][:4] self.assertEqual(magic, imp.get_magic()) - @source_util.writes_bytecode + @source_util.writes_bytecode_files def test_old_mtime(self): # Bytecode with an older mtime should be regenerated. name = 'mod' diff --git a/Lib/importlib/test/source/test_case_sensitivity.py b/Lib/importlib/test/source/test_case_sensitivity.py index 368e893..6fad881 100644 --- a/Lib/importlib/test/source/test_case_sensitivity.py +++ b/Lib/importlib/test/source/test_case_sensitivity.py @@ -36,18 +36,18 @@ class CaseSensitivityTest(unittest.TestCase): with test_support.EnvironmentVarGuard() as env: env.unset('PYTHONCASEOK') sensitive, insensitive = self.sensitivity_test() - self.assert_(hasattr(sensitive, 'load_module')) - self.assert_(self.name in sensitive._base_path) - self.assert_(insensitive is None) + self.assertTrue(hasattr(sensitive, 'load_module')) + self.assertIn(self.name, sensitive._base_path) + self.assertIsNone(insensitive) def test_insensitive(self): with test_support.EnvironmentVarGuard() as env: env.set('PYTHONCASEOK', '1') sensitive, insensitive = self.sensitivity_test() - self.assert_(hasattr(sensitive, 'load_module')) - self.assert_(self.name in sensitive._base_path) - self.assert_(hasattr(insensitive, 'load_module')) - self.assert_(self.name in insensitive._base_path) + self.assertTrue(hasattr(sensitive, 'load_module')) + self.assertIn(self.name, sensitive._base_path) + self.assertTrue(hasattr(insensitive, 'load_module')) + self.assertIn(self.name, insensitive._base_path) def test_main(): diff --git a/Lib/importlib/test/source/test_file_loader.py b/Lib/importlib/test/source/test_file_loader.py index f3d75c3..d01a2a7 100644 --- a/Lib/importlib/test/source/test_file_loader.py +++ b/Lib/importlib/test/source/test_file_loader.py @@ -127,7 +127,7 @@ class BadBytecodeTest(unittest.TestCase): self.assert_(module_name in sys.modules) # [bad magic] - @source_util.writes_bytecode + @source_util.writes_bytecode_files def test_bad_magic(self): with source_util.create_modules('_temp') as mapping: py_compile.compile(mapping['_temp']) @@ -140,7 +140,7 @@ class BadBytecodeTest(unittest.TestCase): self.assertEqual(bytecode_file.read(4), imp.get_magic()) # [bad timestamp] - @source_util.writes_bytecode + @source_util.writes_bytecode_files def test_bad_bytecode(self): zeros = b'\x00\x00\x00\x00' with source_util.create_modules('_temp') as mapping: diff --git a/Lib/importlib/test/source/util.py b/Lib/importlib/test/source/util.py index 280edb4..ca04edf 100644 --- a/Lib/importlib/test/source/util.py +++ b/Lib/importlib/test/source/util.py @@ -9,32 +9,23 @@ import tempfile from test import support -def writes_bytecode(fxn): - """Decorator to protect sys.dont_write_bytecode from mutation.""" +def writes_bytecode_files(fxn): + """Decorator to protect sys.dont_write_bytecode from mutation and to skip + tests that require it to be set to False.""" + if sys.dont_write_bytecode: + return lambda *args, **kwargs: None @functools.wraps(fxn) def wrapper(*args, **kwargs): original = sys.dont_write_bytecode sys.dont_write_bytecode = False - to_return = fxn(*args, **kwargs) - sys.dont_write_bytecode = original + try: + to_return = fxn(*args, **kwargs) + finally: + sys.dont_write_bytecode = original return to_return return wrapper -def writes_bytecode_files(fxn): - """Decorator that returns the function if writing bytecode is enabled, else - a stub function that accepts anything and simply returns None.""" - if sys.dont_write_bytecode: - return lambda *args, **kwargs: None - else: - @functools.wraps(fxn) - def wrapper(*args, **kwargs): - to_return = fxn(*args, **kwargs) - sys.dont_write_bytecode = False - return to_return - return wrapper - - def bytecode_path(source_path): for suffix, _, type_ in imp.get_suffixes(): if type_ == imp.PY_COMPILED: diff --git a/Lib/importlib/test/util.py b/Lib/importlib/test/util.py index 9ff54a2..845e380 100644 --- a/Lib/importlib/test/util.py +++ b/Lib/importlib/test/util.py @@ -7,17 +7,18 @@ import sys def case_insensitive_tests(class_): - """Class decorator that nullifies tests that require a case-insensitive + """Class decorator that nullifies tests requiring a case-insensitive file system.""" - if sys.platform not in ('win32', 'darwin', 'cygwin'): - original_name = os.listdir('.')[0] - if original_name.upper() != original_name: - changed_name = original_name.upper() - else: - changed_name = original_name.lower() + # Windows is the only OS that is *always* case-insensitive + # (OS X *can* be case-sensitive). + if sys.platform not in ('win32', 'cygwin'): + changed_name = __file__.upper() + if changed_name == __file__: + changed_name = __file__.lower() if os.path.exists(changed_name): return class_ - return unittest.TestCase + else: + return unittest.TestCase else: return class_ |