[pypy-svn] r11788 - in pypy/dist: lib-python pypy pypy/interpreter pypy/tool pypy/tool/pytest pypy/tool/test

hpk at codespeak.net hpk at codespeak.net
Mon May 2 17:22:30 CEST 2005


Author: hpk
Date: Mon May  2 17:22:30 2005
New Revision: 11788

Added:
   pypy/dist/pypy/tool/pytest/   (props changed)
   pypy/dist/pypy/tool/pytest/__init__.py
      - copied unchanged from r11784, pypy/dist/pypy/tool/__init__.py
   pypy/dist/pypy/tool/pytest/appsupport.py
      - copied unchanged from r11784, pypy/dist/pypy/tool/pytestsupport.py
   pypy/dist/pypy/tool/pytest/autopath.py
      - copied unchanged from r11784, pypy/dist/pypy/tool/autopath.py
   pypy/dist/pypy/tool/pytest/confpath.py
   pypy/dist/pypy/tool/pytest/genreportdata.py   (contents, props changed)
      - copied, changed from r11783, pypy/testresult/genreportdata.py
   pypy/dist/pypy/tool/pytest/htmlreport.py   (contents, props changed)
      - copied, changed from r11786, pypy/testresult/htmlreport.py
   pypy/dist/pypy/tool/pytest/result.py   (props changed)
      - copied unchanged from r11785, pypy/dist/lib-python/result.py
Removed:
   pypy/dist/lib-python/result.py
   pypy/dist/pypy/tool/pytestsupport.py
Modified:
   pypy/dist/lib-python/conftest.py
   pypy/dist/pypy/conftest.py
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/tool/alarm.py   (props changed)
   pypy/dist/pypy/tool/compile.py   (props changed)
   pypy/dist/pypy/tool/pypyrev.py   (props changed)
   pypy/dist/pypy/tool/test/test_pytestsupport.py
   pypy/dist/pypy/tool/tls.py   (props changed)
Log:
refactor all test-help code including html generation 
into pypy/tool/pytest 



Modified: pypy/dist/lib-python/conftest.py
==============================================================================
--- pypy/dist/lib-python/conftest.py	(original)
+++ pypy/dist/lib-python/conftest.py	Mon May  2 17:22:30 2005
@@ -19,14 +19,9 @@
 from test.regrtest import reportdiff
 from test import pystone
 
-pypydir = py.path.local(pypy.__file__).dirpath()
-libpythondir = pypydir.dirpath('lib-python')
-testdir = libpythondir.join('2.3.4', 'test') 
-modtestdir = libpythondir.join('modified-2.3.4', 'test') 
-
-result = libpythondir.join('result.py').pyimport('result')
-from result import Result, ResultFromMime
-
+from pypy.tool.pytest.confpath import pypydir, libpythondir, \
+                                      regrtestdir, modregrtestdir, testresultdir
+from pypy.tool.pytest.result import Result, ResultFromMime
 
 # 
 # Interfacing/Integrating with py.test's collection process 
@@ -303,17 +298,17 @@
         return l 
 
     def ismodified(self): 
-        return modtestdir.join(self.basename).check() 
+        return modregrtestdir.join(self.basename).check() 
 
     def getfspath(self): 
-        fn = modtestdir.join(self.basename)
+        fn = modregrtestdir.join(self.basename)
         if fn.check(): 
             return fn 
-        fn = testdir.join(self.basename)
+        fn = regrtestdir.join(self.basename)
         return fn 
 
     def getoutputpath(self): 
-        p = testdir.join('output', self.basename).new(ext='')
+        p = regrtestdir.join('output', self.basename).new(ext='')
         if p.check(file=1): 
             return p 
 
@@ -772,7 +767,6 @@
 
 
 def ensuretestresultdir(): 
