summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib/source
diff options
context:
space:
mode:
authorMeador Inge <meadori@gmail.com>2013-09-03 21:53:22 (GMT)
committerMeador Inge <meadori@gmail.com>2013-09-03 21:53:22 (GMT)
commit9ab358ad7cfc235556f52923bcf265b5bc32b4fc (patch)
tree7c1c2b1a5ad6706cc07e61236effadc4ff3d0f97 /Lib/test/test_importlib/source
parentc6171e49ab2aee5807bcb6c0f77d0de13a164a99 (diff)
parentd151da9ef7de3ce93f0e29a62ae2a470495db1d0 (diff)
downloadcpython-9ab358ad7cfc235556f52923bcf265b5bc32b4fc.zip
cpython-9ab358ad7cfc235556f52923bcf265b5bc32b4fc.tar.gz
cpython-9ab358ad7cfc235556f52923bcf265b5bc32b4fc.tar.bz2
Issue #16826: Don't check for PYTHONCASEOK when using -E.
This commit fixes a regression that sneaked into Python 3.3 where importlib was not respecting -E when checking for the PYTHONCASEOK environment variable.
Diffstat (limited to 'Lib/test/test_importlib/source')
-rw-r--r--Lib/test/test_importlib/source/test_case_sensitivity.py67
1 files changed, 57 insertions, 10 deletions
diff --git a/Lib/test/test_importlib/source/test_case_sensitivity.py b/Lib/test/test_importlib/source/test_case_sensitivity.py
index bb78d2e..0289469 100644
--- a/Lib/test/test_importlib/source/test_case_sensitivity.py
+++ b/Lib/test/test_importlib/source/test_case_sensitivity.py
@@ -8,6 +8,7 @@ import os
import sys
from test import support as test_support
import unittest
+import subprocess
@util.case_insensitive_tests
@@ -50,16 +51,62 @@ class CaseSensitivityTest(unittest.TestCase):
self.assertIsNone(insensitive)
def test_insensitive(self):
- with test_support.EnvironmentVarGuard() as env:
- env.set('PYTHONCASEOK', '1')
- if b'PYTHONCASEOK' not in _bootstrap._os.environ:
- self.skipTest('os.environ changes not reflected in '
- '_os.environ')
- sensitive, insensitive = self.sensitivity_test()
- self.assertTrue(hasattr(sensitive, 'load_module'))
- self.assertIn(self.name, sensitive.get_filename(self.name))
- self.assertTrue(hasattr(insensitive, 'load_module'))
- self.assertIn(self.name, insensitive.get_filename(self.name))
+ sensitive_pkg = 'sensitive.{0}'.format(self.name)
+ insensitive_pkg = 'insensitive.{0}'.format(self.name.lower())
+ context = source_util.create_modules(insensitive_pkg, sensitive_pkg)
+ with context as mapping:
+ sensitive_path = os.path.join(mapping['.root'], 'sensitive')
+ insensitive_path = os.path.join(mapping['.root'], 'insensitive')
+ find_snippet = """if True:
+ import sys
+ from importlib import machinery
+
+ def find(path):
+ f = machinery.FileFinder(path,
+ (machinery.SourceFileLoader,
+ machinery.SOURCE_SUFFIXES),
+ (machinery.SourcelessFileLoader,
+ machinery.BYTECODE_SUFFIXES))
+ return f.find_module('{name}')
+
+ sensitive = find('{sensitive_path}')
+ insensitive = find('{insensitive_path}')
+ print(str(hasattr(sensitive, 'load_module')))
+ if hasattr(sensitive, 'load_module'):
+ print(sensitive.get_filename('{name}'))
+ else:
+ print('None')
+ print(str(hasattr(insensitive, 'load_module')))
+ if hasattr(insensitive, 'load_module'):
+ print(insensitive.get_filename('{name}'))
+ else:
+ print('None')
+ """.format(sensitive_path=sensitive_path,
+ insensitive_path=insensitive_path,
+ name=self.name)
+
+ newenv = os.environ.copy()
+ newenv["PYTHONCASEOK"] = "1"
+
+ def check_output(expected, extra_arg=None):
+ args = [sys.executable]
+ if extra_arg:
+ args.append(extra_arg)
+ args.extend(["-c", find_snippet])
+ p = subprocess.Popen(args, stdout=subprocess.PIPE,
+ env=newenv)
+ actual = p.communicate()[0].decode().split()
+ self.assertEqual(expected[0], actual[0])
+ self.assertIn(expected[1], actual[1])
+ self.assertEqual(expected[2], actual[2])
+ self.assertIn(expected[3], actual[3])
+ self.assertEqual(p.wait(), 0)
+
+ # Test with PYTHONCASEOK=1.
+ check_output(["True", self.name, "True", self.name])
+
+ # Test with PYTHONCASEOK=1 ignored because of -E.
+ check_output(["True", self.name, "False", "None"], "-E")
def test_main():