[py-svn] r10522 - in py/branch/py-collect/test: . report terminal testing tkinter
hpk at codespeak.net
hpk at codespeak.net
Sun Apr 10 22:44:22 CEST 2005
Author: hpk
Date: Sun Apr 10 22:44:22 2005
New Revision: 10522
Added:
py/branch/py-collect/test/terminal/ (props changed)
py/branch/py-collect/test/terminal/__init__.py
- copied unchanged from r10519, py/branch/py-collect/test/__init__.py
py/branch/py-collect/test/terminal/out.py
- copied unchanged from r10519, py/branch/py-collect/test/report/text/out.py
py/branch/py-collect/test/terminal/terminal.py
- copied, changed from r10519, py/branch/py-collect/test/terminal.py
Removed:
py/branch/py-collect/test/report/
py/branch/py-collect/test/terminal.py
Modified:
py/branch/py-collect/test/testing/test_api.py (props changed)
py/branch/py-collect/test/tkinter/util.py
Log:
- move terminal related stuff into subdir
- remove unused report directory
(although we may grow a reporting abstraction
again at some point ...)
Deleted: /py/branch/py-collect/test/terminal.py
==============================================================================
--- /py/branch/py-collect/test/terminal.py Sun Apr 10 22:44:22 2005
+++ (empty file)
@@ -1,386 +0,0 @@
-import py
-
-from py.__impl__.test.report.text.out import getout
-from time import time as now
-Item = py.test.Item
-
-class TerminalSession(py.test.Session):
- def __init__(self, config, file=None):
- super(TerminalSession, self).__init__(config)
- if file is None:
- file = py.std.sys.stdout
- self.out = getout(file)
- self._started = {}
- self._opencollectors = []
-
- # ---------------------
- # PROGRESS information
- # ---------------------
-
- def start(self, colitem):
- super(TerminalSession, self).start(colitem)
- if self.config.option.collectonly:
- cols = self._opencollectors
- self.out.line(' ' * len(cols) + repr(colitem))
- cols.append(colitem)
- else:
- cls = getattr(colitem, '__class__', None)
- if cls is None:
- return
- for typ in py.std.inspect.getmro(cls):
- meth = getattr(self, 'start_%s' % typ.__name__, None)
- if meth:
- meth(colitem)
- break
- colitem.start = py.std.time.time()
-
- def start_Module(self, colitem):
- try:
- numunits = len(list(colitem.iteritems()))
- except TypeError:
- numunits = -1
-
- colitem.numunits = numunits
- if numunits > 0:
- fspath = colitem.fspath
- if self.config.option.verbose == 0:
- # old representation
- #parts = fspath.parts()
- #basename = parts.pop().basename
- #while parts and parts[-1].basename in ('testing', 'test'):
- # parts.pop()
- #base = parts[-1].basename
- #if len(base) < 13:
- # base = base + "_" * (13-len(base))
- #abbrev_fn = base + "_" + basename
- abbrev_fn = "/".join(colitem.listnames())
- self.out.write('%s[%d] ' % (abbrev_fn, numunits))
- elif self.config.option.verbose > 0:
- #curdir = py.path.local()
- #if fspath.check(local=True, relto=curdir):
- # fspath = fspath.relto(curdir)
- self.out.line()
- self.out.line("+ testmodule: %s" % fspath)
-
- def start_Item(self, colitem):
- if self.config.option.verbose >= 1:
- if isinstance(colitem, py.test.Item):
- realpath, lineno = colitem.getpathlineno()
- location = "%s:%d" % (realpath.basename, lineno+1)
- self.out.rewrite("%-20s %s " % (
- location, colitem.reprcall()))
-
- def finish(self, colitem, result):
- end = now()
- super(TerminalSession, self).finish(colitem, result)
- if self.config.option.collectonly:
- cols = self._opencollectors
- last = cols.pop()
- #assert last == colitem, "expected %r, got %r" %(last, colitem)
- return
- colitem.elapsedtime = end - colitem.start
- if self.config.option.usepdb:
- if isinstance(result, Item.Failed):
- print "dispatching to ppdb", colitem
- self.repr_failure(colitem, result)
- import pdb
- self.out.rewrite(
- '\n%s: %s\n'
- % (result.excinfo.type.__name__,
- result.excinfo.value))
- pdb.post_mortem(result.excinfo._excinfo[2])
- if isinstance(result, (colitem.Failed,)):
- if self.config.option.exitfirstproblem:
- py.test.exit("exit on first problem configured.", item=colitem)
- if result is None or not isinstance(colitem, py.test.Item):
- if isinstance(colitem, py.test.collect.Module) \
- and self.config.option.verbose == 0 \
- and colitem.numunits > 0:
- self.out.line()
- return
- else:
- restype, c = self._processresult(result)
- if self.config.option.verbose >= 1:
- resultstring = self.namemap.get(restype, result.__class__.__name__)
- resultstring += " (%.2f)" % (colitem.elapsedtime,)
- self.out.line(resultstring)
- else:
- self.out.write(c)
-
- # -------------------
- # HEADER information
- # -------------------
- def header(self, colitems):
- super(TerminalSession, self).header(colitems)
- self.out.sep("=", "test process starts")
- option = self.config.option
- if option.looponfailing:
- mode = 'session/child process'
- elif option.executable:
- mode = 'child process'
- else:
- mode = 'inprocess'
- self.out.line("testing-mode: %s" % mode)
- self.out.line("executable: %s (%s)" %
- (py.std.sys.executable, repr_pythonversion()))
-
-
- if self.config.option.traceconfig or self.config.option.verbose:
- rev = py.__package__.getrev()
- self.out.line("using py lib: %s <rev %s>" % (
- py.path.local(py.__file__).dirpath(), rev))
-
- for x in colitems:
- self.out.line("test target: %s" %(x.fspath,))
-
- for i,x in py.builtin.enumerate(self.config._initialconfigmodules):
- self.out.line("initial conf %d: %s" %(i, x.__file__))
-
- #for i, x in py.builtin.enumerate(py.test.config.configpaths):
- # self.out.line("initial testconfig %d: %s" %(i, x))
- #additional = py.test.config.getfirst('additionalinfo')
- #if additional:
- # for key, descr in additional():
- # self.out.line("%s: %s" %(key, descr))
- self.out.line()
- self.starttime = now()
-
- # -------------------
- # FOOTER information
- # -------------------
-
- def footer(self, colitems):
- super(TerminalSession, self).footer(colitems)
- self.endtime = now()
- self.out.line()
- self.skippedreasons()
- self.failures()
- self.summaryline()
-
- # --------------------
- # progress information
- # --------------------
- typemap = {
- Item.Passed: '.',
- Item.Skipped: 's',
- Item.Failed: 'F',
- }
- namemap = {
- Item.Passed: 'ok',
- Item.Skipped: 'SKIP',
- Item.Failed: 'FAIL',
- }
-
- def _processresult(self, testresult):
- for restype, char in self.typemap.items():
- if isinstance(testresult, restype):
- return restype, char
- else:
- raise TypeError, "not a result instance: %r" % testresult
-
- # --------------------
- # summary information
- # --------------------
- def summaryline(self):
- outlist = []
- sum = 0
- for typ in Item.Passed, Item.Failed, Item.Skipped:
- l = self.getresults(typ)
- if l:
- outlist.append('%d %s' % (len(l), typ.__name__.lower()))
- sum += len(l)
- elapsed = self.endtime-self.starttime
- status = "%s" % ", ".join(outlist)
- self.out.sep('=', 'tests finished: %s in %4.2f seconds' %
- (status, elapsed))
-
- def skippedreasons(self):
- texts = {}
- for colitem, res in self.getresults(Item.Skipped):
- tbindex = getattr(res, 'tbindex', -1)
- raisingtb = res.excinfo.traceback[tbindex]
- fn = raisingtb.frame.code.path
- lineno = raisingtb.lineno
- d = texts.setdefault(res.excinfo.exconly(), {})
- d[(fn,lineno)] = res
-
- if texts:
- self.out.line()
- self.out.sep('_', 'reasons for skipped tests')
- for text, dict in texts.items():
- for (fn, lineno), res in dict.items():
- self.out.line('Skipped in %s:%d' %(fn,lineno))
- self.out.line("reason: %s" % text)
- self.out.line()
-
- def failures(self):
- l = self.getresults(Item.Failed)
- if l:
- self.out.sep('_')
- for colitem, res in l:
- self.repr_failure(colitem, res)
-
- def repr_failure(self, item, res):
- excinfo = res.excinfo
- traceback = excinfo.traceback
- if item:
- self.cut_traceback(traceback, item)
- if not traceback:
- self.out.line("empty traceback from item %r" % (item,))
- return
- last = traceback[-1]
- recursioncache = {}
- for entry in traceback:
- self.out.line("")
- if entry == last:
- indent = self.repr_source(entry, 'E')
- self.repr_failure_explanation(excinfo, indent)
- else:
- self.repr_source(entry, '>')
- self.out.line("")
- self.out.line("[%s:%d]" %(entry.frame.code.path, entry.lineno+1))
- self.repr_locals(entry)
-
- # trailing info
- if entry == last:
- if item:
- self.repr_failure_info(item, entry)
- self.repr_out_err(res)
- self.out.sep("_")
- else:
- self.out.sep("_ ")
- if not self.config.option.nomagic and \
- isinstance(excinfo.value, RuntimeError) and \
- self.isrecursive(entry, recursioncache):
- self.out.line("Recursion detected (same locals & position)")
- self.out.sep("!")
- break
-
- def isrecursive(self, entry, recursioncache):
- # recursion detection
- key = entry.frame.code.path, entry.frame.lineno
- #print "checking for recursion at", key
- l = recursioncache.setdefault(key, [])
- if l:
- f = entry.frame
- loc = f.f_locals
- for otherloc in l:
- if f.is_true(f.eval(co_equal,
- __recursioncache_locals_1=loc,
- __recursioncache_locals_2=otherloc)):
- return True
- l.append(entry.frame.f_locals)
-
- def repr_failure_info(self, item, entry):
- root = item.fspath
- modpath = item.getmodpath()
- try:
- fn, lineno = item.getpathlineno()
- except TypeError:
- assert isinstance(item.parent, py.test.collect.Generator)
- # a generative test yielded a non-callable
- fn, lineno = item.parent.getpathlineno()
- if fn != entry.frame.code.path or \
- entry.frame.code.firstlineno != lineno:
- self.out.line("[testcode : %s:%d]" % (fn, lineno+1))
- if root == fn:
- self.out.line("[modulepath: %s]" %(modpath))
- else:
- self.out.line("[modulepath: %s %s]" %(root.basename, modpath))
-
- def repr_source(self, entry, marker=">"):
- try:
- source = entry.getsource()
- except py.error.ENOENT:
- self.out.line("[failure to get at sourcelines from %r]\n" % entry)
- else:
- source = source.deindent()
- for line in source[:-1]:
- self.out.line(" " + line)
- lastline = source[-1]
- self.out.line(marker + " " + lastline)
- try:
- s = str(source.getstatement(len(source)-1))
- except KeyboardInterrupt:
- raise
- except:
- #self.out.line("[failed to get last statement]\n%s" %(source,))
- s = str(source[-1])
- #print "XXX %r" % s
- return 4 + (len(s) - len(s.lstrip()))
- return 0
-
- def cut_traceback(self, traceback, item=None):
- if self.config.option.fulltrace or item is None:
- return
- path, lineno = item.getpathlineno()
- for i, entry in py.builtin.enumerate(traceback):
- if entry.frame.code.path == path and \
- entry.frame.code.firstlineno == lineno:
- del traceback[:i]
- break
- # get rid of all frames marked with __tracebackhide__
- l = []
- for entry in traceback:
- try:
- x = entry.frame.eval("__tracebackhide__")
- except:
- x = None
- if not x:
- l.append(entry)
- traceback[:] = l
-
- def repr_failure_explanation(self, excinfo, indent):
- info = None
- info = getattr(getattr(excinfo, 'value', ''), 'msg', '')
- if not info and not self.config.option.nomagic:
- 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]")
- indent = " " * indent
- if not info:
- info = str(excinfo)
-
- 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, res):
- for name in 'out', 'err':
- if hasattr(res, name):
- out = getattr(res, name)
- if out.strip():
- self.out.sep("- ", "recorded std%s" % name)
- self.out.line(out.strip())
-
- def repr_locals(self, entry):
- if self.config.option.showlocals:
- self.out.sep('- ', 'locals')
- for name, value in entry.frame.f_locals.items():
- if name == '__builtins__':
- self.out.line("__builtins__ = <builtins>")
- elif len(repr(value)) < 70 or not isinstance(value,
- (list, tuple, dict)):
- self.out.line("%-10s = %r" %(name, value))
- else:
- self.out.line("%-10s =\\" % (name,))
- py.std.pprint.pprint(value, stream=self.out)
-
-co_equal = compile('__recursioncache_locals_1 == __recursioncache_locals_2',
- '?', 'eval')
-
-def repr_pythonversion():
- v = py.std.sys.version_info
- try:
- return "%s.%s.%s-%s-%s" % v
- except ValueError:
- return str(v)
Copied: py/branch/py-collect/test/terminal/terminal.py (from r10519, py/branch/py-collect/test/terminal.py)
==============================================================================
--- py/branch/py-collect/test/terminal.py (original)
+++ py/branch/py-collect/test/terminal/terminal.py Sun Apr 10 22:44:22 2005
@@ -1,6 +1,6 @@
import py
-from py.__impl__.test.report.text.out import getout
+from py.__impl__.test.terminal.out import getout
from time import time as now
Item = py.test.Item
Modified: py/branch/py-collect/test/tkinter/util.py
==============================================================================
--- py/branch/py-collect/test/tkinter/util.py (original)
+++ py/branch/py-collect/test/tkinter/util.py Sun Apr 10 22:44:22 2005
@@ -2,8 +2,7 @@
import sys
import py
-from py.__impl__.test.report.text import out
-from py.__impl__.test.terminal import TerminalSession
+from py.__impl__.test.terminal import out
class Null:
""" Null objects always and reliably "do nothing." """
@@ -200,7 +199,7 @@
def report_failed(self, option, item, res):
#XXX hack abuse of TerminalSession
- terminal = TerminalSession(option)
+ terminal = py.test.TerminalSession(option)
out = OutBuffer()
terminal.out = out
terminal.repr_failure(item, res)
More information about the pytest-commit
mailing list