mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
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.
This commit is contained in:
commit
9ab358ad7c
5 changed files with 3219 additions and 3142 deletions
|
|
@ -6,7 +6,8 @@ from importlib import _bootstrap
|
|||
from importlib import machinery
|
||||
from .. import util
|
||||
from . import util as ext_util
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
@util.case_insensitive_tests
|
||||
class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
|
||||
|
|
@ -30,14 +31,34 @@ class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
|
|||
self.assertIsNone(loader)
|
||||
|
||||
def test_case_insensitivity(self):
|
||||
with 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')
|
||||
loader = self.find_module()
|
||||
self.assertTrue(hasattr(loader, 'load_module'))
|
||||
find_snippet = """if True:
|
||||
from importlib import _bootstrap
|
||||
import sys
|
||||
finder = _bootstrap.FileFinder('{path}',
|
||||
(_bootstrap.ExtensionFileLoader,
|
||||
_bootstrap.EXTENSION_SUFFIXES))
|
||||
loader = finder.find_module('{bad_name}')
|
||||
print(str(hasattr(loader, 'load_module')))
|
||||
""".format(bad_name=ext_util.NAME.upper(), path=ext_util.PATH)
|
||||
|
||||
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().strip()
|
||||
self.assertEqual(expected, actual)
|
||||
self.assertEqual(p.wait(), 0)
|
||||
|
||||
# Test with PYTHONCASEOK=1.
|
||||
check_output("True")
|
||||
|
||||
# Test with PYTHONCASEOK=1 ignored because of -E.
|
||||
check_output("False", "-E")
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue