[pypy-svn] r10387 - in pypy/branch/pycollect-dist-pypy: . pypy pypy/lib/test2 pypy/module/_sre_pypy pypy/tool pypy/translator/test

hpk at codespeak.net hpk at codespeak.net
Thu Apr 7 01:06:26 CEST 2005


Author: hpk
Date: Thu Apr  7 01:06:25 2005
New Revision: 10387

Added:
   pypy/branch/pycollect-dist-pypy/   (props changed)
      - copied from r10386, pypy/dist/
Modified:
   pypy/branch/pycollect-dist-pypy/pypy/conftest.py
   pypy/branch/pycollect-dist-pypy/pypy/lib/test2/conftest.py
   pypy/branch/pycollect-dist-pypy/pypy/lib/test2/support_tests.py
   pypy/branch/pycollect-dist-pypy/pypy/module/_sre_pypy/interpreter_code.py
   pypy/branch/pycollect-dist-pypy/pypy/tool/pytestsupport.py
   pypy/branch/pycollect-dist-pypy/pypy/translator/test/test_pyrextrans.py
Log:
create a modified branch which interfaces 
with an ongoing py.test refactoring (called
the py collect branch because it targets 
a redesign of the test collection process). 

There remain a few problems and one major 
issue (regarding 'from pypy.conftest import ...' 
to work as expected).  This probably requires 
tackling import issues. funfunfun. 



Modified: pypy/branch/pycollect-dist-pypy/pypy/conftest.py
==============================================================================
--- pypy/dist/pypy/conftest.py	(original)
+++ pypy/branch/pycollect-dist-pypy/pypy/conftest.py	Thu Apr  7 01:06:25 2005
@@ -2,6 +2,7 @@
 from pypy.interpreter.gateway import app2interp_temp 
 from pypy.interpreter.error import OperationError
 from pypy.tool import pytestsupport
+from inspect import isclass
 
 rootdir = py.magic.autopath().dirpath()
 
@@ -10,7 +11,12 @@
 # to py.test's standard options) 
 #
 Option = py.test.Option
-options = ('pypy options', [
+
+#class Options: 
+#    group = "pypy options" 
+#    optionlist = 
+
+option = py.test.addoptions("pypy options", 
         Option('-o', '--objspace', action="store", default=None, 
                type="string", dest="objspacename", 
                help="object space to run tests on."),
@@ -18,17 +24,17 @@
                help="enable oldstyle classes as default metaclass (std objspace only)"),
         Option('--allpypy', action="store_true",dest="allpypy", default=False, 
                help="run everything possible on top of PyPy."),
-])
+    )
 
 def getobjspace(name=None, _spacecache={}): 
     """ helper for instantiating and caching space's for testing. 
     """ 
     if name is None: 
-        name = py.test.config.option.objspacename  
+        name = option.objspacename 
         if name is None:
             name = py.std.os.environ.get('OBJSPACE', 'std')
     else:
-        optionname = py.test.config.option.objspacename
+        optionname = option.objspacename 
         if optionname is not None and optionname != name:
             return None
     try:
@@ -38,7 +44,7 @@
         module = __import__("pypy.objspace.%s" % name, None, None, ["Space"])
         space = module.Space()
         _spacecache[name] = space
