Issue #27418: Fixed Tools/importbench/importbench.py.

This commit is contained in:
Serhiy Storchaka 2016-06-30 10:33:17 +03:00
parent 457509826e
commit eb51faadbe
2 changed files with 11 additions and 7 deletions

View file

@ -72,6 +72,11 @@ C API
- Issue #26754: PyUnicode_FSDecoder() accepted a filename argument encoded as - Issue #26754: PyUnicode_FSDecoder() accepted a filename argument encoded as
an iterable of integers. Now only strings and bytes-like objects are accepted. an iterable of integers. Now only strings and bytes-like objects are accepted.
Tools/Demos
-----------
- Issue #27418: Fixed Tools/importbench/importbench.py.
What's New in Python 3.5.2? What's New in Python 3.5.2?
=========================== ===========================

View file

@ -5,7 +5,6 @@
""" """
from test.test_importlib import util from test.test_importlib import util
from test.test_importlib.source import util as source_util
import decimal import decimal
import imp import imp
import importlib import importlib
@ -65,11 +64,11 @@ def source_wo_bytecode(seconds, repeat):
try: try:
name = '__importlib_test_benchmark__' name = '__importlib_test_benchmark__'
# Clears out sys.modules and puts an entry at the front of sys.path. # Clears out sys.modules and puts an entry at the front of sys.path.
with source_util.create_modules(name) as mapping: with util.create_modules(name) as mapping:
assert not os.path.exists(imp.cache_from_source(mapping[name])) assert not os.path.exists(imp.cache_from_source(mapping[name]))
sys.meta_path.append(importlib.machinery.PathFinder) sys.meta_path.append(importlib.machinery.PathFinder)
loader = (importlib.machinery.SourceFileLoader, loader = (importlib.machinery.SourceFileLoader,
importlib.machinery.SOURCE_SUFFIXES, True) importlib.machinery.SOURCE_SUFFIXES)
sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader)) sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader))
yield from bench(name, lambda: sys.modules.pop(name), repeat=repeat, yield from bench(name, lambda: sys.modules.pop(name), repeat=repeat,
seconds=seconds) seconds=seconds)
@ -102,10 +101,10 @@ def source_writing_bytecode(seconds, repeat):
"""Source writing bytecode: small""" """Source writing bytecode: small"""
assert not sys.dont_write_bytecode assert not sys.dont_write_bytecode
name = '__importlib_test_benchmark__' name = '__importlib_test_benchmark__'
with source_util.create_modules(name) as mapping: with util.create_modules(name) as mapping:
sys.meta_path.append(importlib.machinery.PathFinder) sys.meta_path.append(importlib.machinery.PathFinder)
loader = (importlib.machinery.SourceFileLoader, loader = (importlib.machinery.SourceFileLoader,
importlib.machinery.SOURCE_SUFFIXES, True) importlib.machinery.SOURCE_SUFFIXES)
sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader)) sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader))
def cleanup(): def cleanup():
sys.modules.pop(name) sys.modules.pop(name)
@ -136,10 +135,10 @@ def cleanup():
def source_using_bytecode(seconds, repeat): def source_using_bytecode(seconds, repeat):
"""Source w/ bytecode: small""" """Source w/ bytecode: small"""
name = '__importlib_test_benchmark__' name = '__importlib_test_benchmark__'
with source_util.create_modules(name) as mapping: with util.create_modules(name) as mapping:
sys.meta_path.append(importlib.machinery.PathFinder) sys.meta_path.append(importlib.machinery.PathFinder)
loader = (importlib.machinery.SourceFileLoader, loader = (importlib.machinery.SourceFileLoader,
importlib.machinery.SOURCE_SUFFIXES, True) importlib.machinery.SOURCE_SUFFIXES)
sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader)) sys.path_hooks.append(importlib.machinery.FileFinder.path_hook(loader))
py_compile.compile(mapping[name]) py_compile.compile(mapping[name])
assert os.path.exists(imp.cache_from_source(mapping[name])) assert os.path.exists(imp.cache_from_source(mapping[name]))