[py-svn] r56739 - in py/branch/event/py/test2: . rep rep/testing testing

hpk at codespeak.net hpk at codespeak.net
Wed Jul 23 15:33:08 CEST 2008


Author: hpk
Date: Wed Jul 23 15:33:07 2008
New Revision: 56739

Added:
   py/branch/event/py/test2/pypresent.py
      - copied, changed from r56729, py/branch/event/py/test2/present.py
   py/branch/event/py/test2/testing/test_pypresent.py
      - copied, changed from r56729, py/branch/event/py/test2/testing/test_present.py
Removed:
   py/branch/event/py/test2/present.py
   py/branch/event/py/test2/rep/testing/test_reporter_helper.py
   py/branch/event/py/test2/testing/test_present.py
Modified:
   py/branch/event/py/test2/collect.py
   py/branch/event/py/test2/item.py
   py/branch/event/py/test2/rep/reporter.py
   py/branch/event/py/test2/runner.py
   py/branch/event/py/test2/testing/test_runner.py
Log:
move python related presentation issues into pypresent.py 


Modified: py/branch/event/py/test2/collect.py
==============================================================================
--- py/branch/event/py/test2/collect.py	(original)
+++ py/branch/event/py/test2/collect.py	Wed Jul 23 15:33:07 2008
@@ -25,7 +25,6 @@
 """ 
 from __future__ import generators 
 import py
-from py.__.test2 import present
 
 def configproperty(name):
     def fget(self):

Modified: py/branch/event/py/test2/item.py
==============================================================================
--- py/branch/event/py/test2/item.py	(original)
+++ py/branch/event/py/test2/item.py	Wed Jul 23 15:33:07 2008
@@ -1,7 +1,7 @@
 import py
 from py.__.test2.collect import FunctionMixin, Node
 from py.__.test2.runner import basic_runner, fork_runner
-from py.__.test2 import present
+from py.__.test2 import pypresent
 
 _dummy = object()
 
@@ -71,10 +71,9 @@
 
     def repr_run(self, runnerinfo):
         """ return a textual representation of run info. """ 
-        return present.python_repr_run(self, runnerinfo)
+        return pypresent.python_repr_run(self, runnerinfo)
 
     def repr_path(self):
-        from py.__.test2.rep.reporter import getrelpath, getmodpath
-        fspath = getrelpath(self._config.topdir, self.fspath)
-        modpath = getmodpath(self)
+        fspath = pypresent.getrelpath(self._config.topdir, self.fspath)
+        modpath = pypresent.getmodpath(self)
         return (fspath, modpath)

Deleted: /py/branch/event/py/test2/present.py
==============================================================================
--- /py/branch/event/py/test2/present.py	Wed Jul 23 15:33:07 2008
+++ (empty file)
@@ -1,49 +0,0 @@
-""" 
-    Some specifics about reporting Python tracebacks in py.test
-"""
-
-import py
-from py.__.code.tbpresent import TBPresenter
-from py.__.test2.rep.reporter import getmodpath
-
-class PythonFunctionPresenter(TBPresenter):
-    """ presenting information about failing Functions and Generators. """ 
-    def __init__(self, config, item):
-        self._config = config
-        self._item = item 
-        super(PythonFunctionPresenter, self).__init__(
-            showlocals=config.option.showlocals,
-            style=config.option.tbstyle,
-        )
-
-    def header(self, title=None):
-        item = self._item
-        if title is None:
-            modpath = getmodpath(item)
-            title = "entrypoint: %s" % modpath
-        self.out.sep("_", title)
-        self.out.line("")
-        if item.name[-1] == "]":   # print extra info for generated tests
-            if not self._config.option.fulltrace: 
-                args = self._saferepr(item._args)
-                line = "%s%s -> %s%s" %(item.parent.name, item.name, 
-                                        item.obj.__name__, args)
-                self.out.line(line)
-
-
-    def repr_run(self, runnerinfo, title=None):
-        excinfo = runnerinfo.excinfo
-        self.header(title)
-        if excinfo:
-            excinfo.traceback = self._item.prunetraceback(excinfo.traceback)
-            self.repr_tb(excinfo)
-        for name, value in zip(["recorded stdout", "recorded stderr"], runnerinfo.outerr):
-            if value:
-                self.out.sep("- ", "%s, len=%d" %(name, len(value)))
-                self.out.line(value.rstrip())
-        self.repr_sep("_")
-
-def python_repr_run(item, runnerinfo, title=None):
-    p = PythonFunctionPresenter(item._config, item)
-    p.repr_run(runnerinfo, title=title)
-    return p.out.stringio.getvalue()

Copied: py/branch/event/py/test2/pypresent.py (from r56729, py/branch/event/py/test2/present.py)
==============================================================================
--- py/branch/event/py/test2/present.py	(original)
+++ py/branch/event/py/test2/pypresent.py	Wed Jul 23 15:33:07 2008
@@ -1,10 +1,8 @@
 """ 
     Some specifics about reporting Python tracebacks in py.test
 """
-
 import py
 from py.__.code.tbpresent import TBPresenter
-from py.__.test2.rep.reporter import getmodpath
 
 class PythonFunctionPresenter(TBPresenter):
     """ presenting information about failing Functions and Generators. """ 
@@ -47,3 +45,37 @@
     p = PythonFunctionPresenter(item._config, item)
     p.repr_run(runnerinfo, title=title)
     return p.out.stringio.getvalue()
+
+def getmodpath(pycolitem): 
+    """ return dotted module path for the given colitem. """ 
+    colitems = pycolitem.listchain()
+    while colitems: 
+        colitem = colitems.pop(0)
+        if isinstance(colitem, colitem.Module):
+            parts = [colitem.obj.__name__]
+            for colitem in colitems: 
+                if colitem.name[0] in '([':
+                    parts[-1] += colitem.name 
+                else:
+                    parts.append(colitem.name) 
+            return ".".join(parts)
+    return colitem.name  
+
+def repr_pythonversion():
+    v = py.std.sys.version_info
+    try:
+        return "%s.%s.%s-%s-%s" % v
+    except (TypeError, ValueError):
+        return str(v)
+
+def getrelpath(source, dest): 
+    base = source.common(dest)
+    if not base: 
+        return None 
+    # with posix local paths '/' is always a common base
+    relsource = source.relto(base)
+    reldest = dest.relto(base)
+    n = relsource.count(source.sep)
+    target = dest.sep.join(('..', )*n + (reldest, ))
+    return target 
+

Modified: py/branch/event/py/test2/rep/reporter.py
==============================================================================
--- py/branch/event/py/test2/rep/reporter.py	(original)
+++ py/branch/event/py/test2/rep/reporter.py	Wed Jul 23 15:33:07 2008
@@ -14,39 +14,6 @@
 
 from time import time as now
 
-def getrelpath(source, dest): 
-    base = source.common(dest)
-    if not base: 
-        return None 
-    # with posix local paths '/' is always a common base
-    relsource = source.relto(base)
-    reldest = dest.relto(base)
-    n = relsource.count(source.sep)
-    target = dest.sep.join(('..', )*n + (reldest, ))
-    return target 
-
-def getmodpath(pycolitem): 
-    """ return dotted module path for the given colitem. """ 
-    # XXX what about non-functions? 
-    colitems = pycolitem.listchain()
-    while colitems: 
-        colitem = colitems.pop(0)
-        if isinstance(colitem, colitem.Module):
-            parts = [colitem.obj.__name__]
-            for colitem in colitems: 
-                if colitem.name[0] in '([':
-                    parts[-1] += colitem.name 
-                else:
-                    parts.append(colitem.name) 
-            return ".".join(parts)
-    return colitem.name  
-
-def repr_pythonversion():
-    v = py.std.sys.version_info
-    try:
-        return "%s.%s.%s-%s-%s" % v
-    except (TypeError, ValueError):
-        return str(v)
 
 def choose_reporter(reporterclass, config):
     option = config.option

Deleted: /py/branch/event/py/test2/rep/testing/test_reporter_helper.py
==============================================================================
--- /py/branch/event/py/test2/rep/testing/test_reporter_helper.py	Wed Jul 23 15:33:07 2008
+++ (empty file)
@@ -1,37 +0,0 @@
-
-import py
-
-from py.__.test2.rep.reporter import getmodpath, repr_pythonversion
-from py.__.test2.testing import setupdata
-
-def test_getmodpath_cases():
-    tmpdir = py.test.ensuretemp("test_getmodpath_cases") 
-    pkgdir = tmpdir.join("pkg") 
-    pkgdir.ensure("__init__.py") 
-    nopkgdir = tmpdir.ensure("nopkg", dir=1) 
-    def checkpkg(names, expected):
-        fcol = setupdata.getexamplecollector(names, tmpdir=pkgdir)
-        assert getmodpath(fcol) == pkgdir.basename + "." + expected 
-    def checknopkg(names, expected):
-        fcol = setupdata.getexamplecollector(names, tmpdir=nopkgdir)
-        assert getmodpath(fcol) == expected 
-
-    for names in (
-        'mod.py test_f1           mod.test_f1', 
-        'mod.py TestA () test_m1  mod.TestA().test_m1', 
-        'mod.py test_g1           mod.test_g1', 
-        'mod.py test_g1 [0]       mod.test_g1[0]', 
-    ):
-        names = names.split()
-        expected = names.pop()
-        yield checkpkg, names, expected 
-        yield checknopkg, names, expected 
-
-def test_repr_python_version():
-    py.magic.patch(py.std.sys, 'version_info', (2, 5, 1, 'final', 0))
-    try:
-        assert repr_pythonversion() == "2.5.1-final-0"
-        py.std.sys.version_info = x = (2,3)
-        assert repr_pythonversion() == str(x) 
-    finally: 
-        py.magic.revert(py.std.sys, 'version_info') 

Modified: py/branch/event/py/test2/runner.py
==============================================================================
--- py/branch/event/py/test2/runner.py	(original)
+++ py/branch/event/py/test2/runner.py	Wed Jul 23 15:33:07 2008
@@ -8,7 +8,7 @@
 from py.__.test2.outcome import Skipped, Exit
 from py.__.test.outcome import Skipped as Skipped2
 import py.__.test2.custompdb
-from py.__.test2 import present
+from py.__.test2 import pypresent
 
 class RunnerInfo:
     """ info on test runs. """
@@ -49,7 +49,7 @@
     if outcome != "setupfailed":
         repr_run = item.repr_run(runnerinfo)
     else:
-        repr_run = present.python_repr_run(item, runnerinfo, 
+        repr_run = pypresent.python_repr_run(item, runnerinfo, 
                 title="failure during setup/teardown")
 
     rep = repevent.ItemTestReport(trail, outcome, repr_run, repr_path)
@@ -78,7 +78,7 @@
     # xxx look into reusing present/tbpresent-writer 
     tw = py.io.TerminalWriter()
     tw.sep("_", "CRASHED with signal=%d: %s" %
-           (result.signal, present.getmodpath(item)))
+           (result.signal, pypresent.getmodpath(item)))
     code = py.code.Code(item.obj) 
     path, firstlineno = code.path, code.firstlineno 
     src = py.code.Source(item.obj)

Deleted: /py/branch/event/py/test2/testing/test_present.py
==============================================================================
--- /py/branch/event/py/test2/testing/test_present.py	Wed Jul 23 15:33:07 2008
+++ (empty file)
@@ -1,56 +0,0 @@
-import py
-from py.__.test2 import present, repevent
-import suptest, setupdata
-import re, sys
-
-class TestPresenter: 
-    def setup_class(cls):
-        cls.tmpdir = py.test2.ensuretemp(cls.__name__) 
-
-    def getpresenter(self, cmdlinearg=None):
-        args = [self.tmpdir]
-        if cmdlinearg:
-            args.append(cmdlinearg)
-        config = py.test2.config._reparse(args)
-        return present.FuncPresenter(config)
-
-    def test_repr_pruning_tb_generated_test(self):
-        itemtestreport,fn = suptest.getItemTestReport("""
-            def test_gen():
-                def check(x):
-                    assert x
-                yield check, 0
-        """)
-        s = itemtestreport.repr_run
-        print s
-        lines = s.split("\n")
-        assert lines[0].find("test_0.test_0.test_gen[0]") != -1
-        assert lines[2].find("test_gen[0] -> check(0,)") != -1
-        assert lines[3].find("def check(x):") != -1
-
-    def test_repr_tb_short(self):
-        # XXX probably a redundant test 
-        itemtestreport,fn = suptest.getItemTestReport("""
-            def f(x):
-                assert x 
-            def test_f():
-                f(0)
-        """, tb="short")
-        s = itemtestreport.repr_run
-        print s
-        index = -1 
-        basename = fn.basename
-        lines = s.split("\n")[2:]
-        for line in (
-              '  File "%s", line 5, in test_f' % basename, 
-              '    f(0)', 
-              '  File "%s", line 3, in f' % basename, 
-              '    assert x',
-              'E   assert 0'
-        ):
-            actual = lines.pop(0)
-            actual = actual.rstrip()
-            if line != actual:
-                print "expected:", repr(line)
-                print "got     :", repr(actual)
-                assert 0

Copied: py/branch/event/py/test2/testing/test_pypresent.py (from r56729, py/branch/event/py/test2/testing/test_present.py)
==============================================================================
--- py/branch/event/py/test2/testing/test_present.py	(original)
+++ py/branch/event/py/test2/testing/test_pypresent.py	Wed Jul 23 15:33:07 2008
@@ -1,7 +1,8 @@
 import py
-from py.__.test2 import present, repevent
+from py.__.test2 import pypresent
+from py.__.test2.testing import setupdata
 import suptest, setupdata
-import re, sys
+import sys
 
 class TestPresenter: 
     def setup_class(cls):
@@ -12,7 +13,7 @@
         if cmdlinearg:
             args.append(cmdlinearg)
         config = py.test2.config._reparse(args)
-        return present.FuncPresenter(config)
+        return pypresent.FuncPresenter(config)
 
     def test_repr_pruning_tb_generated_test(self):
         itemtestreport,fn = suptest.getItemTestReport("""
