Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c56145

Browse files
committed
Issue #16826: Revert fix while Windows issues are being worked out.
2 parents 2b0a98f + c9e1dcd commit 3c56145

5 files changed

Lines changed: 3134 additions & 3211 deletions

File tree

Lib/importlib/_bootstrap.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ def _make_relax_case():
2929
if sys.platform.startswith(_CASE_INSENSITIVE_PLATFORMS):
3030
def _relax_case():
3131
"""True if filenames must be checked case-insensitively."""
32-
if sys.flags.ignore_environment:
33-
return False
34-
else:
35-
return b'PYTHONCASEOK' in _os.environ
32+
return b'PYTHONCASEOK' in _os.environ
3633
else:
3734
def _relax_case():
3835
"""True if filenames must be checked case-insensitively."""

Lib/test/test_importlib/extension/test_case_sensitivity.py

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from importlib import machinery
77
from .. import util
88
from . import util as ext_util
9-
import os
10-
import subprocess
9+
1110

1211
@util.case_insensitive_tests
1312
class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
@@ -31,34 +30,14 @@ def test_case_sensitive(self):
3130
self.assertIsNone(loader)
3231

3332
def test_case_insensitivity(self):
34-
find_snippet = """if True:
35-
from importlib import _bootstrap
36-
import sys
37-
finder = _bootstrap.FileFinder('{path}',
38-
(_bootstrap.ExtensionFileLoader,
39-
_bootstrap.EXTENSION_SUFFIXES))
40-
loader = finder.find_module('{bad_name}')
41-
print(str(hasattr(loader, 'load_module')))
42-
""".format(bad_name=ext_util.NAME.upper(), path=ext_util.PATH)
43-
44-
newenv = os.environ.copy()
45-
newenv["PYTHONCASEOK"] = "1"
46-
47-
def check_output(expected, extra_arg=None):
48-
args = [sys.executable]
49-
if extra_arg:
50-
args.append(extra_arg)
51-
args.extend(["-c", find_snippet])
52-
p = subprocess.Popen(args, stdout=subprocess.PIPE, env=newenv)
53-
actual = p.communicate()[0].decode().strip()
54-
self.assertEqual(expected, actual)
55-
self.assertEqual(p.wait(), 0)
56-
57-
# Test with PYTHONCASEOK=1.
58-
check_output("True")
33+
with support.EnvironmentVarGuard() as env:
34+
env.set('PYTHONCASEOK', '1')
35+
if b'PYTHONCASEOK' not in _bootstrap._os.environ:
36+
self.skipTest('os.environ changes not reflected in '
37+
'_os.environ')
38+
loader = self.find_module()
39+
self.assertTrue(hasattr(loader, 'load_module'))
5940

60-
# Test with PYTHONCASEOK=1 ignored because of -E.
61-
check_output("False", "-E")
6241

6342

6443

Lib/test/test_importlib/source/test_case_sensitivity.py

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import sys
99
from test import support as test_support
1010
import unittest
11-
import subprocess
1211

1312

1413
@util.case_insensitive_tests
@@ -51,62 +50,16 @@ def test_sensitive(self):
5150
self.assertIsNone(insensitive)
5251

5352
def test_insensitive(self):
54-
sensitive_pkg = 'sensitive.{0}'.format(self.name)
55-
insensitive_pkg = 'insensitive.{0}'.format(self.name.lower())
56-
context = source_util.create_modules(insensitive_pkg, sensitive_pkg)
57-
with context as mapping:
58-
sensitive_path = os.path.join(mapping['.root'], 'sensitive')
59-
insensitive_path = os.path.join(mapping['.root'], 'insensitive')
60-
find_snippet = """if True:
61-
import sys
62-
from importlib import machinery
63-
64-
def find(path):
65-
f = machinery.FileFinder(path,
66-
(machinery.SourceFileLoader,
67-
machinery.SOURCE_SUFFIXES),
68-
(machinery.SourcelessFileLoader,
69-
machinery.BYTECODE_SUFFIXES))
70-
return f.find_module('{name}')
71-
72-
sensitive = find('{sensitive_path}')
73-
insensitive = find('{insensitive_path}')
74-
print(str(hasattr(sensitive, 'load_module')))
75-
if hasattr(sensitive, 'load_module'):
76-
print(sensitive.get_filename('{name}'))
77-
else:
78-
print('None')
79-
print(str(hasattr(insensitive, 'load_module')))
80-
if hasattr(insensitive, 'load_module'):
81-
print(insensitive.get_filename('{name}'))
82-
else:
83-
print('None')
84-
""".format(sensitive_path=sensitive_path,
85-
insensitive_path=insensitive_path,
86-
name=self.name)
87-
88-
newenv = os.environ.copy()
89-
newenv["PYTHONCASEOK"] = "1"
90-
91-
def check_output(expected, extra_arg=None):
92-
args = [sys.executable]
93-
if extra_arg:
94-
args.append(extra_arg)
95-
args.extend(["-c", find_snippet])
96-
p = subprocess.Popen(args, stdout=subprocess.PIPE,
97-
env=newenv)
98-
actual = p.communicate()[0].decode().split()
99-
self.assertEqual(expected[0], actual[0])
100-
self.assertIn(expected[1], actual[1])
101-
self.assertEqual(expected[2], actual[2])
102-
self.assertIn(expected[3], actual[3])
103-
self.assertEqual(p.wait(), 0)
104-
105-
# Test with PYTHONCASEOK=1.
106-
check_output(["True", self.name, "True", self.name])
107-
108-
# Test with PYTHONCASEOK=1 ignored because of -E.
109-
check_output(["True", self.name, "False", "None"], "-E")
53+
with test_support.EnvironmentVarGuard() as env:
54+
env.set('PYTHONCASEOK', '1')
55+
if b'PYTHONCASEOK' not in _bootstrap._os.environ:
56+
self.skipTest('os.environ changes not reflected in '
57+
'_os.environ')
58+
sensitive, insensitive = self.sensitivity_test()
59+
self.assertTrue(hasattr(sensitive, 'load_module'))
60+
self.assertIn(self.name, sensitive.get_filename(self.name))
61+
self.assertTrue(hasattr(insensitive, 'load_module'))
62+
self.assertIn(self.name, insensitive.get_filename(self.name))
11063

11164

11265
def test_main():

Misc/NEWS

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ Core and Builtins
5454
Library
5555
-------
5656

57-
- Issue #16826: Don't check for PYTHONCASEOK if interpreter started with -E.
58-
5957
- Issue #18901: The sunau getparams method now returns a namedtuple rather than
6058
a plain tuple. Patch by Claudiu Popa.
6159

0 commit comments

Comments
 (0)