-    testresultdir = pypydir.dirpath('testresult')
     if not testresultdir.check(dir=1): 
         py.test.skip("""'testresult' directory not found.
         To run tests in reporting mode (without -E), you first have to

Deleted: /pypy/dist/lib-python/result.py
==============================================================================
--- /pypy/dist/lib-python/result.py	Mon May  2 17:22:30 2005
+++ (empty file)
@@ -1,129 +0,0 @@
-import sys 
-import py
-
-class Result(object): 
-    def __init__(self, init=True): 
-        self._headers = {}
-        self._blocks = {}
-        self._blocknames = []
-        if init: 
-            stdinit(self) 
-
-    def __setitem__(self, name, value): 
-        self._headers[name.lower()] = value 
-
-    def __getitem__(self, name): 
-        return self._headers[name.lower()]
-
-    def get(self, name, default): 
-        return self._headers.get(name, default) 
-    
-    def __delitem__(self, name): 
-        del self._headers[name.lower()]
-
-    def items(self): 
-        return self._headers.items()
-
-    def addnamedtext(self, name, text): 
-        assert isinstance(text, str)
-        assert isinstance(name, str)
-        self._blocknames.append(name) 
-        self._blocks[name] = text 
-
-    def getnamedtext(self, name): 
-        return self._blocks[name]
-
-    def repr_short_error(self): 
-        if not self.isok(): 
-            text = self.getnamedtext('stderr') 
-            lines = text.strip().split('\n')
-            if lines: 
-                return lines[-1]
-
-    def repr_mimemessage(self): 
-        from email.MIMEMultipart  import MIMEMultipart 
-        from email.MIMEText  import MIMEText
-        
-        outer = MIMEMultipart()
-        items = self._headers.items()
-        items.sort()
-        reprs = {}
-        for name, value in items: 
-            outer[name] = str(value) 
-            if not isinstance(value, str): 
-                typename = type(value).__name__ 
-                assert typename in vars(py.std.__builtin__)
-                reprs[name] = typename 
-
-        outer['_reprs'] = repr(reprs) 
-    
-        for name in self._blocknames: 
-            text = self._blocks[name]
-            m = MIMEText(text)
-            m.add_header('Content-Disposition', 'attachment', filename=name)
-            outer.attach(m) 
-        return outer 
-
-    def isok(self): 
-        return self['outcome'].lower() == 'ok'
-    def iserr(self): 
-        return self['outcome'].lower()[:3] == 'err'
-    def istimeout(self): 
-        return self['outcome'].lower() == 't/o'
-
-class ResultFromMime(Result): 
-    def __init__(self, path): 
-        super(ResultFromMime, self).__init__(init=False) 
-        f = open(str(path), 'r') 
-        from email import message_from_file 
-        msg = message_from_file(f)
-        # XXX security wise evil (keep in mind once we accept reporsts
-        # from anonymous
-        #print msg['_reprs']
-        self._reprs = eval(msg['_reprs']) 
-        del msg['_reprs']
-        for name, value in msg.items(): 
-            if name in self._reprs: 
-                value = eval(value)  # XXX security
-            self._headers[name] = value 
-        self.fspath = py.path.local(self['fspath']) 
-        self.path = path 
-    
-        payload = msg.get_payload() 
-        if payload: 
-           for submsg in payload: 
-                assert submsg.get_main_type() == 'text'
-                fn = submsg.get_filename() 
-                assert fn
-                self.addnamedtext(fn, submsg.get_payload())
-
-def stdinit(result): 
-    import getpass
-    import socket
-    try:
-        username = getpass.getuser()
-    except:
-        username = 'unknown'
-    userhost = '%s@%s' % (username, socket.gethostname())
-    result['testreport-version'] = "1.1" 
-    result['userhost'] = userhost 
-    result['platform'] = sys.platform 
-    result['python-version-info'] = sys.version_info 
-    info = try_getcpuinfo() 
-    if info is not None:
-        result['cpu model'] = info['model name']
-        result['cpu mhz'] = info['cpu mhz']
-#
-#
-#
-def try_getcpuinfo(): 
-    if sys.platform.startswith('linux'): 
-        cpuinfopath = py.path.local('/proc/cpuinfo')
-        if cpuinfopath.check(file=1): 
-            d = {}
-            for line in cpuinfopath.readlines(): 
-                if line.strip(): 
-                   name, value = line.split(':', 1)
-                   name = name.strip().lower()
-                   d[name] = value.strip()
-            return d 

Modified: pypy/dist/pypy/conftest.py
==============================================================================
--- pypy/dist/pypy/conftest.py	(original)
+++ pypy/dist/pypy/conftest.py	Mon May  2 17:22:30 2005
@@ -1,7 +1,7 @@
 import py
 from pypy.interpreter.gateway import app2interp_temp 
 from pypy.interpreter.error import OperationError
-from pypy.tool import pytestsupport
+from pypy.tool.pytest import appsupport 
 from inspect import isclass
 
 rootdir = py.magic.autopath().dirpath()
@@ -70,13 +70,13 @@
             ''')
         if name != 'flow': # not sensible for flow objspace case
             space.setitem(space.builtin.w_dict, space.wrap('AssertionError'), 
-                          pytestsupport.build_pytest_assertion(space))
+                          appsupport.build_pytest_assertion(space))
             space.setitem(space.builtin.w_dict, space.wrap('raises'),
-                          space.wrap(pytestsupport.app_raises))
+                          space.wrap(appsupport.app_raises))
             space.setitem(space.builtin.w_dict, space.wrap('skip'),
-                          space.wrap(pytestsupport.app_skip))
-            space.raises_w = pytestsupport.raises_w.__get__(space)
-            space.eq_w = pytestsupport.eq_w.__get__(space) 
+                          space.wrap(appsupport.app_skip))
+            space.raises_w = appsupport.raises_w.__get__(space)
+            space.eq_w = appsupport.eq_w.__get__(space) 
         return space
 
 # 
@@ -133,9 +133,9 @@
         except OperationError, e:
             if e.match(space, space.w_KeyboardInterrupt): 
                 raise KeyboardInterrupt 
-            appexcinfo = pytestsupport.AppExceptionInfo(space, e) 
+            appexcinfo = appsupport.AppExceptionInfo(space, e) 
             if appexcinfo.traceback: 
-                raise self.Failed(excinfo=pytestsupport.AppExceptionInfo(space, e))
+                raise self.Failed(excinfo=appsupport.AppExceptionInfo(space, e))
             raise 
 
 class IntTestFunction(PyPyTestFunction):

Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Mon May  2 17:22:30 2005
@@ -337,7 +337,7 @@
     """ NOT_RPYTHON """ 
     # XXX will change once we have our own compiler 
     from pypy.interpreter.pycode import PyCode
-    from pypy.tool.pytestsupport import py  # aehem
+    from pypy.tool.getpy import py  # aehem
     source = source.lstrip()
     assert source.startswith('('), "incorrect header in:\n%s" % (source,)
     source = py.code.Source("def anonymous%s\n" % source)

Added: pypy/dist/pypy/tool/pytest/confpath.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/pytest/confpath.py	Mon May  2 17:22:30 2005
@@ -0,0 +1,11 @@
+import autopath 
+import py
+import pypy
+
+pypydir = py.path.local(pypy.__file__).dirpath()
+distdir = pypydir.dirpath()
+testresultdir = distdir.join('testresult') 
+assert pypydir.check(dir=1) 
+libpythondir = distdir.join('lib-python') 
+regrtestdir = libpythondir.join('2.3.4', 'test') 
+modregrtestdir = libpythondir.join('modified-2.3.4', 'test') 

Copied: pypy/dist/pypy/tool/pytest/genreportdata.py (from r11783, pypy/testresult/genreportdata.py)
==============================================================================
--- pypy/testresult/genreportdata.py	(original)
+++ pypy/dist/pypy/tool/pytest/genreportdata.py	Mon May  2 17:22:30 2005
@@ -1,21 +1,21 @@
+import autopath
 import py
 mydir = py.magic.autopath().dirpath().realpath()
-import htmlreport 
+from pypy.tool.pytest import htmlreport 
+from pypy.tool.pytest import confpath 
 
 if __name__ == '__main__': 
-    assert mydir.basename.endswith('result'), mydir
-    mywc = py.path.svnwc(mydir)
+    testresultdir = confpath.testresultdir 
+    assert testresultdir.check(dir=1)
 
-    print "updating", mywc
-    mywc.update()
+    resultwc = py.path.svnwc(testresultdir)
+
+    print "updating", resultwc
+    resultwc.update()
 
-    ppath = htmlreport.getpicklepath()
-    rep = htmlreport.HtmlReport()
     print "traversing", mydir 
-    rep.parse_all(mydir)
+    rep = htmlreport.HtmlReport()
+    rep.parse_all(testresultdir)
 
-    #print "dumping to", ppath
-    #ppath.dump(rep)
-    
     print "making html files"
-    rep.makeindex(mydir.join('index.html'))
+    rep.makeindex(testresultdir.join('index.html'))

Copied: pypy/dist/pypy/tool/pytest/htmlreport.py (from r11786, pypy/testresult/htmlreport.py)
==============================================================================
--- pypy/testresult/htmlreport.py	(original)
+++ pypy/dist/pypy/tool/pytest/htmlreport.py	Mon May  2 17:22:30 2005
@@ -6,17 +6,11 @@
 """
 import sys, os, re
 import py 
+from pypy.tool.pytest import result
 
 # 
 # various interesting path objects 
 #
-testresultdir = py.magic.autopath().dirpath().realpath()
-assert testresultdir.basename.endswith('result')
-pypydistdir = testresultdir.dirpath()
-pypydir = pypydistdir.join('pypy') 
-assert pypydir.check(dir=1) 
-libpythondir = pypydistdir.join('lib-python') 
-resultmodule = libpythondir.join('result.py').pyimport()
 
 html = py.xml.html
 
@@ -35,7 +29,7 @@
     
     def parse_one(self, resultpath): 
         try: 
-            res = resultmodule.ResultFromMime(resultpath) 
+            res = result.ResultFromMime(resultpath) 
             ver = res['testreport-version']
             if ver != "1.1":
                 raise TypeError
@@ -226,7 +220,8 @@
  
 class TestOfHtmlReportClass: 
     def setup_class(cls): 
-        cls.testresultdir = py.path.local()
+        py.test.skip('needs move to own test file')
+        cls.testresultdir = confpath.testresultdir 
         cls.rep = rep = HtmlReport()
         rep.parse_all(cls.testresultdir)
 

Deleted: /pypy/dist/pypy/tool/pytestsupport.py
==============================================================================
--- /pypy/dist/pypy/tool/pytestsupport.py	Mon May  2 17:22:30 2005
+++ (empty file)
@@ -1,199 +0,0 @@
-from __future__ import generators 
-import autopath
-import py
-from py.__.magic import exprinfo
-from pypy.interpreter import gateway
-from pypy.interpreter.error import OperationError
-
-# ____________________________________________________________
-
-class AppFrame(py.code.Frame):
-
-    def __init__(self, pyframe):
-        self.code = py.code.Code(pyframe.code)
-        self.lineno = pyframe.get_last_lineno() - 1
-        self.space = pyframe.space
-        self.w_globals = pyframe.w_globals
-        self.w_locals = pyframe.getdictscope()
-        self.f_locals = self.w_locals   # for py.test's recursion detection
-
-    def eval(self, code, **vars):
-        space = self.space
-        for key, w_value in vars.items():
-            space.setitem(self.w_locals, space.wrap(key), w_value)
-        return space.eval(code, self.w_globals, self.w_locals)
-
-    def exec_(self, code, **vars):
-        space = self.space
-        for key, w_value in vars.items():
-            space.setitem(self.w_locals, space.wrap(key), w_value)
-        space.exec_(code, self.w_globals, self.w_locals)
-
-    def repr(self, w_value):
-        return self.space.unwrap(self.space.repr(w_value))
-
-    def is_true(self, w_value):
-        return self.space.is_true(w_value)
-
-class AppExceptionInfo(py.code.ExceptionInfo):
-    """An ExceptionInfo object representing an app-level exception."""
-
-    def __init__(self, space, operr):
-        self.space = space
-        self.operr = operr
-        self.traceback = AppTraceback(self.operr.application_traceback)
-
-    def exconly(self, tryshort=True): 
-        return '(application-level) ' + self.operr.errorstr(self.space)
-
-    def errisinstance(self, exc): 
-        clsname = exc.__name__ 
-        try: 
-            w_exc = getattr(self.space, 'w_' + clsname) 
-        except KeyboardInterrupt: 
-            raise 
-        except: 
-            pass 
-        else: 
-            return self.operr.match(self.space, w_exc) 
-        return False 
-
-    def __str__(self):
-        return '(application-level) ' + self.operr.errorstr(self.space)
-
-class AppTracebackEntry(py.code.Traceback.Entry):
-    exprinfo = None
-
-    def __init__(self, tb):
-        self.frame = AppFrame(tb.frame)
-        self.lineno = tb.lineno - 1
-
-    def reinterpret(self):
-        # XXX we need to solve a general problem: how to prevent
-        #     reinterpretation from generating a different exception?
-        #     This problem includes the fact that exprinfo will generate
-        #     its own long message that looks like
-        #        OperationError:   << [<W_TypeObject(NameError)>: W_StringObj...
-        #     which is much less nice than the one produced by str(self).
-        # XXX this reinterpret() is only here to prevent reinterpretation.
-        return self.exprinfo
-
-class AppTraceback(py.code.Traceback): 
-    Entry = AppTracebackEntry 
-
-    def __init__(self, apptb):
-        l = []
-        while apptb is not None: 
-            l.append(self.Entry(apptb))
-            apptb = apptb.next 
-        list.__init__(self, l) 
-
-# ____________________________________________________________
-
-def build_pytest_assertion(space):
-    def my_init(space, w_self, __args__):
-        "Our new AssertionError.__init__()."
-        w_parent_init = space.getattr(w_BuiltinAssertionError,
-                                      space.wrap('__init__'))
-        space.call_args(w_parent_init, __args__.prepend(w_self))
-        framestack = space.getexecutioncontext().framestack
-        frame = framestack.top(0)
-##        # Argh! we may see app-level helpers in the frame stack!
-##        #       that's very probably very bad...
-##        if frame.code.co_name == 'normalize_exception': 
-##            frame = framestack.top(1)
-        
-        # if the assertion provided a message, don't do magic
-        args_w, kwargs_w = __args__.unpack()
-        if args_w: 
-            w_msg = args_w[0]
-        else:
-            runner = AppFrame(frame)
-            try:
-                source = runner.statement
-                source = str(source).strip()
-            except py.error.ENOENT: 
-                source = None
-            from pypy import conftest
-            if source and not conftest.option.nomagic: 
-                msg = exprinfo.interpret(source, runner, should_fail=True)
-                space.setattr(w_self, space.wrap('args'),
-                            space.newtuple([space.wrap(msg)]))
-                w_msg = space.wrap(msg)
-            else:
-                w_msg = space.w_None
-        space.setattr(w_self, space.wrap('msg'), w_msg)
-
-    # build a new AssertionError class to replace the original one.
-    w_BuiltinAssertionError = space.getitem(space.builtin.w_dict, 
-                                            space.wrap('AssertionError'))
-    w_metaclass = space.type(w_BuiltinAssertionError)
-    w_init = space.wrap(gateway.interp2app_temp(my_init,
-                                                unwrap_spec=[gateway.ObjSpace,
-                                                             gateway.W_Root,
-                                                             gateway.Arguments]))
-    w_dict = space.newdict([])
-    space.setitem(w_dict, space.wrap('__init__'), w_init)
-    return space.call_function(w_metaclass,
-                               space.wrap('AssertionError'),
-                               space.newtuple([w_BuiltinAssertionError]),
-                               w_dict)
-
-def pypyraises(space, w_ExpectedException, w_expr, __args__):
-    """A built-in function providing the equivalent of py.test.raises()."""
-    args_w, kwds_w = __args__.unpack()
-    if space.is_true(space.isinstance(w_expr, space.w_str)):
-        if args_w:
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("raises() takes no argument "
-                                            "after a string expression"))
-        expr = space.unwrap(w_expr)
-        source = py.code.Source(expr)
-        frame = space.getexecutioncontext().framestack.top()
-        w_locals = frame.getdictscope()
-        w_locals = space.call_method(w_locals, 'copy')
-        for key, w_value in kwds_w.items():
-            space.setitem(w_locals, space.wrap(key), w_value)
-        try:
-            space.exec_(str(source), frame.w_globals, w_locals)
-        except OperationError, e:
-            if e.match(space, w_ExpectedException):
-                return space.sys.call('exc_info')
-            raise
-    else:
-        try:
-            space.call_args(w_expr, __args__)
-        except OperationError, e:
-            if e.match(space, w_ExpectedException):
-                return space.sys.call('exc_info')
-            raise
-    raise OperationError(space.w_AssertionError,
-                         space.wrap("DID NOT RAISE"))
-
-app_raises = gateway.interp2app_temp(pypyraises,
-                                     unwrap_spec=[gateway.ObjSpace,
-                                                  gateway.W_Root,
-                                                  gateway.W_Root,
-                                                  gateway.Arguments])
-
-def pypyskip(space, w_message): 
-    """skip a test at app-level. """ 
-    msg = space.unwrap(w_message) 
-    py.test.skip(msg)
-
-app_skip = gateway.interp2app_temp(pypyskip)
-
-def raises_w(space, w_ExpectedException, *args, **kwds):
-    try:
-        excinfo = py.test.raises(OperationError, *args, **kwds)
-        type, value, tb = excinfo._excinfo
-        if not value.match(space, w_ExpectedException):
-            raise type, value, tb
-        return excinfo
-    except py.test.Item.ExceptionFailure, e:
-        e.tbindex = getattr(e, 'tbindex', -1) - 1
-        raise
-
-def eq_w(space, w_obj1, w_obj2): 
-    """ return interp-level boolean of eq(w_obj1, w_obj2). """ 
-    return space.is_true(space.eq(w_obj1, w_obj2))

Modified: pypy/dist/pypy/tool/test/test_pytestsupport.py
==============================================================================
--- pypy/dist/pypy/tool/test/test_pytestsupport.py	(original)
+++ pypy/dist/pypy/tool/test/test_pytestsupport.py	Mon May  2 17:22:30 2005
@@ -5,7 +5,7 @@
 from pypy.interpreter.argument import Arguments
 from pypy.interpreter.pycode import PyCode
 from pypy.interpreter.pyframe import PyFrame
-from pypy.tool.pytestsupport import AppFrame, build_pytest_assertion, AppExceptionInfo
+from pypy.tool.pytest.appsupport import AppFrame, build_pytest_assertion, AppExceptionInfo
 
 
 def somefunc(x):



More information about the Pypy-commit mailing list