changeset: 102370:f4c91b883772 parent: 102368:0d8f139a6e19 parent: 102369:6b46c1510bfa user: Brett Cannon date: Sat Jul 16 10:45:16 2016 -0700 files: Lib/importlib/_bootstrap_external.py Lib/test/test_importlib/extension/test_case_sensitivity.py Lib/test/test_importlib/source/test_case_sensitivity.py Lib/test/test_importlib/util.py Python/importlib_external.h description: Merge for #27083 diff -r 0d8f139a6e19 -r f4c91b883772 Lib/importlib/_bootstrap_external.py --- a/Lib/importlib/_bootstrap_external.py Sat Jul 16 07:17:46 2016 +0000 +++ b/Lib/importlib/_bootstrap_external.py Sat Jul 16 10:45:16 2016 -0700 @@ -21,16 +21,22 @@ # anything specified at the class level. # Bootstrap-related code ###################################################### - -_CASE_INSENSITIVE_PLATFORMS = 'win', 'cygwin', 'darwin' +_CASE_INSENSITIVE_PLATFORMS_STR_KEY = 'win', +_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY = 'cygwin', 'darwin' +_CASE_INSENSITIVE_PLATFORMS = (_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY + + _CASE_INSENSITIVE_PLATFORMS_STR_KEY) def _make_relax_case(): if sys.platform.startswith(_CASE_INSENSITIVE_PLATFORMS): + if sys.platform.startswith(_CASE_INSENSITIVE_PLATFORMS_STR_KEY): + key = 'PYTHONCASEOK' + else: + key = b'PYTHONCASEOK' + def _relax_case(): """True if filenames must be checked case-insensitively.""" - return (b'PYTHONCASEOK' in _os.environ - or 'PYTHONCASEOK' in _os.environ) + return key in _os.environ else: def _relax_case(): """True if filenames must be checked case-insensitively.""" diff -r 0d8f139a6e19 -r f4c91b883772 Lib/test/test_importlib/extension/test_case_sensitivity.py --- a/Lib/test/test_importlib/extension/test_case_sensitivity.py Sat Jul 16 07:17:46 2016 +0000 +++ b/Lib/test/test_importlib/extension/test_case_sensitivity.py Sat Jul 16 10:45:16 2016 -0700 @@ -4,12 +4,13 @@ from .. import util +importlib = util.import_importlib('importlib') machinery = util.import_importlib('importlib.machinery') @unittest.skipIf(util.EXTENSIONS.filename is None, '_testcapi not available') @util.case_insensitive_tests -class ExtensionModuleCaseSensitivityTest: +class ExtensionModuleCaseSensitivityTest(util.CASEOKTestBase): def find_module(self): good_name = util.EXTENSIONS.name @@ -23,25 +24,22 @@ def test_case_sensitive(self): with support.EnvironmentVarGuard() as env: env.unset('PYTHONCASEOK') - if b'PYTHONCASEOK' in _bootstrap_external._os.environ: - self.skipTest('os.environ changes not reflected in ' - '_os.environ') + self.caseok_env_changed(should_exist=False) loader = self.find_module() self.assertIsNone(loader) def test_case_insensitivity(self): with support.EnvironmentVarGuard() as env: env.set('PYTHONCASEOK', '1') - if b'PYTHONCASEOK' not in _bootstrap_external._os.environ: - self.skipTest('os.environ changes not reflected in ' - '_os.environ') + self.caseok_env_changed(should_exist=True) loader = self.find_module() self.assertTrue(hasattr(loader, 'load_module')) (Frozen_ExtensionCaseSensitivity, Source_ExtensionCaseSensitivity - ) = util.test_both(ExtensionModuleCaseSensitivityTest, machinery=machinery) + ) = util.test_both(ExtensionModuleCaseSensitivityTest, importlib=importlib, + machinery=machinery) if __name__ == '__main__': diff -r 0d8f139a6e19 -r f4c91b883772 Lib/test/test_importlib/source/test_case_sensitivity.py --- a/Lib/test/test_importlib/source/test_case_sensitivity.py Sat Jul 16 07:17:46 2016 +0000 +++ b/Lib/test/test_importlib/source/test_case_sensitivity.py Sat Jul 16 10:45:16 2016 -0700 @@ -10,7 +10,7 @@ @util.case_insensitive_tests -class CaseSensitivityTest: +class CaseSensitivityTest(util.CASEOKTestBase): """PEP 235 dictates that on case-preserving, case-insensitive file systems that imports are case-sensitive unless the PYTHONCASEOK environment @@ -38,17 +38,10 @@ insensitive_finder = self.finder(insensitive_path) return self.find(sensitive_finder), self.find(insensitive_finder) - def env_changed(self, *, should_exist): - possibilities = b'PYTHONCASEOK', 'PYTHONCASEOK' - if any(x in self.importlib._bootstrap_external._os.environ - for x in possibilities) == should_exist: - self.skipTest('os.environ changes not reflected in ' - '_os.environ') - def test_sensitive(self): with test_support.EnvironmentVarGuard() as env: env.unset('PYTHONCASEOK') - self.env_changed(should_exist=False) + self.caseok_env_changed(should_exist=False) sensitive, insensitive = self.sensitivity_test() self.assertIsNotNone(sensitive) self.assertIn(self.name, sensitive.get_filename(self.name)) @@ -57,7 +50,7 @@ def test_insensitive(self): with test_support.EnvironmentVarGuard() as env: env.set('PYTHONCASEOK', '1') - self.env_changed(should_exist=True) + self.caseok_env_changed(should_exist=True) sensitive, insensitive = self.sensitivity_test() self.assertIsNotNone(sensitive) self.assertIn(self.name, sensitive.get_filename(self.name)) diff -r 0d8f139a6e19 -r f4c91b883772 Lib/test/test_importlib/util.py --- a/Lib/test/test_importlib/util.py Sat Jul 16 07:17:46 2016 +0000 +++ b/Lib/test/test_importlib/util.py Sat Jul 16 10:45:16 2016 -0700 @@ -377,3 +377,12 @@ raise ImportError return importer return hook + + +class CASEOKTestBase: + + def caseok_env_changed(self, *, should_exist): + possibilities = b'PYTHONCASEOK', 'PYTHONCASEOK' + if any(x in self.importlib._bootstrap_external._os.environ + for x in possibilities) != should_exist: + self.skipTest('os.environ changes not reflected in _os.environ')