changeset: 76873:e1d0535372d0 user: Brett Cannon date: Fri May 11 11:12:00 2012 -0400 files: Lib/importlib/test/benchmark.py description: Issue #14764: Update importlib.test.benchmark to work in a world where import machinery is no longer implicit. diff -r 4e9680570be8 -r e1d0535372d0 Lib/importlib/test/benchmark.py --- a/Lib/importlib/test/benchmark.py Thu May 10 18:11:30 2012 -0700 +++ b/Lib/importlib/test/benchmark.py Fri May 11 11:12:00 2012 -0400 @@ -9,6 +9,8 @@ import decimal import imp import importlib +import importlib._bootstrap +import importlib.machinery import json import os import py_compile @@ -68,6 +70,10 @@ # Clears out sys.modules and puts an entry at the front of sys.path. with source_util.create_modules(name) as mapping: assert not os.path.exists(imp.cache_from_source(mapping[name])) + sys.meta_path.append(importlib.machinery.PathFinder) + loader = (importlib.machinery.SourceFileLoader, + importlib._bootstrap._SOURCE_SUFFIXES, True) + sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader)) for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat, seconds=seconds): yield result @@ -102,6 +108,10 @@ assert not sys.dont_write_bytecode name = '__importlib_test_benchmark__' with source_util.create_modules(name) as mapping: + sys.meta_path.append(importlib.machinery.PathFinder) + loader = (importlib.machinery.SourceFileLoader, + importlib._bootstrap._SOURCE_SUFFIXES, True) + sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader)) def cleanup(): sys.modules.pop(name) os.unlink(imp.cache_from_source(mapping[name])) @@ -133,6 +143,10 @@ """Source w/ bytecode: small""" name = '__importlib_test_benchmark__' with source_util.create_modules(name) as mapping: + sys.meta_path.append(importlib.machinery.PathFinder) + loader = (importlib.machinery.SourceFileLoader, + importlib._bootstrap._SOURCE_SUFFIXES, True) + sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader)) py_compile.compile(mapping[name]) assert os.path.exists(imp.cache_from_source(mapping[name])) for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat,

AltStyle によって変換されたページ (->オリジナル) /