[py-svn] r7786 - in py/dist: doc example/test py/test py/test/report/text
hpk at codespeak.net
hpk at codespeak.net
Thu Dec 9 01:10:50 CET 2004
Author: hpk
Date: Thu Dec 9 01:10:49 2004
New Revision: 7786
Modified:
py/dist/doc/rest_test.py
py/dist/example/test/failure_demo.py
py/dist/py/test/drive.py
py/dist/py/test/item.py
py/dist/py/test/report/text/reporter.py
Log:
M dist/doc/rest_test.py
simplified rest-tests considerably (with the new generative
tests which i begin to like)
M dist/py/test/item.py
M dist/py/test/drive.py
separate Item.execute into Item.run (caring for setup/teardown)
and Item.execute(callable, *args) to execute an actual function.
M dist/example/test/failure_demo.py
M dist/py/test/report/text/reporter.py
add two failures involving generator tests and
fix the reporter to not break.
Modified: py/dist/doc/rest_test.py
==============================================================================
--- py/dist/doc/rest_test.py (original)
+++ py/dist/doc/rest_test.py Thu Dec 9 01:10:49 2004
@@ -6,25 +6,11 @@
mydir = mypath.dirpath()
rest = mydir.dirpath('tool', 'rest.py')
-class RestItem(py.test.Item):
- def __init__(self, path):
- self.path = path
- self.extpy = py.path.extpy(mypath, 'RestItem.execute')
+def restcheck(path):
+ out = py.process.cmdexec("%s %s 2>&1" %(rest, path))
+ assert not out
- def execute(self, *args):
- out = py.process.cmdexec("%s %s 2>&1" %(rest, self.path))
- assert not out
-
-class Collector(py.test.collect.Module):
- def __init__(self, extpy):
- self.extpy = extpy
-
- def __iter__(self):
- for x in mydir.listdir('*.txt'):
- yield RestItem(x)
+def test_rest_files():
+ for x in mydir.listdir('*.txt'):
+ yield restcheck, x
-#def test_rest(p):
-# out = py.process.cmdexec("%s %s" %(rest, mypath))
-# print out
-# assert not out
-
Modified: py/dist/example/test/failure_demo.py
==============================================================================
--- py/dist/example/test/failure_demo.py (original)
+++ py/dist/example/test/failure_demo.py Thu Dec 9 01:10:49 2004
@@ -85,5 +85,15 @@
if namenotexi:
pass
+ def test_generator(self):
+ yield None
+
+ def func1(self):
+ assert 41 == 42
+
+ def test_generator2(self):
+ yield self.func1
+
+
def globf(x):
return x+1
Modified: py/dist/py/test/drive.py
==============================================================================
--- py/dist/py/test/drive.py (original)
+++ py/dist/py/test/drive.py Thu Dec 9 01:10:49 2004
@@ -89,7 +89,7 @@
self.reporter.startitem(item)
if not self.option.collectonly:
try:
- res = item.execute(self) or item.Passed()
+ res = item.run(self) or item.Passed()
except item.Outcome, res:
res.excinfo = py.std.sys.exc_info()
except (KeyboardInterrupt, SystemExit):
Modified: py/dist/py/test/item.py
==============================================================================
--- py/dist/py/test/item.py (original)
+++ py/dist/py/test/item.py Thu Dec 9 01:10:49 2004
@@ -71,14 +71,26 @@
self.name = extpy.basename
self.args = args
- def execute(self, driver):
+ def run(self, driver):
self.setupmanager.setup_path(self.extpy)
target, teardown = self.setupmanager.setup_method(self.extpy)
try:
- target(*self.args)
+ self.execute(target, *self.args)
finally:
if teardown:
teardown(target)
+
+ def execute(self, target, *args):
+ """ default implementation for calling a test target is to
+ simply call it.
+ """
+ return target(*args)
+
+ def reprcall(self):
+ """ return a string representing a call to the underlying
+ test function.
+ """
+ return "%r%r" % (self.extpy.modpath, self.args)
class Outcome:
def __init__(self, **kwargs):
@@ -94,20 +106,20 @@
class GenItem(Item):
def __init__(self, extpy, call, *args):
+ assert callable(call), "generated test %r is not callable" % (call,)
super(GenItem, self).__init__(extpy, *args)
self.call = call
- assert callable(call), "generated test %r is not callable" % (call,)
- def execute(self, driver):
- self.setupmanager.setup_path(self.extpy)
- # XXX target is superflous here
- target, teardown = self.setupmanager.setup_method(self.extpy)
- try:
- print "calling %r%r" %(self.call, self.args)
- self.call(*self.args)
- finally:
- if teardown:
- teardown(target)
+ def execute(self, target, *args):
+ print "calling %r%r" %(self.call, args)
+ return self.call(*args)
+
+ def reprcall(self):
+ """ return a string representing a call to the underlying
+ generated test function.
+ """
+ name = getattr(self.call, '__name__', self.call)
+ return "%s -> %s%r" % (self.extpy.modpath, name, self.args)
#
# triggering specific outcomes from executing Items
Modified: py/dist/py/test/report/text/reporter.py
==============================================================================
--- py/dist/py/test/report/text/reporter.py (original)
+++ py/dist/py/test/report/text/reporter.py Thu Dec 9 01:10:49 2004
@@ -140,7 +140,7 @@
location = "%s:%d" % (realpath.basename, lineno)
resultstring = self.namemap.get(restype, result.__class__.__name__)
self.out.rewrite("%.3f %-2s %-20s %s%s" % (
- elapsed, resultstring, location, str(item.extpy.modpath), writeinfo
+ elapsed, resultstring, location, item.reprcall(), writeinfo
))
if self.option.usepdb:
if (issubclass(restype, Collector.Error) or
More information about the pytest-commit
mailing list