[pypy-svn] pypy default: Added tests for the new extmodules config option.
tav
commits-noreply at bitbucket.org
Thu Mar 24 21:15:07 CET 2011
Author: tav <tav at espians.com>
Branch:
Changeset: r42913:87c9a7050e13
Date: 2011-03-24 20:12 +0000
http://bitbucket.org/pypy/pypy/changeset/87c9a7050e13/
Log: Added tests for the new extmodules config option.
diff --git a/pypy/interpreter/test/test_extmodules.py b/pypy/interpreter/test/test_extmodules.py
new file mode 100644
--- /dev/null
+++ b/pypy/interpreter/test/test_extmodules.py
@@ -0,0 +1,66 @@
+import sys
+
+from pypy.config.pypyoption import get_pypy_config
+from pypy.objspace.std import StdObjSpace
+from pypy.tool.udir import udir
+
+mod_init = """
+from pypy.interpreter.mixedmodule import MixedModule
+
+import time
+
+class Module(MixedModule):
+
+ appleveldefs = {}
+
+ interpleveldefs = {
+ 'clock' : 'interp_time.clock',
+ 'time' : 'interp_time.time_',
+ 'sleep' : 'interp_time.sleep',
+ }
+"""
+
+mod_interp = """
+import time
+
+from pypy.interpreter.gateway import unwrap_spec
+
+def clock(space):
+ return space.wrap(time.clock())
+
+def time_(space):
+ return space.wrap(time.time())
+
+ at unwrap_spec(seconds=float)
+def sleep(space, seconds):
+ time.sleep(seconds)
+"""
+
+old_sys_path = []
+
+def init_extmodule_code():
+ pkg = udir.join("testext")
+ pkg.ensure(dir=True)
+ pkg.join("__init__.py").write("# package")
+ mod = pkg.join("extmod")
+ mod.ensure(dir=True)
+ mod.join("__init__.py").write(mod_init)
+ mod.join("interp_time.py").write(mod_interp)
+
+class AppTestExtModules(object):
+ def setup_class(cls):
+ init_extmodule_code()
+ conf = get_pypy_config()
+ conf.objspace.extmodules = 'testext.extmod'
+ old_sys_path[:] = sys.path[:]
+ sys.path.insert(0, str(udir))
+ space = StdObjSpace(conf)
+ cls.space = space
+
+ def teardown_class(cls):
+ sys.path[:] = old_sys_path
+
+ def test_import(self):
+ import extmod
+ assert extmod.__file__.endswith('extmod')
+ assert type(extmod.time()) is float
More information about the Pypy-commit
mailing list