@@ -54,3 +55,36 @@
                 print "expected:", repr(line)
                 print "got     :", repr(actual)
                 assert 0
+
+
+def test_getmodpath_cases():
+    tmpdir = py.test.ensuretemp("test_getmodpath_cases") 
+    pkgdir = tmpdir.join("pkg") 
+    pkgdir.ensure("__init__.py") 
+    nopkgdir = tmpdir.ensure("nopkg", dir=1) 
+    def checkpkg(names, expected):
+        fcol = setupdata.getexamplecollector(names, tmpdir=pkgdir)
+        assert pypresent.getmodpath(fcol) == pkgdir.basename + "." + expected 
+    def checknopkg(names, expected):
+        fcol = setupdata.getexamplecollector(names, tmpdir=nopkgdir)
+        assert pypresent.getmodpath(fcol) == expected 
+
+    for names in (
+        'mod.py test_f1           mod.test_f1', 
+        'mod.py TestA () test_m1  mod.TestA().test_m1', 
+        'mod.py test_g1           mod.test_g1', 
+        'mod.py test_g1 [0]       mod.test_g1[0]', 
+    ):
+        names = names.split()
+        expected = names.pop()
+        yield checkpkg, names, expected 
+        yield checknopkg, names, expected 
+
+def test_repr_python_version():
+    py.magic.patch(py.std.sys, 'version_info', (2, 5, 1, 'final', 0))
+    try:
+        assert pypresent.repr_pythonversion() == "2.5.1-final-0"
+        py.std.sys.version_info = x = (2,3)
+        assert pypresent.repr_pythonversion() == str(x) 
+    finally: 
+        py.magic.revert(py.std.sys, 'version_info') 

