[pypy-svn] r74680 - in pypy/trunk/py: . _code _plugin _test

hpk at codespeak.net hpk at codespeak.net
Sat May 22 17:20:40 CEST 2010


Author: hpk
Date: Sat May 22 17:20:39 2010
New Revision: 74680

Modified:
   pypy/trunk/py/__init__.py
   pypy/trunk/py/_code/code.py
   pypy/trunk/py/_plugin/pytest_mark.py
   pypy/trunk/py/_plugin/pytest_runner.py
   pypy/trunk/py/_plugin/pytest_skipping.py
   pypy/trunk/py/_plugin/pytest_terminal.py
   pypy/trunk/py/_test/collect.py
   pypy/trunk/py/_test/pycollect.py
Log:
update to py-1.3.1 release candidate


Modified: pypy/trunk/py/__init__.py
==============================================================================
--- pypy/trunk/py/__init__.py	(original)
+++ pypy/trunk/py/__init__.py	Sat May 22 17:20:39 2010
@@ -8,7 +8,7 @@
 
 (c) Holger Krekel and others, 2004-2010
 """
-__version__ = version = "1.3.1a1"
+__version__ = version = "1.3.1"
 
 import py.apipkg
 

Modified: pypy/trunk/py/_code/code.py
==============================================================================
--- pypy/trunk/py/_code/code.py	(original)
+++ pypy/trunk/py/_code/code.py	Sat May 22 17:20:39 2010
@@ -416,7 +416,7 @@
                 args.append((argname, self._saferepr(argvalue)))
             return ReprFuncArgs(args)
 
-    def get_source(self, source, line_index=-1, excinfo=None):
+    def get_source(self, source, line_index=-1, excinfo=None, short=False):
         """ return formatted and marked up source lines. """
         lines = []
         if source is None:
@@ -428,6 +428,8 @@
             if i == line_index:
                 prefix = self.flow_marker + "   "
             else:
+                if short:
+                    continue
                 prefix = "    "
             line = prefix + source[i]
             lines.append(line)
@@ -482,24 +484,26 @@
             line_index = entry.lineno - max(entry.getfirstlinesource(), 0)
 
         lines = []
-        if self.style == "long":
-            reprargs = self.repr_args(entry) 
-            lines.extend(self.get_source(source, line_index, excinfo))
-            message = excinfo and excinfo.typename or ""
+        if self.style in ("short", "long"):
+            short = self.style == "short"
+            reprargs = None
+            if not short:
+                reprargs = self.repr_args(entry) 
+            s = self.get_source(source, line_index, excinfo, short=short)
+            lines.extend(s)
+            if short:
+                message = "in %s" %(entry.name)
+            else:
+                message = excinfo and excinfo.typename or ""
             path = self._makepath(entry.path)
             filelocrepr = ReprFileLocation(path, entry.lineno+1, message)
-            localsrepr =  self.repr_locals(entry.locals)
-            return ReprEntry(lines, reprargs, localsrepr, filelocrepr)
-        else: 
-            if self.style == "short":
-                line = source[line_index].lstrip()
-                basename = os.path.basename(entry.frame.code.filename)
-                lines.append('  File "%s", line %d, in %s' % (
-                    basename, entry.lineno+1, entry.name))
-                lines.append("    " + line) 
-            if excinfo: 
-                lines.extend(self.get_exconly(excinfo, indent=4))
-            return ReprEntry(lines, None, None, None)
+            localsrepr = None
+            if not short:
+                localsrepr =  self.repr_locals(entry.locals)
+            return ReprEntry(lines, reprargs, localsrepr, filelocrepr, short)
+        if excinfo: 
+            lines.extend(self.get_exconly(excinfo, indent=4))
+        return ReprEntry(lines, None, None, None, False)
 
     def _makepath(self, path):
         if not self.abspath:
@@ -595,13 +599,21 @@
 class ReprEntry(TerminalRepr):
     localssep = "_ "
 
-    def __init__(self, lines, reprfuncargs, reprlocals, filelocrepr):
+    def __init__(self, lines, reprfuncargs, reprlocals, filelocrepr, short):
         self.lines = lines
         self.reprfuncargs = reprfuncargs
         self.reprlocals = reprlocals 
         self.reprfileloc = filelocrepr
+        self.short = short
 
     def toterminal(self, tw):
+        if self.short:
+            self.reprfileloc.toterminal(tw)
+            for line in self.lines:
+                red = line.startswith("E   ") 
+                tw.line(line, bold=True, red=red)
+            #tw.line("")
+            return
         if self.reprfuncargs:
             self.reprfuncargs.toterminal(tw)
         for line in self.lines:

Modified: pypy/trunk/py/_plugin/pytest_mark.py
==============================================================================
--- pypy/trunk/py/_plugin/pytest_mark.py	(original)
+++ pypy/trunk/py/_plugin/pytest_mark.py	Sat May 22 17:20:39 2010
@@ -44,11 +44,13 @@
     class TestClass:
         def test_startup(self):
             ...
+        def test_startup_and_more(self):
+            ...
 
 This is equivalent to directly applying the decorator to the
-``test_startup`` function. 
+two test functions. 
 
-To remain compatible with Python2.5 you can instead set a 
+To remain compatible with Python2.5 you can also set a 
 ``pytestmark`` attribute on a TestClass like this::
 
     import py
@@ -56,7 +58,7 @@
     class TestClass:
         pytestmark = py.test.mark.webtest
 
-or if you need to use multiple markers::
+or if you need to use multiple markers you can use a list::
 
     import py
 
@@ -68,7 +70,7 @@
     import py
     pytestmark = py.test.mark.webtest
 
-in which case then it will be applied to all functions and 
+in which case it will be applied to all functions and 
 methods defined in the module.  
 
 Using "-k MARKNAME" to select tests
@@ -114,11 +116,14 @@
             if len(args) == 1 and hasattr(func, '__call__') or \
                hasattr(func, '__bases__'):
                 if hasattr(func, '__bases__'):
-                    l = func.__dict__.setdefault("pytestmark", [])
-                    if not isinstance(l, list):
-                       func.pytestmark = [l, self]
-                    else: 
-                       l.append(self)
+                    if hasattr(func, 'pytestmark'):
+                        l = func.pytestmark
+                        if not isinstance(l, list):
+                           func.pytestmark = [l, self]
+                        else: 
+                           l.append(self)
+                    else:
+                       func.pytestmark = [self]
                 else:
                     holder = getattr(func, self.markname, None)
                     if holder is None:

Modified: pypy/trunk/py/_plugin/pytest_runner.py
==============================================================================
--- pypy/trunk/py/_plugin/pytest_runner.py	(original)
+++ pypy/trunk/py/_plugin/pytest_runner.py	Sat May 22 17:20:39 2010
@@ -188,7 +188,11 @@
             self.passed = True
             self.result = result 
         else:
-            self.longrepr = self.collector._repr_failure_py(excinfo)
+            style = "short"
+            if collector.config.getvalue("fulltrace"):
+                style = "long"
+            self.longrepr = self.collector._repr_failure_py(excinfo, 
+                style=style)
             if excinfo.errisinstance(py.test.skip.Exception):
                 self.skipped = True
                 self.reason = str(excinfo.value)

Modified: pypy/trunk/py/_plugin/pytest_skipping.py
==============================================================================
--- pypy/trunk/py/_plugin/pytest_skipping.py	(original)
+++ pypy/trunk/py/_plugin/pytest_skipping.py	Sat May 22 17:20:39 2010
@@ -106,6 +106,17 @@
 
     @py.test.mark.xfail(..., reason="my reason")
 
+imperative xfail from within a test or setup function
+------------------------------------------------------
+
+If you cannot declare xfail-conditions at import time
+you can also imperatively produce an XFail-outcome from 
+within test or setup code.  Example::
+
+    def test_function():
+        if not valid_config():
+            py.test.xfail("unsuppored configuration")
+
 
 skipping on a missing import dependency
 --------------------------------------------------
@@ -207,11 +218,12 @@
         if not evalxfail:
             return
     if call.excinfo and call.excinfo.errisinstance(py.test.xfail.Exception):
-        rep = __multicall__.execute()
-        rep.keywords['xfail'] = "reason: " + call.excinfo.value.msg
-        rep.skipped = True
-        rep.failed = False
-        return rep
+        if not item.config.getvalue("runxfail"):
+            rep = __multicall__.execute()
+            rep.keywords['xfail'] = "reason: " + call.excinfo.value.msg
+            rep.skipped = True
+            rep.failed = False
+            return rep
     if call.when == "setup":
         rep = __multicall__.execute()
         if rep.skipped and evalxfail.istrue():

Modified: pypy/trunk/py/_plugin/pytest_terminal.py
==============================================================================
--- pypy/trunk/py/_plugin/pytest_terminal.py	(original)
+++ pypy/trunk/py/_plugin/pytest_terminal.py	Sat May 22 17:20:39 2010
@@ -284,7 +284,7 @@
         self._sessionstarttime = py.std.time.time()
 
         verinfo = ".".join(map(str, sys.version_info[:3]))
-        msg = "python: platform %s -- Python %s" % (sys.platform, verinfo)
+        msg = "platform %s -- Python %s" % (sys.platform, verinfo)
         msg += " -- pytest-%s" % (py.__version__)
         if self.config.option.verbose or self.config.option.debug or getattr(self.config.option, 'pastebin', None):
             msg += " -- " + str(sys.executable)

Modified: pypy/trunk/py/_test/collect.py
==============================================================================
--- pypy/trunk/py/_test/collect.py	(original)
+++ pypy/trunk/py/_test/collect.py	Sat May 22 17:20:39 2010
@@ -172,14 +172,15 @@
     def _prunetraceback(self, traceback):
         return traceback 
 
-    def _repr_failure_py(self, excinfo):
+    def _repr_failure_py(self, excinfo, style=None):
         excinfo.traceback = self._prunetraceback(excinfo.traceback)
         # XXX should excinfo.getrepr record all data and toterminal()
         # process it? 
-        if self.config.option.tbstyle == "short":
-            style = "short"
-        else:
-            style = "long"
+        if style is None:
+            if self.config.option.tbstyle == "short":
+                style = "short"
+            else:
+                style = "long"
         return excinfo.getrepr(funcargs=True, 
                                showlocals=self.config.option.showlocals,
                                style=style)

Modified: pypy/trunk/py/_test/pycollect.py
==============================================================================
--- pypy/trunk/py/_test/pycollect.py	(original)
+++ pypy/trunk/py/_test/pycollect.py	Sat May 22 17:20:39 2010
@@ -253,7 +253,7 @@
             traceback = ntraceback.filter()
         return traceback 
 
-    def _repr_failure_py(self, excinfo):
+    def _repr_failure_py(self, excinfo, style="long"):
         if excinfo.errisinstance(funcargs.FuncargRequest.LookupError):
             fspath, lineno, msg = self.reportinfo()
             lines, _ = inspect.getsourcelines(self.obj)
@@ -261,11 +261,13 @@
                 if line.strip().startswith('def'):
                     return FuncargLookupErrorRepr(fspath, lineno,
             lines[:i+1], str(excinfo.value))
-        return super(FunctionMixin, self)._repr_failure_py(excinfo)
+        return super(FunctionMixin, self)._repr_failure_py(excinfo, 
+            style=style)
 
     def repr_failure(self, excinfo, outerr=None):
         assert outerr is None, "XXX outerr usage is deprecated"
-        return self._repr_failure_py(excinfo)
+        return self._repr_failure_py(excinfo, 
+            style=self.config.getvalue("tbstyle"))
 
     shortfailurerepr = "F"
 



More information about the Pypy-commit mailing list