-        if name == 'std' and py.test.config.option.oldstyle:
+        if name == 'std' and option.oldstyle: 
             space.enable_old_style_classes_as_default_metaclass()
         if name != 'flow': # not sensible for flow objspace case
             space.setitem(space.builtin.w_dict, space.wrap('AssertionError'), 
@@ -60,26 +66,34 @@
         and at interp-level (because we need to stick a space 
         at the class) ourselves. 
     """
-    def collect_function(self, extpy): 
-        if extpy.check(func=1, basestarts='test_'):
-            if extpy.check(genfunc=1): 
-                yield IntTestGenerator(extpy) 
-            else: 
-                yield IntTestFunction(extpy)
+    def funcnamefilter(self, name): 
+        return name.startswith('test_') or name.startswith('app_test_')
+    def classnamefilter(self, name): 
+        return name.startswith('Test') or name.startswith('AppTest') 
 
-    def collect_app_function(self, extpy): 
-        if extpy.check(func=1, basestarts='app_test_'):
-            assert not extpy.check(genfunc=1), (
-                "generator app level functions? you must be joking")
-            yield AppTestFunction(extpy)
-            
-    def collect_class(self, extpy): 
-        if extpy.check(class_=1, basestarts="Test"): 
-            yield IntClassCollector(extpy) 
-
-    def collect_appclass(self, extpy): 
-        if extpy.check(class_=1, basestarts="AppTest"): 
-            yield AppClassCollector(extpy) 
+    def setup(self): 
+        # stick py.test raise in module globals
+        self.obj.raises = py.test.raises 
+        super(Module, self).setup() 
+        #    if hasattr(mod, 'objspacename'): 
+        #        mod.space = getttestobjspace(mod.objspacename)
+
+    def join(self, name): 
+        obj = getattr(self.obj, name) 
+        if isclass(obj): 
+            if name.startswith('AppTest'): 
+                return AppClassCollector(name, parent=self) 
+            else: 
+                return IntClassCollector(name, parent=self) 
+        elif hasattr(obj, 'func_code'): 
+            if name.startswith('app_test_'): 
+                assert not obj.func_code.co_flags & 32, \
+                    "generator app level functions? you must be joking" 
+                return AppTestFunction(name, parent=self) 
+            elif obj.func_code.co_flags & 32: # generator function 
+                return self.Generator(name, parent=self) 
+            else: 
+                return IntTestFunction(name, parent=self) 
 
 def gettestobjspace(name=None):
     space = getobjspace(name)
@@ -88,33 +102,21 @@
     return space
 
 
-class PyPyItem(py.test.Item):
+class PyPyTestFunction(py.test.Function):
     # All PyPy test items catch and display OperationErrors specially.
 
-    def setup_module(self, mod): 
-    #    if hasattr(mod, 'objspacename'): 
-    #        mod.space = getttestobjspace(mod.objspacename)
-        # stick py.test raise in module globals
-        mod.raises = py.test.raises
-        super(PyPyItem, self).setup_module(mod) 
-
-    def setup_class(self, cls): 
-        name = getattr(cls, 'objspacename', None) 
-        if name is None: 
-            m = __import__(cls.__module__, {}, {}, ["objspacename"])
-            name = getattr(m, 'objspacename', None) 
-        cls.space = gettestobjspace(name) 
-        super(PyPyItem, self).setup_class(cls) 
-
     def execute_appex(self, space, target, *args):
         try:
             target(*args)
         except OperationError, e:
             if e.match(space, space.w_KeyboardInterrupt): 
                 raise KeyboardInterrupt 
-            raise self.Failed(excinfo=pytestsupport.AppExceptionInfo(space, e))
+            appexcinfo = pytestsupport.AppExceptionInfo(space, e) 
+            if appexcinfo.traceback: 
+                raise self.Failed(excinfo=pytestsupport.AppExceptionInfo(space, e))
+            raise 
 
-class IntTestFunction(PyPyItem):
+class IntTestFunction(PyPyTestFunction):
     def execute(self, target, *args):
         co = target.func_code
         if 'space' in co.co_varnames[:co.co_argcount]: 
@@ -124,29 +126,37 @@
         else:
             target(*args)
 
-class IntTestMethod(PyPyItem): 
-    def execute(self, target, *args):
-        target(*args) 
-
-class AppTestFunction(PyPyItem): 
+class AppTestFunction(PyPyTestFunction): 
     def execute(self, target, *args):
         assert not args 
         name = target.func_globals.get('objspacename', None) 
         space = gettestobjspace(name) 
         func = app2interp_temp(target)
+        print "executing", func
         self.execute_appex(space, func, space)
 
-
-class AppTestMethod(PyPyItem): 
+class AppTestMethod(PyPyTestFunction): 
     def execute(self, target, *args): 
         assert not args 
         space = target.im_self.space 
         func = app2interp_temp(target.im_func) 
         self.execute_appex(space, func, space, space.w_None)
 
-class AppClassCollector(py.test.collect.Class): 
-    Item = AppTestMethod 
-
 class IntClassCollector(py.test.collect.Class): 
-    Item = IntTestMethod 
-    
+    Function = IntTestFunction 
+
+    def setup(self): 
+        cls = self.obj 
+        name = getattr(cls, 'objspacename', None) 
+        if name is None: 
+            m = __import__(cls.__module__, {}, {}, ["objspacename"])
+            name = getattr(m, 'objspacename', None) 
+        cls.space = gettestobjspace(name) 
+        super(IntClassCollector, self).setup() 
+
+class AppClassInstance(py.test.collect.Instance): 
+    Function = AppTestMethod 
+
+class AppClassCollector(IntClassCollector): 
+    Instance = AppClassInstance 
+

Modified: pypy/branch/pycollect-dist-pypy/pypy/lib/test2/conftest.py
==============================================================================
--- pypy/dist/pypy/lib/test2/conftest.py	(original)
+++ pypy/branch/pycollect-dist-pypy/pypy/lib/test2/conftest.py	Thu Apr  7 01:06:25 2005
@@ -2,7 +2,7 @@
 import sys
 import py
 import pypy
-from pypy.conftest import gettestobjspace 
+from pypy.conftest import gettestobjspace, option
 
 ModuleType = type(sys)
 
@@ -25,7 +25,7 @@
 conftest.__file__ = str(conftest.__file__)  # keep out the py's importhook 
 
 def Module(fspath): 
-    if py.test.config.option.allpypy: 
+    if option.allpypy: 
         return conftest.Module(fspath) 
     return UnittestModuleOnCPython(fspath) 
 

Modified: pypy/branch/pycollect-dist-pypy/pypy/lib/test2/support_tests.py
==============================================================================
--- pypy/dist/pypy/lib/test2/support_tests.py	(original)
+++ pypy/branch/pycollect-dist-pypy/pypy/lib/test2/support_tests.py	Thu Apr  7 01:06:25 2005
@@ -12,7 +12,7 @@
     tmpdir = sys.pypy_getudir()
 except AttributeError:
     import py 
-    tmpdir = str(py.test.config.tmpdir)
+    tmpdir = str(py.test.ensuretemp('support_tests_tempdir'))
 TESTFN = os.path.join(tmpdir, '@test')
 
 class Error(Exception):

Modified: pypy/branch/pycollect-dist-pypy/pypy/module/_sre_pypy/interpreter_code.py
==============================================================================
--- pypy/dist/pypy/module/_sre_pypy/interpreter_code.py	(original)
+++ pypy/branch/pycollect-dist-pypy/pypy/module/_sre_pypy/interpreter_code.py	Thu Apr  7 01:06:25 2005
@@ -104,6 +104,7 @@
 
 def _SRE_Pattern_match(space, w_wrapped, pattern, pos, endpos):
     wrapped = space.interpclass_w(w_wrapped).value
+    print pattern, pos, endpos 
     match_obj = wrapped.match(pattern, pos, endpos)
     if match_obj is None:
         return space.w_None

Modified: pypy/branch/pycollect-dist-pypy/pypy/tool/pytestsupport.py
==============================================================================
--- pypy/dist/pypy/tool/pytestsupport.py	(original)
+++ pypy/branch/pycollect-dist-pypy/pypy/tool/pytestsupport.py	Thu Apr  7 01:06:25 2005
@@ -4,7 +4,10 @@
 from py.__impl__.magic import exprinfo
 from pypy.interpreter import gateway
 from pypy.interpreter.error import OperationError
+import pypy
 
+optionpath = py.path.extpy(py.path.local(pypy.__file__).dirpath('conftest.py'), 
+                       'option') 
 # ____________________________________________________________
 
 class AppFrame(py.code.Frame):
@@ -99,7 +102,7 @@
                 source = str(source).strip()
             except py.error.ENOENT: 
                 source = None
-            if source and not py.test.config.option.nomagic:
+            if source and not optionpath.resolve().nomagic: 
                 msg = exprinfo.interpret(source, runner, should_fail=True)
                 space.setattr(w_self, space.wrap('args'),
                             space.newtuple([space.wrap(msg)]))

Modified: pypy/branch/pycollect-dist-pypy/pypy/translator/test/test_pyrextrans.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_pyrextrans.py	(original)
+++ pypy/branch/pycollect-dist-pypy/pypy/translator/test/test_pyrextrans.py	Thu Apr  7 01:06:25 2005
@@ -7,6 +7,11 @@
 from pypy.translator.tool.buildpyxmodule import skip_missing_compiler
 from pypy.translator.translator import Translator
 
+import pypy, py
+optionpath = py.path.extpy(py.path.local(pypy.__file__).dirpath('conftest.py'), 
+                  'option') 
+#from pypy.conftest import option
+
 from pypy.translator.test import snippet 
 
 # XXX this tries to make compiling faster for full-scale testing
@@ -21,7 +26,7 @@
         try: func = func.im_func
         except AttributeError: pass
 
-        dot = py.test.config.option.verbose >0 and 1 or 0
+        dot = optionpath.resolve().verbose > 0 and 1 or 0 
         options = {
             'simplify' : 1,
             'dot' : dot,



More information about the Pypy-commit mailing list