2012-04-22 20:58:33 -03:00
|
|
|
import imp
|
2009-01-17 20:24:28 -04:00
|
|
|
import sys
|
2009-02-01 00:00:05 -04:00
|
|
|
from test import support
|
2009-01-17 20:24:28 -04:00
|
|
|
import unittest
|
2009-03-12 19:47:53 -03:00
|
|
|
from importlib import _bootstrap
|
2009-02-01 00:00:05 -04:00
|
|
|
from .. import util
|
2009-02-06 22:06:43 -04:00
|
|
|
from . import util as ext_util
|
2013-09-03 18:37:26 -03:00
|
|
|
import os
|
|
|
|
import subprocess
|
2009-01-17 20:24:28 -04:00
|
|
|
|
2009-02-01 00:00:05 -04:00
|
|
|
@util.case_insensitive_tests
|
2009-01-17 20:24:28 -04:00
|
|
|
class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
|
|
|
|
|
|
|
|
def find_module(self):
|
2009-02-06 22:06:43 -04:00
|
|
|
good_name = ext_util.NAME
|
2009-01-17 20:24:28 -04:00
|
|
|
bad_name = good_name.upper()
|
|
|
|
assert good_name != bad_name
|
2012-04-22 20:58:33 -03:00
|
|
|
finder = _bootstrap.FileFinder(ext_util.PATH,
|
|
|
|
(_bootstrap.ExtensionFileLoader,
|
2012-08-10 14:47:54 -03:00
|
|
|
_bootstrap.EXTENSION_SUFFIXES))
|
2009-01-17 20:24:28 -04:00
|
|
|
return finder.find_module(bad_name)
|
|
|
|
|
|
|
|
def test_case_sensitive(self):
|
2009-02-01 00:00:05 -04:00
|
|
|
with support.EnvironmentVarGuard() as env:
|
2009-01-17 20:24:28 -04:00
|
|
|
env.unset('PYTHONCASEOK')
|
2012-01-30 13:51:49 -04:00
|
|
|
if b'PYTHONCASEOK' in _bootstrap._os.environ:
|
|
|
|
self.skipTest('os.environ changes not reflected in '
|
|
|
|
'_os.environ')
|
2009-01-17 20:24:28 -04:00
|
|
|
loader = self.find_module()
|
2009-05-10 22:47:11 -03:00
|
|
|
self.assertIsNone(loader)
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
def test_case_insensitivity(self):
|
2013-09-03 18:37:26 -03:00
|
|
|
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")
|
2009-01-17 20:24:28 -04:00
|
|
|
|
2013-09-03 18:37:26 -03:00
|
|
|
# Test with PYTHONCASEOK=1 ignored because of -E.
|
|
|
|
check_output("False", "-E")
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_main():
|
2009-03-08 17:50:32 -03:00
|
|
|
if ext_util.FILENAME is None:
|
|
|
|
return
|
2009-02-01 00:00:05 -04:00
|
|
|
support.run_unittest(ExtensionModuleCaseSensitivityTest)
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|