Modified: py/branch/event/py/test2/testing/test_runner.py
==============================================================================
--- py/branch/event/py/test2/testing/test_runner.py	(original)
+++ py/branch/event/py/test2/testing/test_runner.py	Wed Jul 23 15:33:07 2008
@@ -2,7 +2,7 @@
 import py
 from py.__.test2 import runner
 from py.__.test2.outcome import Exit
-from py.__.test2 import present
+from py.__.test2 import pypresent
 from py.__.test2 import mock 
 
 class MockItem:
@@ -93,11 +93,11 @@
                 py.test2.skip("skip")
         def testfunc(): pass
         def pythonreprrun(item, runnerinfo, title=None): return ""
-        py.magic.patch(present, "python_repr_run", pythonreprrun)
+        py.magic.patch(pypresent, "python_repr_run", pythonreprrun)
         try:
             testrep = self.run(testfunc, setupstate=MySetupState())
         finally:
-            py.magic.revert(present, "python_repr_run")
+            py.magic.revert(pypresent, "python_repr_run")
         assert testrep.skipped 
         assert not testrep.failed
         assert not testrep.passed
@@ -112,11 +112,11 @@
         def pythonreprrun(item, runnerinfo, title=None):
             assert runnerinfo.excinfo.errisinstance(ValueError)
             return "pythonreprrun"
