2013-10-25 16:39:02 -03:00
|
|
|
from importlib import _bootstrap
|
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
|
2013-06-15 19:39:21 -03:00
|
|
|
|
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 21:43:49 -03:00
|
|
|
|
2013-10-25 16:39:02 -03:00
|
|
|
frozen_machinery, source_machinery = util.import_importlib('importlib.machinery')
|
|
|
|
|
2009-01-17 20:24:28 -04:00
|
|
|
|
2013-11-22 12:05:39 -04:00
|
|
|
# XXX find_spec tests
|
|
|
|
|
2013-10-25 16:39:02 -03:00
|
|
|
@unittest.skipIf(ext_util.FILENAME is None, '_testcapi not available')
|
2009-02-01 00:00:05 -04:00
|
|
|
@util.case_insensitive_tests
|
2013-10-25 16:39:02 -03:00
|
|
|
class ExtensionModuleCaseSensitivityTest:
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
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
|
2013-10-25 16:39:02 -03:00
|
|
|
finder = self.machinery.FileFinder(ext_util.PATH,
|
|
|
|
(self.machinery.ExtensionFileLoader,
|
|
|
|
self.machinery.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 21:43:49 -03:00
|
|
|
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'))
|
2009-01-17 20:24:28 -04:00
|
|
|
|
2013-10-25 16:39:02 -03:00
|
|
|
Frozen_ExtensionCaseSensitivity, Source_ExtensionCaseSensitivity = util.test_both(
|
|
|
|
ExtensionModuleCaseSensitivityTest,
|
|
|
|
machinery=[frozen_machinery, source_machinery])
|
2009-01-17 20:24:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2013-10-25 16:39:02 -03:00
|
|
|
unittest.main()
|