annotate Lib/test/test_importlib/source/test_path_hook.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents b0f570aef6fd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
87009
b0f570aef6fd Issue #16803: test.test_importlib.source now tests frozen and source code
Brett Cannon <brett@python.org>
parents: 84159
diff changeset
1 from .. import util
76303
2dd046be2c88 Issue #2377: Make importlib the implementation of __import__().
Brett Cannon <brett@python.org>
parents: 62760
diff changeset
2 from . import util as source_util
2dd046be2c88 Issue #2377: Make importlib the implementation of __import__().
Brett Cannon <brett@python.org>
parents: 62760
diff changeset
3
87009
b0f570aef6fd Issue #16803: test.test_importlib.source now tests frozen and source code
Brett Cannon <brett@python.org>
parents: 84159
diff changeset
4 machinery = util.import_importlib('importlib.machinery')
b0f570aef6fd Issue #16803: test.test_importlib.source now tests frozen and source code
Brett Cannon <brett@python.org>
parents: 84159
diff changeset
5
50845
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
6 import unittest
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
7
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
8
87009
b0f570aef6fd Issue #16803: test.test_importlib.source now tests frozen and source code
Brett Cannon <brett@python.org>
parents: 84159
diff changeset
9 class PathHookTest:
50845
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
10
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
11 """Test the path hook for source."""
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
12
76478
1da623513b26 Issue #14605: Expose importlib.abc.FileLoader and
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
13 def path_hook(self):
87009
b0f570aef6fd Issue #16803: test.test_importlib.source now tests frozen and source code
Brett Cannon <brett@python.org>
parents: 84159
diff changeset
14 return self.machinery.FileFinder.path_hook((self.machinery.SourceFileLoader,
b0f570aef6fd Issue #16803: test.test_importlib.source now tests frozen and source code
Brett Cannon <brett@python.org>
parents: 84159
diff changeset
15 self.machinery.SOURCE_SUFFIXES))
76478
1da623513b26 Issue #14605: Expose importlib.abc.FileLoader and
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
16
50845
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
17 def test_success(self):
51236
d85ef26efd10 Rename importlib.test.support to importlib.test.util.
Brett Cannon <bcannon@gmail.com>
parents: 51234
diff changeset
18 with source_util.create_modules('dummy') as mapping:
76478
1da623513b26 Issue #14605: Expose importlib.abc.FileLoader and
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
19 self.assertTrue(hasattr(self.path_hook()(mapping['.root']),
50845
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
20 'find_module'))
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
21
62760
34f015bca54e Make importlib.abc.SourceLoader the primary mechanism for importlib.
Brett Cannon <bcannon@gmail.com>
parents: 62756
diff changeset
22 def test_empty_string(self):
34f015bca54e Make importlib.abc.SourceLoader the primary mechanism for importlib.
Brett Cannon <bcannon@gmail.com>
parents: 62756
diff changeset
23 # The empty string represents the cwd.
76478
1da623513b26 Issue #14605: Expose importlib.abc.FileLoader and
Brett Cannon <brett@python.org>
parents: 76303
diff changeset
24 self.assertTrue(hasattr(self.path_hook()(''), 'find_module'))
62760
34f015bca54e Make importlib.abc.SourceLoader the primary mechanism for importlib.
Brett Cannon <bcannon@gmail.com>
parents: 62756
diff changeset
25
87009
b0f570aef6fd Issue #16803: test.test_importlib.source now tests frozen and source code
Brett Cannon <brett@python.org>
parents: 84159
diff changeset
26 Frozen_PathHookTest, Source_PathHooktest = util.test_both(PathHookTest, machinery=machinery)
50845
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
27
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
28
aac51b70c74c Add initial implementation of importlib. See the NOTES files for what is
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
29 if __name__ == '__main__':
87009
b0f570aef6fd Issue #16803: test.test_importlib.source now tests frozen and source code
Brett Cannon <brett@python.org>
parents: 84159
diff changeset
30 unittest.main()