[pypy-svn] r70148 - in pypy/branch/import-builtin: lib-python/modified-2.5.2/test pypy/module/imp pypy/module/imp/test
afa at codespeak.net
afa at codespeak.net
Wed Dec 16 16:27:33 CET 2009
Author: afa
Date: Wed Dec 16 16:27:31 2009
New Revision: 70148
Added:
pypy/branch/import-builtin/lib-python/modified-2.5.2/test/test_runpy.py
- copied, changed from r70029, pypy/branch/import-builtin/lib-python/2.5.2/test/test_runpy.py
Modified:
pypy/branch/import-builtin/lib-python/modified-2.5.2/test/test_import.py
pypy/branch/import-builtin/pypy/module/imp/importing.py
pypy/branch/import-builtin/pypy/module/imp/interp_imp.py
pypy/branch/import-builtin/pypy/module/imp/test/test_import.py
Log:
Do it the other way and have imp.find_module consistent with __import__() and reload();
Skip the relevant tests in Python test suite.
Modified: pypy/branch/import-builtin/lib-python/modified-2.5.2/test/test_import.py
==============================================================================
--- pypy/branch/import-builtin/lib-python/modified-2.5.2/test/test_import.py (original)
+++ pypy/branch/import-builtin/lib-python/modified-2.5.2/test/test_import.py Wed Dec 16 16:27:31 2009
@@ -56,6 +56,11 @@
os.unlink(source)
try:
+ #--- the block below is to check that "reload" manages to import
+ #--- the .pyc file alone. We don't support it in PyPy in the default
+ #--- configuration.
+ return
+
try:
reload(mod)
except ImportError, err:
Copied: pypy/branch/import-builtin/lib-python/modified-2.5.2/test/test_runpy.py (from r70029, pypy/branch/import-builtin/lib-python/2.5.2/test/test_runpy.py)
==============================================================================
--- pypy/branch/import-builtin/lib-python/2.5.2/test/test_runpy.py (original)
+++ pypy/branch/import-builtin/lib-python/modified-2.5.2/test/test_runpy.py Wed Dec 16 16:27:31 2009
@@ -150,6 +150,12 @@
del d1 # Ensure __loader__ entry doesn't keep file open
__import__(mod_name)
os.remove(mod_fname)
+
+ #--- the block below is to check that "imp.find_module"
+ #--- manages to import the .pyc file alone. We don't
+ #--- support it in PyPy in the default configuration.
+ return
+
if verbose: print "Running from compiled:", mod_name
d2 = run_module(mod_name) # Read from bytecode
self.failUnless(d2["x"] == 1)
Modified: pypy/branch/import-builtin/pypy/module/imp/importing.py
==============================================================================
--- pypy/branch/import-builtin/pypy/module/imp/importing.py (original)
+++ pypy/branch/import-builtin/pypy/module/imp/importing.py Wed Dec 16 16:27:31 2009
@@ -25,7 +25,7 @@
# PY_CODERESOURCE = 8
IMP_HOOK = 9
-def find_modtype(space, filepart, force_lonepycfiles=False):
+def find_modtype(space, filepart):
"""Check which kind of module to import for the given filepart,
which is a path without extension. Returns PY_SOURCE, PY_COMPILED or
SEARCH_ERROR.
@@ -40,7 +40,7 @@
# look for a lone .pyc file.
# The "imp" module does not respect this, and is allowed to find
# lone .pyc files.
- if not space.config.objspace.lonepycfiles and not force_lonepycfiles:
+ if not space.config.objspace.lonepycfiles:
return SEARCH_ERROR, None, None
# check the .pyc file
@@ -261,7 +261,7 @@
return FindInfo(IMP_HOOK, '', None, w_loader=w_loader)
def find_module(space, modulename, w_modulename, partname, w_path,
- use_loader=True, force_lonepycfiles=False):
+ use_loader=True):
# Examin importhooks (PEP302) before doing the import
if use_loader:
w_loader = find_in_meta_path(space, w_modulename, w_path)
@@ -292,16 +292,14 @@
filepart = os.path.join(path, partname)
if os.path.isdir(filepart) and case_ok(filepart):
initfile = os.path.join(filepart, '__init__')
- modtype, _, _ = find_modtype(space, initfile,
- force_lonepycfiles)
+ modtype, _, _ = find_modtype(space, initfile)
if modtype in (PY_SOURCE, PY_COMPILED):
return FindInfo(PKG_DIRECTORY, filepart, None)
else:
msg = "Not importing directory " +\
"'%s' missing __init__.py" % (filepart,)
space.warn(msg, space.w_ImportWarning)
- modtype, suffix, filemode = find_modtype(space, filepart,
- force_lonepycfiles)
+ modtype, suffix, filemode = find_modtype(space, filepart)
try:
if modtype in (PY_SOURCE, PY_COMPILED):
filename = filepart + suffix
@@ -449,7 +447,7 @@
return load_module(space, w_modulename, find_info, reuse=True)
except:
# load_module probably removed name from modules because of
- # the error. Put back the original module object.
+ # the error. Put back the original module object.
space.sys.setmodule(w_module)
raise
finally:
Modified: pypy/branch/import-builtin/pypy/module/imp/interp_imp.py
==============================================================================
--- pypy/branch/import-builtin/pypy/module/imp/interp_imp.py (original)
+++ pypy/branch/import-builtin/pypy/module/imp/interp_imp.py Wed Dec 16 16:27:31 2009
@@ -36,9 +36,7 @@
w_path = None
find_info = importing.find_module(
- space, name, w_name, name, w_path,
- use_loader=False,
- force_lonepycfiles=True)
+ space, name, w_name, name, w_path, use_loader=False)
if not find_info:
raise OperationError(
space.w_ImportError,
Modified: pypy/branch/import-builtin/pypy/module/imp/test/test_import.py
==============================================================================
--- pypy/branch/import-builtin/pypy/module/imp/test/test_import.py (original)
+++ pypy/branch/import-builtin/pypy/module/imp/test/test_import.py Wed Dec 16 16:27:31 2009
@@ -883,8 +883,8 @@
m = __import__(mname, globals(), locals(), ["__dummy__"])
m.__loader__ # to make sure we actually handled the import
finally:
- sys.meta_path.pop(0)
- sys.path_hooks.pop(0)
+ sys.meta_path.pop()
+ sys.path_hooks.pop()
class AppTestNoPycFile(object):
usepycfiles = False
@@ -903,9 +903,6 @@
_teardown(cls.space, cls.saved_modules)
def test_import_possibly_from_pyc(self):
- import sys
- assert sys.meta_path == []
- assert sys.path_hooks == []
from compiled import x
if self.usepycfiles:
assert x.__file__.endswith('x.pyc')
More information about the Pypy-commit
mailing list