annotate Lib/importlib/test/source/test_case_sensitivity.py @ 78069:a8aa77458e12 3.2

Add c_size_t and c_ssize_t to the ctypes summary table.
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 12 Jul 2012 20:31:50 +0200
parents 34d827249ce0
children 54d7823ec488
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50845
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
1 """Test case-sensitivity (PEP 235)."""
52142
04a5b6438526 Finish properly hiding importlib implementation code.
Brett Cannon <bcannon@gmail.com>
parents: 51769
diff changeset
2 from importlib import _bootstrap
51236
d85ef26efd10 Rename importlib.test.support to importlib.test.util.
Brett Cannon <bcannon@gmail.com>
parents: 51234
diff changeset
3 from .. import util
51234
4b3246c83e3f Split out support code that is specific to source tests out of
Brett Cannon <bcannon@gmail.com>
parents: 50858
diff changeset
4 from . import util as source_util
50845
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
5 import os
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
6 import sys
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
7 from test import support as test_support
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
8 import unittest
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
9
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
10
51236
d85ef26efd10 Rename importlib.test.support to importlib.test.util.
Brett Cannon <bcannon@gmail.com>
parents: 51234
diff changeset
11 @util.case_insensitive_tests
50845
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
12 class CaseSensitivityTest(unittest.TestCase):
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
13
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
14 """PEP 235 dictates that on case-preserving, case-insensitive file systems
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
15 that imports are case-sensitive unless the PYTHONCASEOK environment
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
16 variable is set."""
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
17
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
18 name = 'MoDuLe'
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
19 assert name != name.lower()
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
20
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
21 def find(self, path):
62756
34d827249ce0 Make importlib.abc.SourceLoader the primary mechanism for importlib.
Brett Cannon <bcannon@gmail.com>
parents: 53996
diff changeset
22 finder = _bootstrap._FileFinder(path,
34d827249ce0 Make importlib.abc.SourceLoader the primary mechanism for importlib.
Brett Cannon <bcannon@gmail.com>
parents: 53996
diff changeset
23 _bootstrap._SourceFinderDetails(),
34d827249ce0 Make importlib.abc.SourceLoader the primary mechanism for importlib.
Brett Cannon <bcannon@gmail.com>
parents: 53996
diff changeset
24 _bootstrap._SourcelessFinderDetails())
50845
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
25 return finder.find_module(self.name)
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
26
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
27 def sensitivity_test(self):
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
28 """Look for a module with matching and non-matching sensitivity."""
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
29 sensitive_pkg = 'sensitive.{0}'.format(self.name)
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
30 insensitive_pkg = 'insensitive.{0}'.format(self.name.lower())
51234
4b3246c83e3f Split out support code that is specific to source tests out of
Brett Cannon <bcannon@gmail.com>
parents: 50858
diff changeset
31 context = source_util.create_modules(insensitive_pkg, sensitive_pkg)
62756
34d827249ce0 Make importlib.abc.SourceLoader the primary mechanism for importlib.
Brett Cannon <bcannon@gmail.com>
parents: 53996
diff changeset
32 with context as mapping:
50845
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
33 sensitive_path = os.path.join(mapping['.root'], 'sensitive')
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
34 insensitive_path = os.path.join(mapping['.root'], 'insensitive')
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
35 return self.find(sensitive_path), self.find(insensitive_path)
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
36
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
37 def test_sensitive(self):
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
38 with test_support.EnvironmentVarGuard() as env:
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
39 env.unset('PYTHONCASEOK')
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
40 sensitive, insensitive = self.sensitivity_test()
53996
0495bc47cd08 Tests for case-senstivity were not being skipped for darwin when installed on a
Brett Cannon <bcannon@gmail.com>
parents: 52142
diff changeset
41 self.assertTrue(hasattr(sensitive, 'load_module'))
62756
34d827249ce0 Make importlib.abc.SourceLoader the primary mechanism for importlib.
Brett Cannon <bcannon@gmail.com>
parents: 53996
diff changeset
42 self.assertIn(self.name, sensitive.get_filename(self.name))
53996
0495bc47cd08 Tests for case-senstivity were not being skipped for darwin when installed on a
Brett Cannon <bcannon@gmail.com>
parents: 52142
diff changeset
43 self.assertIsNone(insensitive)
50845
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
44
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
45 def test_insensitive(self):
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
46 with test_support.EnvironmentVarGuard() as env:
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
47 env.set('PYTHONCASEOK', '1')
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
48 sensitive, insensitive = self.sensitivity_test()
53996
0495bc47cd08 Tests for case-senstivity were not being skipped for darwin when installed on a
Brett Cannon <bcannon@gmail.com>
parents: 52142
diff changeset
49 self.assertTrue(hasattr(sensitive, 'load_module'))
62756
34d827249ce0 Make importlib.abc.SourceLoader the primary mechanism for importlib.
Brett Cannon <bcannon@gmail.com>
parents: 53996
diff changeset
50 self.assertIn(self.name, sensitive.get_filename(self.name))
53996
0495bc47cd08 Tests for case-senstivity were not being skipped for darwin when installed on a
Brett Cannon <bcannon@gmail.com>
parents: 52142
diff changeset
51 self.assertTrue(hasattr(insensitive, 'load_module'))
62756
34d827249ce0 Make importlib.abc.SourceLoader the primary mechanism for importlib.
Brett Cannon <bcannon@gmail.com>
parents: 53996
diff changeset
52 self.assertIn(self.name, insensitive.get_filename(self.name))
50845
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
53
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
54
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
55 def test_main():
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
56 test_support.run_unittest(CaseSensitivityTest)
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
57
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
58
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
59 if __name__ == '__main__':
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
60 test_main()