[py-svn] r10395 - in py/branch/py-collect/test/tkinter: . testing
jan at codespeak.net
jan at codespeak.net
Thu Apr 7 10:04:23 CEST 2005
Author: jan
Date: Thu Apr 7 10:04:23 2005
New Revision: 10395
Removed:
py/branch/py-collect/test/tkinter/testing/test_exceptionfailure.py
Modified:
py/branch/py-collect/test/tkinter/guidriver.py
py/branch/py-collect/test/tkinter/repository.py
py/branch/py-collect/test/tkinter/testing/test_repository.py
py/branch/py-collect/test/tkinter/testing/test_util.py
py/branch/py-collect/test/tkinter/tkgui.py
py/branch/py-collect/test/tkinter/util.py
Log:
cleaned up code
added label to GUI with information about selected tests
Modified: py/branch/py-collect/test/tkinter/guidriver.py
==============================================================================
--- py/branch/py-collect/test/tkinter/guidriver.py (original)
+++ py/branch/py-collect/test/tkinter/guidriver.py Thu Apr 7 10:04:23 2005
@@ -1,9 +1,7 @@
-
+'''GuiDriver builds TestReport instances and sends them to tkgui.Manager'''
import py
-from util import Status, TestReport, Null
-from py.__impl__.test.drive import Exit, exit, SimpleOutErrCapture
-
-import pprint
+from util import TestReport
+from py.__impl__.test.drive import Exit, SimpleOutErrCapture
class GuiDriver(py.test.Driver):
@@ -12,19 +10,6 @@
self.channel = channel
self.reportlist = []
- def info(self, **kwargs):
- return
- print '-' * 60
- #print 'reportlist:', self.reportlist
- for key, value in kwargs.items():
- print key,':', pprint.pformat(value)
- if isinstance(kwargs.get('res'), (py.test.Item.Passed,
- py.test.Item.Skipped,
- py.test.Item.Failed)):
- print '!' *80
- print 'py.test.item.Outcome found'
- print '!' *80
- print '-' * 60
def header(self, colitems):
super(GuiDriver, self).header(colitems)
@@ -57,7 +42,7 @@
#py.std.time.sleep(0.5)
def sendreport(self, report):
- self.channel.send(report.toChannel())
+ self.channel.send(report.to_channel())
def warning(self, msg):
pass
Modified: py/branch/py-collect/test/tkinter/repository.py
==============================================================================
--- py/branch/py-collect/test/tkinter/repository.py (original)
+++ py/branch/py-collect/test/tkinter/repository.py Thu Apr 7 10:04:23 2005
@@ -5,25 +5,11 @@
import copy
import time
-from util import Null
-from itertools import izip, count
-
import UserDict
-## import logging
-## log = logging
-## def initlog():
-## global log
-## remote = logging.FileHandler('./remote.log')
-## remote.setLevel(logging.DEBUG)
-## formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
-## remote.setFormatter(formatter)
-## log = logging.getLogger('remote')
-## log.addHandler(remote)
-
-
class Repository(object):
+ '''like a trie'''
nothing = object()
def __init__(self):
@@ -106,7 +92,7 @@
class OrderedDict(UserDict.DictMixin):
-
+ '''like a normal dict, but keys are ordered by time of setting'''
def __init__(self, *args, **kwargs):
self._dict = dict(*args, **kwargs)
self._keys = self._dict.keys()
@@ -136,7 +122,7 @@
return new
class OrderedDictMemo(UserDict.DictMixin):
-
+ '''memorize all keys and how they were ordered'''
def __init__(self, *args, **kwargs):
self._dict = dict(*args, **kwargs)
self._keys = self._dict.keys()
Deleted: /py/branch/py-collect/test/tkinter/testing/test_exceptionfailure.py
==============================================================================
--- /py/branch/py-collect/test/tkinter/testing/test_exceptionfailure.py Thu Apr 7 10:04:23 2005
+++ (empty file)
@@ -1,7 +0,0 @@
-
-import time
-
-import py
-
-def test_exceptionfailure():
- py.test.raises(TypeError, 'time.time()')
Modified: py/branch/py-collect/test/tkinter/testing/test_repository.py
==============================================================================
--- py/branch/py-collect/test/tkinter/testing/test_repository.py (original)
+++ py/branch/py-collect/test/tkinter/testing/test_repository.py Thu Apr 7 10:04:23 2005
@@ -148,23 +148,5 @@
assert self.dict.keys() == ['key1', 'key2']
-class Test_Failing:
- """ will fail!!"""
-
- def test_fail(self):
- print 'recorded stdout'
- m = dict(((1,2),(3,4)))
- l = (1,m)
- assert False == l
-
- def test_calling_fail(self):
- py.test.fail('Try to fail')
-
- def test_skip(self):
- print 'recorded stdout'
- py.test.skip('Try to skip this test')
-
- def test_skip_on_error(self):
- py.test.skip_on_error(''.index, 'hello')
Modified: py/branch/py-collect/test/tkinter/testing/test_util.py
==============================================================================
--- py/branch/py-collect/test/tkinter/testing/test_util.py (original)
+++ py/branch/py-collect/test/tkinter/testing/test_util.py Thu Apr 7 10:04:23 2005
@@ -86,8 +86,8 @@
def test_toChannel_fromChannel(self):
- assert isinstance(self.testresult.toChannel()['status'], str)
- result = TestReport.fromChannel(self.testresult.toChannel())
+ assert isinstance(self.testresult.to_channel()['status'], str)
+ result = TestReport.fromChannel(self.testresult.to_channel())
assert isinstance(result.status, Status)
def test_copy(self):
Modified: py/branch/py-collect/test/tkinter/tkgui.py
==============================================================================
--- py/branch/py-collect/test/tkinter/tkgui.py (original)
+++ py/branch/py-collect/test/tkinter/tkgui.py Thu Apr 7 10:04:23 2005
@@ -39,6 +39,8 @@
def createwidgets(self):
self.mainframe = tk.Frame(self.parent)
+ self.reportlabel = tk.Label(self.mainframe, text = ' \n ', anchor=tk.W)
+ self.reportlabel.pack()
self.treeframe = tk.Frame(self.mainframe)
self.tree = gui.ResultTree(master=self.treeframe, root_id='Root',
get_contents_callback=self.create_new_nodes,
@@ -80,7 +82,8 @@
#self.text.yview_pickplace(tk.END)
self.attacheditorhotspots(self.text)
self.text['state'] = tk.DISABLED
- pass
+
+ self.reportlabel['text'] = '%s\n%s' % (report.fspath, report.modpath)
def attacheditorhotspots(self, text):
# Attach clickable regions to a Text widget.
@@ -136,8 +139,12 @@
folder = 1
self.tree.add_node(name=name, id=report.id, flag=folder, report = report)
- def display_action(self, action):
+ def display_action(self, action, node_id=None):
self.parent.title(str(action))
+ if node_id is not None:
+ report = self.repositorycommand().find(node_id)
+ self.reportlabel['text'] = '%s\n%s' % (report.fspath,
+ report.modpath)
def process_messages(self, manager):
"""
@@ -155,7 +162,7 @@
self.parent.bell()
else:
self.tree.update_node(full_id)
- self.display_action('running: ' + str(full_id[-1]) )
+ self.display_action('running: ' + str(full_id[-1]), full_id )
except Queue.Empty:
pass
self.tree.update_root(self.repositorycommand().find(self.tree.root.full_id()))
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 Thu Apr 7 10:04:23 2005
@@ -1,4 +1,6 @@
-import types, string, sys
+'''some classes to handle text reports'''
+
+import sys
import py
from py.__impl__.test.report.text import out
from py.__impl__.test.terminal import TerminalDriver
@@ -24,6 +26,8 @@
_ExceptionFailure = 'ExceptionFailure'
class Status(object):
+ '''Represents py.test.Collector.Outcome as a string.
+ Possible values: NotExecuted, Passed, Skipped, Failed, ExceptionFailure'''
def NotExecuted(cls):
return cls('NotExecuted')
@@ -78,10 +82,13 @@
return self.str
def update(self, status):
+ '''merge self and status, self will be set to the "higher" status
+ in ordered_list'''
name_int_map = dict(
py.std.itertools.izip(self.ordered_list,
py.std.itertools.count()))
- self.str = self.ordered_list[max([name_int_map[i] for i in (str(status), self.str)])]
+ self.str = self.ordered_list[max([name_int_map[i]
+ for i in (str(status), self.str)])]
def __eq__(self, other):
return self.str == other.str
@@ -90,7 +97,8 @@
return not self.__eq__(other)
class OutBuffer(out.Out):
-
+ '''Simple MockObject for py.__impl__.test.report.text.out.Out.
+ Used to get the output of TerminalDriver.'''
def __init__(self, fullwidth = 80 -1):
self.output = []
self.fullwidth = fullwidth
@@ -111,6 +119,7 @@
class TestReport(object):
+ '''"Channel-save" report of a py.test.Collector.Outcome instance'''
template = {'time' : 0,
'label': 'Root',
@@ -121,8 +130,12 @@
'error_report': '',
'finished': False,
'restart_params': None, # ('',('',))
+ 'fspath' : '',
+ 'modpath': '',
}
+
def fromChannel(cls, kwdict):
+ ''' TestReport.fromChannel(report.toChannel()) == report '''
if 'status' in kwdict:
kwdict['status'] = Status(kwdict['status'])
return cls(**kwdict)
@@ -136,6 +149,7 @@
setattr(self, key, value)
def start(self, collector):
+ '''Driver.start should call this to init the report'''
self.full_id = collector.listnames()
self.id = collector.name
if collector.getpathlineno(): # save for Null() in test_util.py
@@ -145,18 +159,24 @@
else:
str_append = ' [%s]' % fspath.basename
self.label = collector.name + str_append
-
+
+ self.fspath = self.abbrev_path(collector.fspath)
+ self.modpath = collector.getmodpath()
self.settime()
self.restart_params = (str(collector.listchain()[0].fspath),
collector.listnames())
self.status = Status.NotExecuted()
def finish(self, collector, res, option = Null()):
+ '''Driver.finish should call this to set the
+ value of error_report
+ option is passed to Driver at initialization'''
self.settime()
if collector.getpathlineno(): # save for Null() in test_util.py
fspath, lineno = collector.getpathlineno()
if lineno != sys.maxint:
- str_append = ' [%s:%s] %0.2fsecs' % (fspath.basename, lineno, self.time)
+ str_append = ' [%s:%s] %0.2fsecs' % (fspath.basename,
+ lineno, self.time)
else:
str_append = ' [%s] %0.2fsecs' % (fspath.basename, self.time)
self.label = collector.name + str_append
@@ -168,6 +188,16 @@
self.status.update(Status(res))
self.finished = True
+ def abbrev_path(self, fspath):
+ 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))
+ return base + "_" + basename
+
def report_failed(self, option, item, res):
#XXX hack abuse of TerminalDriver
terminal = TerminalDriver(option)
@@ -176,27 +206,29 @@
terminal.repr_failure(item, res)
return out.getoutput()
- def report_skipped(self,option, item, res):
+ def report_skipped(self, option, item, res):
texts = {}
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
+ d[(fn, lineno)] = res
out = OutBuffer()
out.sep('_', 'reasons for skipped tests')
for text, dict in texts.items():
for (fn, lineno), res in dict.items():
- out.line('Skipped in %s:%d' %(fn,lineno))
+ out.line('Skipped in %s:%d' %(fn, lineno))
out.line("reason: %s" % text)
return out.getoutput()
def settime(self):
+ '''update self.time '''
self.time = py.std.time.time() - self.time
- def toChannel(self):
+ def to_channel(self):
+ '''counterpart of classmethod fromChannel'''
ret = self.template.copy()
for key in ret.keys():
ret[key] = getattr(self, key, self.template[key])
@@ -204,18 +236,18 @@
return ret
def __str__(self):
- return str(self.toChannel())
+ return str(self.to_channel())
def __repr__(self):
return str(self)
def copy(self, **kwargs):
- channel_dict = self.toChannel()
+ channel_dict = self.to_channel()
channel_dict.update(kwargs)
return TestReport.fromChannel(channel_dict)
class TestFileWatcher:
-
+ '''watches files or paths'''
def __init__(self, *paths):
self.paths = [py.path.local(path) for path in paths]
self.watchdict = dict()
@@ -227,6 +259,7 @@
return None
def check_files(self):
+ '''returns (changed files, deleted files)'''
fil = py.path.checker(fnmatch='*.py')
rec = py.path.checker(dotfile=0)
@@ -237,14 +270,17 @@
else:
files.extend(path.visit(fil, rec))
newdict = dict(zip(files, [self.file_information(p) for p in files]))
- files_deleted = [f for f in self.watchdict.keys() if not newdict.has_key(f)]
+ files_deleted = [f for f in self.watchdict.keys()
+ if not newdict.has_key(f)]
files_new = [f for f in newdict.keys() if not self.watchdict.has_key(f)]
- files_changed = [f for f in newdict.keys() if self.watchdict.has_key(f) and newdict[f]!= self.watchdict[f]]
+ files_changed = [f for f in newdict.keys() if self.watchdict.has_key(f)
+ and newdict[f]!= self.watchdict[f]]
files_changed = files_new + files_changed
self.watchdict = newdict
return files_changed, files_deleted
def changed(self):
+ '''returns False if nothing changed'''
changed, deleted = self.check_files()
return changed != [] or deleted != []
More information about the pytest-commit
mailing list