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

Skip to content

Commit c9e1dcd

Browse files
committed
Issue #16826: Revert fix while Windows issues are being worked out.
1 parent d151da9 commit c9e1dcd

5 files changed

Lines changed: 4225 additions & 4303 deletions

File tree

Lib/importlib/_bootstrap.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ def _make_relax_case():
3333
if sys.platform.startswith(_CASE_INSENSITIVE_PLATFORMS):
3434
def _relax_case():
3535
"""True if filenames must be checked case-insensitively."""
36-
if sys.flags.ignore_environment:
37-
return False
38-
else:
39-
return b'PYTHONCASEOK' in _os.environ
36+
return b'PYTHONCASEOK' in _os.environ
4037
else:
4138
def _relax_case():
4239
"""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
@@ -5,8 +5,7 @@
55
from importlib import _bootstrap
66
from .. import util
77
from . import util as ext_util
8-
import os
9-
import subprocess
8+
109

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

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

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

6241

6342

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
@@ -66,8 +66,6 @@ Core and Builtins
6666
Library
6767
-------
6868

69-
- Issue #16826: Don't check for PYTHONCASEOK if interpreter started with -E.
70-
7169
- Issue #18418: After fork(), reinit all threads states, not only active ones.
7270
Patch by A. Jesse Jiryu Davis.
7371

0 commit comments

Comments
 (0)