Author: Antonio Cuni <[email protected]>
Branch: dummy-importlib
Changeset: r98332:c37f7da0a5ee
Date: 2019-12-19 11:23 +0100
http://bitbucket.org/pypy/pypy/changeset/c37f7da0a5ee/
Log: make it possible to use __import__ directly, and use a dummy package
to run tests instead of trying to import more expensive ones
diff --git a/pypy/module/_dummy_importlib/interp_import.py
b/pypy/module/_dummy_importlib/interp_import.py
--- a/pypy/module/_dummy_importlib/interp_import.py
+++ b/pypy/module/_dummy_importlib/interp_import.py
@@ -6,7 +6,7 @@
@unwrap_spec(name='text0', level=int)
def importhook(space, name, w_globals=None,
- w_locals=None, w_fromlist=None, level=-1):
+ w_locals=None, w_fromlist=None, level=0):
"""
NOT_RPYTHON
diff --git a/pypy/module/_dummy_importlib/test/dummypkg/__init__.py
b/pypy/module/_dummy_importlib/test/dummypkg/__init__.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_dummy_importlib/test/dummypkg/__init__.py
@@ -0,0 +1,1 @@
+FOO = 42
diff --git a/pypy/module/_dummy_importlib/test/dummypkg/mod.py
b/pypy/module/_dummy_importlib/test/dummypkg/mod.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_dummy_importlib/test/dummypkg/mod.py
@@ -0,0 +1,1 @@
+BAR = 43
diff --git a/pypy/module/_dummy_importlib/test/test__dummy_importlib.py
b/pypy/module/_dummy_importlib/test/test__dummy_importlib.py
--- a/pypy/module/_dummy_importlib/test/test__dummy_importlib.py
+++ b/pypy/module/_dummy_importlib/test/test__dummy_importlib.py
@@ -1,5 +1,9 @@
+import py
from pypy.tool.pytest.objspace import gettestobjspace
+THISDIR = py.path.local(__file__).dirpath()
+
+
def test_default_is_dummy_importlib():
space = gettestobjspace()
assert space.config.objspace.usemodules._dummy_importlib
@@ -12,14 +16,36 @@
class AppTestDummyImportlib:
+ def setup_method(self, meth):
+ space = self.space
+ self.w_thisidr = space.newtext(str(THISDIR))
+ space.appexec([self.w_thisidr], """(dir):
+ import sys
+ sys.path.append(dir)
+ """)
+
+
+ def teardown_method(self, meth):
+ space = self.space
+ space.appexec([self.w_thisidr], """(dir):
+ import sys
+ if dir in sys.path:
+ sys.path.remove(dir)
+ """)
+
def test_import_builtin(self):
import sys
assert sys.__name__ == 'sys'
+ def test___import__(self):
+ import sys
+ sys2 = __import__('sys')
+ assert sys is sys2
+
def test_import_lib_pypy(self):
import _structseq
assert hasattr(_structseq, 'structseq_new')
def test_import_package(self):
- import collections
- assert hasattr(collections, 'namedtuple')
+ import dummypkg
+ assert dummypkg.FOO == 42
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit