[py-svn] r37176 - in py/branch/config/py: code test/rsession test/terminal
fijal at codespeak.net
fijal at codespeak.net
Tue Jan 23 11:29:23 CET 2007
Author: fijal
Date: Tue Jan 23 11:29:21 2007
New Revision: 37176
Modified:
py/branch/config/py/code/representation.py
py/branch/config/py/test/rsession/reporter.py
py/branch/config/py/test/terminal/terminal.py
Log:
Move one method from terminal outside to the representation.py.
Now rsession should use this one as well.
Modified: py/branch/config/py/code/representation.py
==============================================================================
--- py/branch/config/py/code/representation.py (original)
+++ py/branch/config/py/code/representation.py Tue Jan 23 11:29:21 2007
@@ -12,16 +12,20 @@
""" Class used for presentation of various objects,
sharing common output style
"""
- def __init__(self, out):
+ def __init__(self, out, config):
""" out is a file-like object (we can write to it)
"""
assert hasattr(out, 'write')
self.out = out
+ self.config = config
def repr_source(self, source, marker=">", marker_location=-1):
""" This one represents piece of source with possible
marker at requested position
"""
+ if isinstance(source, str):
+ # why the hell, string is iterable?
+ source = source.split("\n")
if marker_location < 0:
marker_location += len(source)
if marker_location < 0:
@@ -50,3 +54,44 @@
self.out.sep("_", "entrypoint: %s" %(modpath))
else:
self.out.sep("_", "entrypoint: %s %s" %(root.basename, modpath))
+
+ def repr_failure_explanation(self, excinfo, source):
+ try:
+ s = str(source.getstatement(len(source)-1))
+ except KeyboardInterrupt:
+ raise
+ except:
+ s = str(source[-1])
+ indent = " " * (4 + (len(s) - len(s.lstrip())))
+ # get the real exception information out
+ lines = excinfo.exconly(tryshort=True).split('\n')
+ self.out.line('>' + indent[:-1] + lines.pop(0))
+ for x in lines:
+ self.out.line(indent + x)
+ return
+
+ # XXX reinstate the following with a --magic option?
+ # the following line gets user-supplied messages (e.g.
+ # for "assert 0, 'custom message'")
+ msg = getattr(getattr(excinfo, 'value', ''), 'msg', '')
+ info = None
+ if not msg:
+ special = excinfo.errisinstance((SyntaxError, SystemExit, KeyboardInterrupt))
+ if not self.config.option.nomagic and not special:
+ try:
+ info = excinfo.traceback[-1].reinterpret() # very detailed info
+ except KeyboardInterrupt:
+ raise
+ except:
+ if self.config.option.verbose >= 1:
+ self.out.line("[reinterpretation traceback]")
+ py.std.traceback.print_exc(file=py.std.sys.stdout)
+ else:
+ self.out.line("[reinterpretation failed, increase "
+ "verbosity to see details]")
+ # print reinterpreted info if any
+ if info:
+ lines = info.split('\n')
+ self.out.line('>' + indent[:-1] + lines.pop(0))
+ for x in lines:
+ self.out.line(indent + x)
Modified: py/branch/config/py/test/rsession/reporter.py
==============================================================================
--- py/branch/config/py/test/rsession/reporter.py (original)
+++ py/branch/config/py/test/rsession/reporter.py Tue Jan 23 11:29:21 2007
@@ -23,7 +23,7 @@
self.failed_tests_outcome = []
self.skipped_tests_outcome = []
self.out = getout(py.std.sys.stdout)
- self.presenter = Presenter(self.out)
+ self.presenter = Presenter(self.out, config)
self.failed = dict([(host, 0) for host in hosts])
self.skipped = dict([(host, 0) for host in hosts])
self.passed = dict([(host, 0) for host in hosts])
@@ -125,7 +125,7 @@
def gethost(self, event):
return event.host.hostname
- def repr_failure(self, item, outcome):
+ def repr_failure(self, item, outcome):
excinfo = outcome.excinfo
traceback = excinfo.traceback
#if item and not self.config.option.fulltrace:
Modified: py/branch/config/py/test/terminal/terminal.py
==============================================================================
--- py/branch/config/py/test/terminal/terminal.py (original)
+++ py/branch/config/py/test/terminal/terminal.py Tue Jan 23 11:29:21 2007
@@ -27,7 +27,7 @@
self._file = file
self.out = getout(file)
self._opencollectors = []
- self.presenter = Presenter(self.out)
+ self.presenter = Presenter(self.out, config)
# ---------------------
# PROGRESS information
@@ -295,7 +295,7 @@
marker_location = entry.lineno - firstsourceline
if entry == last:
self.presenter.repr_source(source, 'E', marker_location)
- self.repr_failure_explanation(excinfo, source)
+ self.presenter.repr_failure_explanation(excinfo, source)
else:
self.presenter.repr_source(source, '>', marker_location)
self.out.line("")
@@ -338,7 +338,7 @@
if entry == last:
if source:
self.presenter.repr_source(source, 'E')
- self.repr_failure_explanation(excinfo, source)
+ self.presenter.repr_failure_explanation(excinfo, source)
else:
if source:
self.presenter.repr_source(source, ' ')
@@ -364,47 +364,6 @@
source = py.code.Source("[failure to get at sourcelines from %r]\n" % entry)
return source.deindent()
- def repr_failure_explanation(self, excinfo, source):
- try:
- s = str(source.getstatement(len(source)-1))
- except KeyboardInterrupt:
- raise
- except:
- s = str(source[-1])
- indent = " " * (4 + (len(s) - len(s.lstrip())))
- # get the real exception information out
- lines = excinfo.exconly(tryshort=True).split('\n')
- self.out.line('>' + indent[:-1] + lines.pop(0))
- for x in lines:
- self.out.line(indent + x)
- return
-
- # XXX reinstate the following with a --magic option?
- # the following line gets user-supplied messages (e.g.
- # for "assert 0, 'custom message'")
- msg = getattr(getattr(excinfo, 'value', ''), 'msg', '')
- info = None
- if not msg:
- special = excinfo.errisinstance((SyntaxError, SystemExit, KeyboardInterrupt))
- if not self.config.option.nomagic and not special:
- try:
- info = excinfo.traceback[-1].reinterpret() # very detailed info
- except KeyboardInterrupt:
- raise
- except:
- if self.config.option.verbose >= 1:
- self.out.line("[reinterpretation traceback]")
- py.std.traceback.print_exc(file=py.std.sys.stdout)
- else:
- self.out.line("[reinterpretation failed, increase "
- "verbosity to see details]")
- # print reinterpreted info if any
- if info:
- lines = info.split('\n')
- self.out.line('>' + indent[:-1] + lines.pop(0))
- for x in lines:
- self.out.line(indent + x)
-
def repr_out_err(self, colitem):
for parent in colitem.listchain():
for name, obj in zip(['out', 'err'], parent.getouterr()):
More information about the pytest-commit
mailing list