-        py.magic.patch(present, "python_repr_run", pythonreprrun)
+        py.magic.patch(pypresent, "python_repr_run", pythonreprrun)
         try:
             testrep = self.run(testfunc, setupstate=MySetupState())
         finally:
-            py.magic.revert(present, "python_repr_run")
+            py.magic.revert(pypresent, "python_repr_run")
         assert testrep.setupfailed
         assert testrep.failed
         assert not testrep.passed
@@ -182,11 +182,11 @@
             pass
         def pythonreprrun(item, runnerinfo, title=None):
             l.append(runnerinfo)
-        py.magic.patch(present, "python_repr_run", pythonreprrun)
+        py.magic.patch(pypresent, "python_repr_run", pythonreprrun)
         try:
             testrep = self.run(testfunc, setupstate=MySetupState())
         finally:
-            py.magic.revert(present, "python_repr_run")
+            py.magic.revert(pypresent, "python_repr_run")
         assert testrep.setupfailed
         assert testrep.failed
         assert not testrep.passed
@@ -230,5 +230,5 @@
 def test_crash_report():
     py.test.skip("check that crash reporting works")
 
-def test_present_tb_and_python_repr_run():
-    py.test.skip("check that present_tb and python_repr_run work")
+def test_pypresent_tb_and_python_repr_run():
+    py.test.skip("check that pypresent_tb and python_repr_run work")



More information about the pytest-commit mailing list