[py-svn] r10500 - in py/branch/py-collect/test: . testing
hpk at codespeak.net
hpk at codespeak.net
Sat Apr 9 23:42:53 CEST 2005
Author: hpk
Date: Sat Apr 9 23:42:52 2005
New Revision: 10500
Modified:
py/branch/py-collect/test/collect.py
py/branch/py-collect/test/config.py
py/branch/py-collect/test/session.py
py/branch/py-collect/test/testing/test_collect.py
py/branch/py-collect/test/testing/test_session.py
Log:
- refactored Collector.run() to return a list of names
instead of colitems. This makes it more natural
for custom Collectors.
- fixed output capturing to work with --pdb
Modified: py/branch/py-collect/test/collect.py
==============================================================================
--- py/branch/py-collect/test/collect.py (original)
+++ py/branch/py-collect/test/collect.py Sat Apr 9 23:42:52 2005
@@ -116,7 +116,11 @@
the same order as in their file.
"""
for x in self.run():
- return x.sortvalue()
+ return self.join(x).sortvalue()
+
+ def multijoin(self, namelist):
+ """ return a list of colitems for the given namelist. """
+ return [self.join(name) for name in namelist]
def getpathlineno(self):
return self.fspath, py.std.sys.maxint
@@ -163,7 +167,7 @@
yield self
else:
for x in self.run():
- for y in x.iteritems():
+ for y in self.join(x).iteritems():
yield y
def fspath():
@@ -203,10 +207,9 @@
def run(self):
l = self.fspath.listdir()
l.sort()
- l = [self.join(x.basename) for x in l
+ return [x.basename for x in l
if (x.check(file=1) and self.filefilter(x) or
x.check(dir=1) and self.recfilter(x))]
- return filter(None, l)
def join(self, name):
x = self.fspath.join(name)
@@ -226,8 +229,8 @@
for name in dir(self.obj):
if self.funcnamefilter(name) or self.classnamefilter(name):
x = self.join(name)
- if x:
- l.append((x.sortvalue(), x))
+ if x is not None:
+ l.append((x.sortvalue(), name))
l.sort()
return [x[1] for x in l]
@@ -262,7 +265,7 @@
def run(self):
if getattr(self.obj, 'disabled', 0):
return []
- return [self.join("()")]
+ return ["()"]
def join(self, name):
assert name == '()'
@@ -300,7 +303,7 @@
if not callable(call):
raise TypeError("yielded test %r not callable" %(call,))
l.append(x)
- namelist.append(self.join("[%d]" % i))
+ namelist.append("[%d]" % i)
return namelist
def join(self, name):
Modified: py/branch/py-collect/test/config.py
==============================================================================
--- py/branch/py-collect/test/config.py (original)
+++ py/branch/py-collect/test/config.py Sat Apr 9 23:42:52 2005
@@ -189,9 +189,10 @@
l = [current]
return l
-def flattenoptions(parser):
- for group in parser.option_groups:
- for y in group.option_list:
- yield y
- for x in parser.option_list:
- yield x
+#XXX was needed for extracting defaults, not needed anymore?
+#def flattenoptions(parser):
+# for group in parser.option_groups:
+# for y in group.option_list:
+# yield y
+# for x in parser.option_list:
+# yield x
Modified: py/branch/py-collect/test/session.py
==============================================================================
--- py/branch/py-collect/test/session.py (original)
+++ py/branch/py-collect/test/session.py Sat Apr 9 23:42:52 2005
@@ -57,30 +57,26 @@
if self.shouldclose():
raise SystemExit, "received external close signal"
+ res = capture = None
if not self.option.nocapture: # and isinstance(colitem, py.test.Item):
capture = SimpleOutErrCapture()
- else:
- capture = None
-
- res = None
+ needfinish = False
try:
self.start(colitem)
- try:
- try:
- res = self.run(colitem)
- except (KeyboardInterrupt, Exit):
- raise
- except colitem.Outcome, res:
- if not hasattr(res, 'excinfo'):
- res.excinfo = py.code.ExceptionInfo()
- except:
- excinfo = py.code.ExceptionInfo()
- res = colitem.Failed(excinfo=excinfo)
- else:
- assert (res is None or
- isinstance(res, (list, colitem.Outcome)))
- finally:
- self.finish(colitem, res)
+ needfinish = True
+ try:
+ res = self.run(colitem)
+ except (KeyboardInterrupt, Exit):
+ raise
+ except colitem.Outcome, res:
+ if not hasattr(res, 'excinfo'):
+ res.excinfo = py.code.ExceptionInfo()
+ except:
+ excinfo = py.code.ExceptionInfo()
+ res = colitem.Failed(excinfo=excinfo)
+ else:
+ assert (res is None or
+ isinstance(res, (list, colitem.Outcome)))
finally:
if capture is not None:
out, err = capture.reset()
@@ -88,6 +84,8 @@
res.out, res.err = out, err
except AttributeError:
pass
+ if needfinish:
+ self.finish(colitem, res)
def run(self, colitem):
if self.option.collectonly and isinstance(colitem, py.test.Item):
@@ -102,7 +100,8 @@
raise TypeError("%r.run() returned neither "
"sequence nor None: %r" % (colitem, res))
else:
- for obj in seq:
+ for name in seq:
+ obj = colitem.join(name)
self.runtraced(obj)
return res
Modified: py/branch/py-collect/test/testing/test_collect.py
==============================================================================
--- py/branch/py-collect/test/testing/test_collect.py (original)
+++ py/branch/py-collect/test/testing/test_collect.py Sat Apr 9 23:42:52 2005
@@ -29,20 +29,23 @@
col = py.test.collect.Module(fn)
l = col.run()
assert len(l) == 2
+ assert l[0] == 'test_one'
+ assert l[1] == 'TestClass'
+
items = list(col.iteritems())
assert len(items) == 2
-
- assert l[0].name == 'test_one'
- assert l[1].name == 'TestClass'
- assert l[1].fspath == fn
+ for item in items:
+ assert item.fspath == fn
def test_failing_import_directory():
class MyDirectory(py.test.collect.Directory):
filefilter = py.path.checker(fnmatch='testspecial*.py')
- l = MyDirectory(datadir).run()
+ mydir = MyDirectory(datadir)
+ l = mydir.run()
assert len(l) == 1
- assert isinstance(l[0], py.test.collect.Module)
- py.test.raises(ImportError, l[0].run)
+ item = mydir.join(l[0])
+ assert isinstance(item, py.test.collect.Module)
+ py.test.raises(ImportError, item.run)
def test_module_file_not_found():
fn = datadir.join('nada','no')
@@ -58,8 +61,9 @@
col = py.test.collect.Module(datadir.join('disabled.py'))
l = col.run()
assert len(l) == 1
- assert isinstance(l[0], py.test.collect.Class)
- assert not l[0].run()
+ colitem = col.join(l[0])
+ assert isinstance(colitem, py.test.collect.Class)
+ assert not colitem.run()
class Testsomeclass:
disabled = True
@@ -97,12 +101,13 @@
col = py.test.collect.Module(tfile)
l = col.run()
assert len(l) == 2
+ l = col.multijoin(l)
generator = l[0]
- print l
assert isinstance(generator, py.test.collect.Generator)
l2 = generator.run()
assert len(l2) == 2
+ l2 = generator.multijoin(l2)
assert isinstance(l2[0], py.test.Function)
assert isinstance(l2[1], py.test.Function)
assert l2[0].name == '[0]'
@@ -112,10 +117,13 @@
classlist = l[1].run()
assert len(classlist) == 1
- generator = classlist[0].run()[0]
+ classlist = l[1].multijoin(classlist)
+ cls = classlist[0]
+ generator = cls.join(cls.run()[0])
assert isinstance(generator, py.test.collect.Generator)
l2 = generator.run()
assert len(l2) == 2
+ l2 = generator.multijoin(l2)
assert isinstance(l2[0], py.test.Function)
assert isinstance(l2[1], py.test.Function)
assert l2[0].name == '[0]'
@@ -148,7 +156,10 @@
def check_method(self):
assert 23 == 23
""")
+ print "tmpdir", tmpdir
+ print "o", o
from py.__impl__.test.collect import getfscollector
items = list(getfscollector(o).iteritems())
+ print items
assert len(items) == 2
assert items[1].__class__.__name__ == 'MyFunction'
Modified: py/branch/py-collect/test/testing/test_session.py
==============================================================================
--- py/branch/py-collect/test/testing/test_session.py (original)
+++ py/branch/py-collect/test/testing/test_session.py Sat Apr 9 23:42:52 2005
@@ -133,4 +133,4 @@
item, result = l[-1]
assert item.name == 'test_4'
names = item.listnames()
- assert names == ['test_drive', 'ordertest', 'test_orderofexecution.py', 'Testmygroup', '()', 'test_4']
+ assert names == ['ordertest', 'test_orderofexecution.py', 'Testmygroup', '()', 'test_4']
More information about the pytest-commit
mailing list