[pypy-svn] r17098 - in pypy/dist/pypy: . module/thread/test

arigo at codespeak.net arigo at codespeak.net
Tue Aug 30 20:02:57 CEST 2005


Author: arigo
Date: Tue Aug 30 20:02:54 2005
New Revision: 17098

Modified:
   pypy/dist/pypy/conftest.py
   pypy/dist/pypy/module/thread/test/support.py
Log:
Some tentative clean-ups of conftest.py w.r.t. object space creation and
caching.  Now the gettestobjspace() function takes an optional name
'std'/'thunk' as before, but also keyword options to pass to the space. The
result is cached.

As far as I can tell there was already no difference left between
getobjspace() and gettestobjspace().

For interp-level test classes, 'cls.space' attribute is now lazily computed
the first time the attribute is actually accessed.  This is cool when working
on parts of PyPy that don't need an object space around, or that only need a
custom one (e.g. with a usemodules keyword).



Modified: pypy/dist/pypy/conftest.py
==============================================================================
--- pypy/dist/pypy/conftest.py	(original)
+++ pypy/dist/pypy/conftest.py	Tue Aug 30 20:02:54 2005
@@ -38,22 +38,26 @@
                help="(mixed) modules to use."),
     )
 
-def getobjspace(name=None, _spacecache={}): 
+_SPACECACHE={}
+def getobjspace(name=None, **kwds): 
     """ helper for instantiating and caching space's for testing. 
     """ 
-    name = name or option.objspace or 'std' 
+    name = name or option.objspace or 'std'
+    key = kwds.items()
+    key.sort()
+    key = name, tuple(key)
     try:
-        return _spacecache[name]
+        return _SPACECACHE[key]
     except KeyError:
         assert name in ('std', 'thunk'), name 
         mod = __import__('pypy.objspace.%s' % name, None, None, ['Space'])
         Space = mod.Space
         try: 
-            space = Space(uselibfile=option.uselibfile, 
-                          nofaking=option.nofaking, 
-                          oldstyle=option.oldstyle,
-                          usemodules=option.usemodules
-                          )
+            kwds.setdefault('uselibfile', option.uselibfile)
+            kwds.setdefault('nofaking', option.nofaking)
+            kwds.setdefault('oldstyle', option.oldstyle)
+            kwds.setdefault('usemodules', option.usemodules)
+            space = Space(**kwds)
         except KeyboardInterrupt: 
             raise 
         except OperationError, e: 
@@ -68,7 +72,7 @@
                 import traceback 
                 traceback.print_exc() 
             py.test.fail("fatal: cannot initialize objspace:  %r" %(Space,))
-        _spacecache[name] = space
+        _SPACECACHE[key] = space
         space.setitem(space.builtin.w_dict, space.wrap('AssertionError'), 
                       appsupport.build_pytest_assertion(space))
         space.setitem(space.builtin.w_dict, space.wrap('raises'),
@@ -117,12 +121,19 @@
             else: 
                 return IntTestFunction(name, parent=self) 
 
-def gettestobjspace(name=None):
-    space = getobjspace(name)
-    if space is None:
-        py.test.skip('test requires object space %r' % (name,))
+def gettestobjspace(name=None, **kwds):
+    space = getobjspace(name, **kwds)
+    #if space is None:   XXX getobjspace() cannot return None any more I think
+    #    py.test.skip('test requires object space %r' % (name,))
     return space
 
+class LazyObjSpaceGetter(object):
+    def __get__(self, obj, cls=None):
+        space = gettestobjspace()
+        if cls:
+            cls.space = space
+        return space
+
 
 class PyPyTestFunction(py.test.Function):
     # All PyPy test items catch and display OperationErrors specially.
@@ -187,7 +198,7 @@
 
     def setup(self): 
         cls = self.obj 
-        cls.space = gettestobjspace() 
+        cls.space = LazyObjSpaceGetter()
         super(IntClassCollector, self).setup() 
 
 class AppClassInstance(py.test.collect.Instance): 

Modified: pypy/dist/pypy/module/thread/test/support.py
==============================================================================
--- pypy/dist/pypy/module/thread/test/support.py	(original)
+++ pypy/dist/pypy/module/thread/test/support.py	Tue Aug 30 20:02:54 2005
@@ -1,11 +1,11 @@
 import py
+from pypy.conftest import gettestobjspace
 
 class GenericTestThread:
 
     def setup_class(cls):
-        space = cls.space
-        if "thread" not in space.options.usemodules:
-            py.test.skip("--usemodules=thread option not provided")
+        space = gettestobjspace(usemodules=('thread',))
+        cls.space = space
 
         cls.w_waitfor = space.appexec([], """():
             import time



More information about the Pypy-commit mailing list