[py-svn] r57024 - in py/branch/event/py: code code/testing test2 test2/rep test2/testing
hpk at codespeak.net
hpk at codespeak.net
Wed Aug 6 11:27:56 CEST 2008
Author: hpk
Date: Wed Aug 6 11:27:55 2008
New Revision: 57024
Modified:
py/branch/event/py/code/excinfo.py
py/branch/event/py/code/testing/test_excinfo.py
py/branch/event/py/test2/rep/terminal.py
py/branch/event/py/test2/repevent.py
py/branch/event/py/test2/testing/acceptance_test.py
py/branch/event/py/test2/testing/test_repevent.py
Log:
traceback presentation
Modified: py/branch/event/py/code/excinfo.py
==============================================================================
--- py/branch/event/py/code/excinfo.py (original)
+++ py/branch/event/py/code/excinfo.py Wed Aug 6 11:27:55 2008
@@ -59,7 +59,7 @@
"""
repr = self._formatrepr(showlocals=showlocals, style=style)
tw = py.io.TerminalWriter()
- repr.writeterminal(tw)
+ repr.toterminal(tw)
return tw.stringio.getvalue()
def __str__(self):
@@ -78,7 +78,7 @@
self.showlocals = showlocals
self.style = style
- def writeterminal(self, tw):
+ def toterminal(self, tw):
for line in self.lines:
if isinstance(line, LineSep):
tw.sep(line.sep, line.line)
@@ -100,7 +100,7 @@
try:
source = entry.getsource()
except py.error.ENOENT:
- source = "???"
+ source = py.code.Source("???")
return source.deindent()
def _saferepr(self, obj):
@@ -159,6 +159,7 @@
line_index = entry.lineno - entry.getfirstlinesource()
if self.style == "long":
+ self._line("")
self.repr_source(source, line_index, excinfo)
self._line("")
message = excinfo and excinfo.exconly() or ""
@@ -217,6 +218,7 @@
# filename and lineno output for each entry,
# using an output format that most editors unterstand
msg = self.message
- if msg.find("\n") != -1:
- msg = repr(msg)
+ i = msg.find("\n")
+ if i != -1:
+ msg = msg[:i]
return ("%s:%s: %s" %(self.path, self.lineno, msg))
Modified: py/branch/event/py/code/testing/test_excinfo.py
==============================================================================
--- py/branch/event/py/code/testing/test_excinfo.py (original)
+++ py/branch/event/py/code/testing/test_excinfo.py Wed Aug 6 11:27:55 2008
@@ -1,6 +1,14 @@
import py
from py.__.code.excinfo import FormattedExcinfo
+class TWMock:
+ def __init__(self):
+ self.lines = []
+ def sep(self, sep, line):
+ self.lines.append((sep, line))
+ def line(self, line):
+ self.lines.append(line)
+
def test_excinfo_simple():
try:
raise ValueError
@@ -272,10 +280,11 @@
# test intermittent entries
- assert lines[0] == " def entry():"
- assert lines[1] == "> func1()"
- assert not lines[2]
- loc = lines[3]
+ assert lines[0] == ""
+ assert lines[1] == " def entry():"
+ assert lines[2] == "> func1()"
+ assert not lines[3]
+ loc = lines[4]
assert loc.path == mod.__file__
assert loc.lineno == 5
assert not loc.message
@@ -284,15 +293,16 @@
p = FormattedExcinfo()
p.repr_tb_entry(excinfo.traceback[-1], excinfo)
lines = p.lines
- assert lines[0] == " def func1():"
- assert lines[1] == '> raise ValueError("hello\\nworld")'
- assert lines[2] == "E ValueError: hello"
- assert lines[3] == "E world"
- loc = lines[5]
+ assert lines[0] == ""
+ assert lines[1] == " def func1():"
+ assert lines[2] == '> raise ValueError("hello\\nworld")'
+ assert lines[3] == "E ValueError: hello"
+ assert lines[4] == "E world"
+ loc = lines[6]
assert loc.path == mod.__file__
assert loc.lineno == 3
assert loc.message == "ValueError: hello\nworld"
- assert str(loc) == "%s:3: 'ValueError: hello\\nworld'" %(mod.__file__,)
+ assert str(loc) == "%s:3: ValueError: hello" %(mod.__file__,)
def test_repr_tbentry_short(self):
mod = self.importasmod("""
@@ -418,9 +428,36 @@
assert str(line1) == str(line2)
tw = py.io.TerminalWriter()
- fex.writeterminal(tw)
+ fex.toterminal(tw)
lines1 = tw.stringio.getvalue().split("\n")
lines2 = excinfo.format().split("\n")
for line1, line2 in zip(repr.lines, fex.lines):
assert line1 == line2
+
+ def test_toterminal(self):
+ mod = self.importasmod("""
+ def g(x):
+ raise ValueError(x)
+ def f():
+ g(3)
+ """)
+ excinfo = py.test.raises(ValueError, mod.f)
+ excinfo.traceback = excinfo.traceback.filter()
+ repr = excinfo._formatrepr()
+ tw = TWMock()
+
+ repr.toterminal(tw)
+ assert tw.lines
+ assert tw.lines.pop(0) == ""
+ assert tw.lines[0] == " def f():"
+ assert tw.lines[1] == "> g(3)"
+ assert tw.lines[2] == ""
+ assert tw.lines[3].endswith("mod.py:5: ")
+ assert tw.lines[4] == ("_ ", "")
+ assert tw.lines[5] == ""
+ assert tw.lines[6] == " def g(x):"
+ assert tw.lines[7] == "> raise ValueError(x)"
+ assert tw.lines[8] == "E ValueError: 3"
+ assert tw.lines[9] == ""
+ assert tw.lines[10].endswith("mod.py:3: ValueError: 3")
Modified: py/branch/event/py/test2/rep/terminal.py
==============================================================================
--- py/branch/event/py/test2/rep/terminal.py (original)
+++ py/branch/event/py/test2/rep/terminal.py Wed Aug 6 11:27:55 2008
@@ -42,8 +42,11 @@
def rep_SessionFinish(self, ev):
self.out.line("")
- for ev in self._failed:
- ev.writelongrepr(self.out)
+ if self._failed:
+ self.out.sep("=", "FAILURES")
+ for ev in self._failed:
+ self.out.sep("_")
+ ev.writelongrepr(self.out)
if not self._failed or self.config.option.showskipsummary:
folded_skips = self._folded_skips()
Modified: py/branch/event/py/test2/repevent.py
==============================================================================
--- py/branch/event/py/test2/repevent.py (original)
+++ py/branch/event/py/test2/repevent.py Wed Aug 6 11:27:55 2008
@@ -54,8 +54,8 @@
def writelongrepr(self, out):
longrepr = self.failed.longrepr
- if hasattr(longrepr, 'terminalwrite'):
- longrepr.terminalwrite(self.out)
+ if hasattr(longrepr, 'toterminal'):
+ longrepr.toterminal(out)
else:
out.line(str(longrepr))
Modified: py/branch/event/py/test2/testing/acceptance_test.py
==============================================================================
--- py/branch/event/py/test2/testing/acceptance_test.py (original)
+++ py/branch/event/py/test2/testing/acceptance_test.py Wed Aug 6 11:27:55 2008
@@ -28,7 +28,8 @@
ret = None
for name, value in kwargs.iteritems():
p = py.path.local(name).new(ext=".py")
- p.write(py.code.Source(value))
+ source = py.code.Source(value)
+ p.write(str(py.code.Source(value)).lstrip())
if ret is None:
ret = p
return ret
@@ -115,7 +116,7 @@
"*test_one.py ss",
"*test_two.py - Skipped*",
"___* skipped test summary *_",
- "*conftest.py:3: *3* Skipped: 'test'",
+ "*conftest.py:2: *3* Skipped: 'test'",
])
def test_no_skip_summary_if_failure(self):
@@ -167,6 +168,35 @@
"* no failures :)*",
])
+ def test_traceback_failure(self):
+ p1 = self.makepyfile(test_fail="""
+ def g():
+ return 2
+ def f(x):
+ assert x == g()
+ def test_onefails():
+ f(3)
+ """)
+ result = self.runpytest(p1)
+ assert_lines_contain_lines(result.outlines, [
+ "test_fail.py F",
+ "====* FAILURES *====",
+ "____*____",
+ " def test_onefails():",
+ "> f(3)",
+ "",
+ "*test_fail.py:6: ",
+ "_ _ _ *",
+ #"",
+ " def f(x):",
+ "> assert x == g()",
+ "E assert 3 == 2",
+ "E + where 2 = g()",
+ "",
+ "*test_fail.py:4: AssertionError: assert 3 == 2",
+ ])
+
+
def test_looponfailing_looping(self):
py.test.skip("thought needed to nicely test --looponfailing")
py.test.skip("xxx check events")
Modified: py/branch/event/py/test2/testing/test_repevent.py
==============================================================================
--- py/branch/event/py/test2/testing/test_repevent.py (original)
+++ py/branch/event/py/test2/testing/test_repevent.py Wed Aug 6 11:27:55 2008
@@ -1,6 +1,7 @@
from py.__.test2 import repevent
import setupdata, suptest
+from py.__.code.testing.test_excinfo import TWMock
class TestItemTestReport(object):
@@ -9,7 +10,11 @@
reports = sorter.get(repevent.ItemTestReport)
ev = reports[0]
assert ev.failed
- #assert ev.repr_run.find("AssertionError") != -1
+ twmock = TWMock()
+ ev.writelongrepr(twmock)
+ assert ('_', '') in twmock.lines
+
+ ##assert ev.repr_run.find("AssertionError") != -1
filepath = ev.colitem.fspath
#filepath , modpath = ev.itemrepr_path
assert str(filepath).endswith("filetest.py")
More information about the pytest-commit
mailing list