1from importlib import _bootstrap_external 2from test.support import os_helper 3import unittest 4import sys 5from .. import util 6 7importlib = util.import_importlib('importlib') 8machinery = util.import_importlib('importlib.machinery') 9 10 11@unittest.skipIf(util.EXTENSIONS.filename is None, '_testcapi not available') 12@util.case_insensitive_tests 13class ExtensionModuleCaseSensitivityTest(util.CASEOKTestBase): 14 15 def find_spec(self): 16 good_name = util.EXTENSIONS.name 17 bad_name = good_name.upper() 18 assert good_name != bad_name 19 finder = self.machinery.FileFinder(util.EXTENSIONS.path, 20 (self.machinery.ExtensionFileLoader, 21 self.machinery.EXTENSION_SUFFIXES)) 22 return finder.find_spec(bad_name) 23 24 @unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set') 25 def test_case_sensitive(self): 26 with os_helper.EnvironmentVarGuard() as env: 27 env.unset('PYTHONCASEOK') 28 self.caseok_env_changed(should_exist=False) 29 spec = self.find_spec() 30 self.assertIsNone(spec) 31 32 @unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set') 33 def test_case_insensitivity(self): 34 with os_helper.EnvironmentVarGuard() as env: 35 env.set('PYTHONCASEOK', '1') 36 self.caseok_env_changed(should_exist=True) 37 spec = self.find_spec() 38 self.assertTrue(spec) 39 40 41(Frozen_ExtensionCaseSensitivity, 42 Source_ExtensionCaseSensitivity 43 ) = util.test_both(ExtensionModuleCaseSensitivityTest, importlib=importlib, 44 machinery=machinery) 45 46 47if __name__ == '__main__': 48 unittest.main() 49