Author: Amaury Forgeot d'Arc <[email protected]>
Branch: less-gettestobjspace
Changeset: r58625:607b9abb53a6
Date: 2012-10-29 22:29 +0100
http://bitbucket.org/pypy/pypy/changeset/607b9abb53a6/

Log:    Finlly move gettestobjspace and maketestobjspace to their own file.

diff --git a/pypy/conftest.py b/pypy/conftest.py
--- a/pypy/conftest.py
+++ b/pypy/conftest.py
@@ -3,8 +3,6 @@
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.function import Method
 from pypy.tool.pytest import appsupport
-from pypy.tool.option import make_config, make_objspace
-from pypy.config.config import ConflictConfigError
 from inspect import isclass, getmro
 from pypy.tool.udir import udir
 from pypy.tool.autopath import pypydir
@@ -70,49 +68,10 @@
         pass
 
 def pytest_funcarg__space(request):
+    from pypy.tool.pytest.objspace import gettestobjspace
     spaceconfig = getattr(request.cls, 'spaceconfig', {})
     return gettestobjspace(**spaceconfig)
 
-_SPACECACHE={}
-def gettestobjspace(name=None, **kwds):
-    """ helper for instantiating and caching space's for testing.
-    """
-    try:
-        config = make_config(option, objspace=name, **kwds)
-    except ConflictConfigError, e:
-        # this exception is typically only raised if a module is not available.
-        # in this case the test should be skipped
-        py.test.skip(str(e))
-    key = config.getkey()
-    try:
-        return _SPACECACHE[key]
-    except KeyError:
-        if getattr(option, 'runappdirect', None):
-            if name not in (None, 'std'):
-                myname = getattr(sys, 'pypy_objspaceclass', '')
-                if not myname.lower().startswith(name):
-                    py.test.skip("cannot runappdirect test: "
-                                 "%s objspace required" % (name,))
-            return TinyObjSpace(**kwds)
-        space = maketestobjspace(config)
-        _SPACECACHE[key] = space
-        return space
-
-def maketestobjspace(config=None):
-    if config is None:
-        config = make_config(option)
-    space = make_objspace(config)
-    space.startup() # Initialize all builtin modules
-    space.setitem(space.builtin.w_dict, space.wrap('AssertionError'),
-                  appsupport.build_pytest_assertion(space))
-    space.setitem(space.builtin.w_dict, space.wrap('raises'),
-                  space.wrap(appsupport.app_raises))
-    space.setitem(space.builtin.w_dict, space.wrap('skip'),
-                  space.wrap(appsupport.app_skip))
-    space.raises_w = appsupport.raises_w.__get__(space)
-    space.eq_w = appsupport.eq_w.__get__(space)
-    return space
-
 class TinyObjSpace(object):
     def __init__(self, **kwds):
         import sys
@@ -311,6 +270,7 @@
 
 class LazyObjSpaceGetter(object):
     def __get__(self, obj, cls=None):
+        from pypy.tool.pytest.objspace import gettestobjspace
         space = gettestobjspace()
         if cls:
             cls.space = space
@@ -329,6 +289,7 @@
             # Make cls.space and cls.runappdirect available in tests.
             spaceconfig = getattr(appclass.obj, 'spaceconfig', None)
             if spaceconfig is not None:
+                from pypy.tool.pytest.objspace import gettestobjspace
                 appclass.obj.space = gettestobjspace(**spaceconfig)
             appclass.obj.runappdirect = option.runappdirect
 
@@ -407,6 +368,7 @@
         target = self.obj
         if self.config.option.runappdirect:
             return target()
+        from pypy.tool.pytest.objspace import gettestobjspace
         space = gettestobjspace()
         filename = self._getdynfilename(target)
         func = app2interp_temp(target, filename=filename)
