]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #27083: Respect the PYTHONCASEOK environment variable under
authorBrett Cannon <brett@python.org>
Fri, 15 Jul 2016 18:54:38 +0000 (11:54 -0700)
committerBrett Cannon <brett@python.org>
Fri, 15 Jul 2016 18:54:38 +0000 (11:54 -0700)
Windows.

Originally only b'PYTHONCASEOK' was being checked for in os.environ,
but that won't work under Windows where all environment variables are
strings (on OS X they are bytes).

Thanks to Eryk Sun for the bug report.

Lib/importlib/_bootstrap_external.py
Lib/test/test_importlib/source/test_case_sensitivity.py
Misc/NEWS

index 08ddb2b17fe4e48a7fba3f6b32bfd5d5b755e5b8..6e2ddb5b7dfbf599c6818244cc7e0df8c58a102c 100644 (file)
@@ -29,7 +29,8 @@ def _make_relax_case():
     if sys.platform.startswith(_CASE_INSENSITIVE_PLATFORMS):
         def _relax_case():
             """True if filenames must be checked case-insensitively."""
-            return b'PYTHONCASEOK' in _os.environ
+            return (b'PYTHONCASEOK' in _os.environ
+                    or 'PYTHONCASEOK' in _os.environ)
     else:
         def _relax_case():
             """True if filenames must be checked case-insensitively."""
index c274b3823f837b4c3a2dae4d50934da2a04e60eb..c4bf306b5d94bf05c37a18c2fee15168bac1abe9 100644 (file)
@@ -39,12 +39,17 @@ class CaseSensitivityTest:
             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')
-            if b'PYTHONCASEOK' in self.importlib._bootstrap_external._os.environ:
-                self.skipTest('os.environ changes not reflected in '
-                              '_os.environ')
+            self.env_changed(should_exist=False)
             sensitive, insensitive = self.sensitivity_test()
             self.assertIsNotNone(sensitive)
             self.assertIn(self.name, sensitive.get_filename(self.name))
@@ -53,9 +58,7 @@ class CaseSensitivityTest:
     def test_insensitive(self):
         with test_support.EnvironmentVarGuard() as env:
             env.set('PYTHONCASEOK', '1')
-            if b'PYTHONCASEOK' not in self.importlib._bootstrap_external._os.environ:
-                self.skipTest('os.environ changes not reflected in '
-                              '_os.environ')
+            self.env_changed(should_exist=True)
             sensitive, insensitive = self.sensitivity_test()
             self.assertIsNotNone(sensitive)
             self.assertIn(self.name, sensitive.get_filename(self.name))
index 6911d1f6ac5132342603ffa52e798709404d4d25..a13b2fb34b8c32c14180684fde8f384baa8f2eea 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ Release date: TBA
 Core and Builtins
 -----------------
 
+- Issue #27083: Respect the PYTHONCASEOK environment variable under Windows.
+
 - Issue #27514: Make having too many statically nested blocks a SyntaxError
   instead of SystemError.