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