diff --git a/pypy/interpreter/test/test_appinterp.py 
b/pypy/interpreter/test/test_appinterp.py
--- a/pypy/interpreter/test/test_appinterp.py
+++ b/pypy/interpreter/test/test_appinterp.py
@@ -134,7 +134,7 @@
         per-instance attribute, holding a fresh copy of the dictionary.
         """
         from pypy.interpreter.mixedmodule import MixedModule
-        from pypy.conftest import maketestobjspace
+        from pypy.tool.pytest.objspace import maketestobjspace
 
         class MyModule(MixedModule):
             interpleveldefs = {}
@@ -155,6 +155,9 @@
         w_str = space1.getattr(w_mymod1, space1.wrap("hi"))
         assert space1.str_w(w_str) == "hello"
 
+class TestMixedModuleUnfreeze:
+    spaceconfig = dict(usemodules=('_ssl', '_socket'))
+
     def test_random_stuff_can_unfreeze(self):
         # When a module contains an "import" statement in applevel code, the
         # imported module is initialized, possibly after it has been already
@@ -163,11 +166,8 @@
         # This is important when the module startup() function does something
         # at runtime, like setting os.environ (posix module) or initializing
         # the winsock library (_socket module)
-        from pypy.conftest import gettestobjspace
-        space = gettestobjspace(usemodules=('_ssl', '_socket'))
-
-        w_socket = space.builtin_modules['_socket']
-        w_ssl = space.builtin_modules['_ssl']
+        w_socket = self.space.builtin_modules['_socket']
+        w_ssl = self.space.builtin_modules['_ssl']
 
         # Uncomment this line for a workaround
         # space.getattr(w_ssl, space.wrap('SSLError'))
diff --git a/pypy/module/_socket/test/test_sock_app.py 
b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -1,6 +1,6 @@
-from pypy.conftest import gettestobjspace
 import sys
 import py
+from pypy.tool.pytest.objspace import gettestobjspace
 from pypy.tool.udir import udir
 from pypy.rlib import rsocket
 from pypy.rpython.lltypesystem import lltype, rffi
diff --git a/pypy/module/cpyext/presetup.py b/pypy/module/cpyext/presetup.py
--- a/pypy/module/cpyext/presetup.py
+++ b/pypy/module/cpyext/presetup.py
@@ -19,7 +19,7 @@
 sys.path.insert(0, os.getcwd())
 from distutils import sysconfig
 
-from pypy.conftest import gettestobjspace
+from pypy.tool.pytest.objspace import gettestobjspace
 from pypy.module.cpyext.api import build_bridge
 from pypy.module.imp.importing import get_so_extension
 
diff --git a/pypy/module/posix/test/test_posix2.py 
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -4,7 +4,7 @@
 from __future__ import with_statement
 from pypy.objspace.std import StdObjSpace
 from pypy.tool.udir import udir
-from pypy.conftest import gettestobjspace
+from pypy.tool.pytest.objspace import gettestobjspace
 from pypy.tool.autopath import pypydir
 from pypy.rpython.module.ll_os import RegisterOs
 import os
@@ -38,7 +38,7 @@
     os.stat_float_times(True)
 
     # Initialize sys.filesystemencoding
-    space.call_method(space.getbuiltinmodule('sys'), 'getfilesystemencoding')
+    # space.call_method(space.getbuiltinmodule('sys'), 'getfilesystemencoding')
 
 def need_sparse_files():
     if sys.platform == 'darwin':
@@ -1008,7 +1008,7 @@
     def setup_class(cls):
         cls.space = space
         cls.w_posix = space.appexec([], GET_POSIX)
-        if py.test.config.option.runappdirect:
+        if cls.runappdirect:
             # Can't change encoding
             try:
                 u"&#261;".encode(sys.getfilesystemencoding())
diff --git a/pypy/objspace/std/test/test_smalllongobject.py 
b/pypy/objspace/std/test/test_smalllongobject.py
--- a/pypy/objspace/std/test/test_smalllongobject.py
+++ b/pypy/objspace/std/test/test_smalllongobject.py
@@ -2,7 +2,7 @@
 import sys
 from pypy.objspace.std.smalllongobject import W_SmallLongObject
 from pypy.objspace.std.test import test_longobject
-from pypy.conftest import gettestobjspace
+from pypy.tool.pytest.objspace import gettestobjspace
 from pypy.rlib.rarithmetic import r_longlong
 from pypy.interpreter.error import OperationError
 
diff --git a/pypy/objspace/std/test/test_smalltupleobject.py 
b/pypy/objspace/std/test/test_smalltupleobject.py
--- a/pypy/objspace/std/test/test_smalltupleobject.py
+++ b/pypy/objspace/std/test/test_smalltupleobject.py
@@ -2,7 +2,7 @@
 from pypy.objspace.std.smalltupleobject import W_SmallTupleObject
 from pypy.interpreter.error import OperationError
 from pypy.objspace.std.test.test_tupleobject import AppTestW_TupleObject
-from pypy.conftest import gettestobjspace
+from pypy.tool.pytest.objspace import gettestobjspace
 
 class AppTestW_SmallTupleObject(AppTestW_TupleObject):
     spaceconfig = {"objspace.std.withsmalltuple": True}
diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py 
b/pypy/objspace/std/test/test_specialisedtupleobject.py
--- a/pypy/objspace/std/test/test_specialisedtupleobject.py
+++ b/pypy/objspace/std/test/test_specialisedtupleobject.py
@@ -3,7 +3,7 @@
 from pypy.objspace.std.specialisedtupleobject import W_SpecialisedTupleObject
 from pypy.objspace.std.specialisedtupleobject import _specialisations
 from pypy.interpreter.error import OperationError
-from pypy.conftest import gettestobjspace
+from pypy.tool.pytest.objspace import gettestobjspace
 from pypy.objspace.std.test import test_tupleobject
 from pypy.interpreter import gateway
 
diff --git a/pypy/objspace/std/test/test_stdobjspace.py 
b/pypy/objspace/std/test/test_stdobjspace.py
--- a/pypy/objspace/std/test/test_stdobjspace.py
+++ b/pypy/objspace/std/test/test_stdobjspace.py
@@ -1,6 +1,6 @@
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.gateway import app2interp
-from pypy.conftest import gettestobjspace
+from pypy.tool.pytest.objspace import gettestobjspace
 
 class TestW_StdObjSpace:
 
diff --git a/pypy/objspace/test/test_thunkobjspace.py 
b/pypy/objspace/test/test_thunkobjspace.py
--- a/pypy/objspace/test/test_thunkobjspace.py
+++ b/pypy/objspace/test/test_thunkobjspace.py
@@ -1,4 +1,4 @@
-from pypy.conftest import gettestobjspace
+from pypy.tool.pytest.objspace import gettestobjspace
 from pypy.interpreter import gateway
 
 class AppTest_Thunk:
diff --git a/pypy/tool/pytest/objspace.py b/pypy/tool/pytest/objspace.py
new file mode 100644
--- /dev/null
+++ b/pypy/tool/pytest/objspace.py
@@ -0,0 +1,46 @@
+import py
+from pypy.config.config import ConflictConfigError
+from pypy.tool.option import make_config, make_objspace
+from pypy.tool.pytest import appsupport
+from pypy.conftest import option
+
+_SPACECACHE={}
+def gettestobjspace(name=None, **kwds):
+    """ helper for instantiating and caching space's for testing.
+    """
+    try:
+        config = make_config(option, objspace=name, **kwds)
+    except ConflictConfigError, e:
+        # this exception is typically only raised if a module is not available.
+        # in this case the test should be skipped
+        py.test.skip(str(e))
+    key = config.getkey()
+    try:
+        return _SPACECACHE[key]
+    except KeyError:
+        if getattr(option, 'runappdirect', None):
+            if name not in (None, 'std'):
+                myname = getattr(sys, 'pypy_objspaceclass', '')
+                if not myname.lower().startswith(name):
+                    py.test.skip("cannot runappdirect test: "
+                                 "%s objspace required" % (name,))
+            return TinyObjSpace(**kwds)
+        space = maketestobjspace(config)
+        _SPACECACHE[key] = space
+        return space
+
+def maketestobjspace(config=None):
+    if config is None:
+        config = make_config(option)
+    space = make_objspace(config)
+    space.startup() # Initialize all builtin modules
+    space.setitem(space.builtin.w_dict, space.wrap('AssertionError'),
+                  appsupport.build_pytest_assertion(space))
+    space.setitem(space.builtin.w_dict, space.wrap('raises'),
+                  space.wrap(appsupport.app_raises))
+    space.setitem(space.builtin.w_dict, space.wrap('skip'),
+                  space.wrap(appsupport.app_skip))
+    space.raises_w = appsupport.raises_w.__get__(space)
+    space.eq_w = appsupport.eq_w.__get__(space)
+    return space
+
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to