[py-svn] r51564 - in py/branch/event/py/test2: . testing
hpk at codespeak.net
hpk at codespeak.net
Sun Feb 17 19:49:20 CET 2008
Author: hpk
Date: Sun Feb 17 19:49:19 2008
New Revision: 51564
Modified:
py/branch/event/py/test2/collect.py
py/branch/event/py/test2/genitem.py
py/branch/event/py/test2/item.py
py/branch/event/py/test2/testing/test_collect.py
py/branch/event/py/test2/testing/test_session.py
Log:
* disambiguate Collectors and Test Items. deprecate
collector.run() in favour of collector.listdir().
* forget about one skipped test (re-running test from py/doc)
because i have not the slightest clue about it, even after
checking the revision which introduced it.
Modified: py/branch/event/py/test2/collect.py
==============================================================================
--- py/branch/event/py/test2/collect.py (original)
+++ py/branch/event/py/test2/collect.py Sun Feb 17 19:49:19 2008
@@ -34,7 +34,7 @@
return self._config.getvalue(name, self.fspath)
return property(fget)
-class Collector(object):
+class Base(object):
""" Collector instances are iteratively generated
(through their run() and join() methods)
and form a tree. attributes::
@@ -49,14 +49,6 @@
self._config = getattr(parent, '_config', py.test2.config)
self.fspath = getattr(parent, 'fspath', None)
- Module = configproperty('Module')
- DoctestFile = configproperty('DoctestFile')
- Directory = configproperty('Directory')
- Class = configproperty('Class')
- Instance = configproperty('Instance')
- Function = configproperty('Function')
- Generator = configproperty('Generator')
-
_stickyfailure = None
def __repr__(self):
@@ -78,26 +70,7 @@
s2 = other._getsortvalue()
#print "cmp", s1, s2
return cmp(s1, s2)
-
-
- def run(self):
- """ returns a list of names available from this collector.
- You can return an empty list. Callers of this method
- must take care to catch exceptions properly. The session
- object guards its calls to ``colitem.run()`` in its
- ``session.runtraced(colitem)`` method, including
- catching of stdout.
- """
- raise NotImplementedError("abstract")
-
- def join(self, name):
- """ return a child item for the given name. Usually the
- session feeds the join method with each name obtained
- from ``colitem.run()``. If the return value is None
- it means the ``colitem`` was not able to resolve
- with the given name.
- """
-
+
def obj():
def fget(self):
try:
@@ -148,7 +121,7 @@
if name:
next = cur.join(name)
if next is None:
- existingnames = cur.run()
+ existingnames = cur.listdir()
msg = ("Collector %r does not have name %r "
"existing names are: %s" %
(cur, name, existingnames))
@@ -210,6 +183,35 @@
"""
return self._config.get_collector_trail(self)
+class Collector(Base):
+ Module = configproperty('Module')
+ DoctestFile = configproperty('DoctestFile')
+ Directory = configproperty('Directory')
+ Class = configproperty('Class')
+ Instance = configproperty('Instance')
+ Function = configproperty('Function')
+ Generator = configproperty('Generator')
+
+ def run(self):
+ """ deprecated: use listdir(). """
+ py.std.warnings.warn("deprecated: use listdir()", category=DeprecationWarning)
+ return self.listdir()
+
+ def listdir(self):
+ """ returns a list of names available from this collector.
+ You can return an empty list. Callers of this method
+ must take care to catch exceptions properly.
+ """
+ raise NotImplementedError("abstract")
+
+ def join(self, name):
+ """ return a child item for the given name. Usually the
+ session feeds the join method with each name obtained
+ from ``colitem.run()``. If the return value is None
+ it means the ``colitem`` was not able to resolve
+ with the given name.
+ """
+
class FSCollector(Collector):
def __init__(self, fspath, parent=None):
fspath = py.path.local(fspath)
@@ -228,10 +230,7 @@
if path.check(dir=1, dotfile=0):
return path.basename not in ('CVS', '_darcs', '{arch}')
- def list(self):
- return [self.join(x) for x in self.run()]
-
- def run(self):
+ def listdir(self):
files = []
dirs = []
for p in self.fspath.listdir():
@@ -307,7 +306,7 @@
self._name2items_exception = py.std.sys.exc_info()
raise
- def run(self):
+ def listdir(self):
self._prepare()
itemlist = self._name2items.values()
itemlist.sort()
@@ -319,10 +318,10 @@
class Module(FSCollector, PyCollectorMixin):
- def run(self):
+ def listdir(self):
if getattr(self.obj, 'disabled', 0):
return []
- return super(Module, self).run()
+ return super(Module, self).listdir()
def join(self, name):
res = super(Module, self).join(name)
@@ -369,7 +368,7 @@
class Class(PyCollectorMixin, Collector):
- def run(self):
+ def listdir(self):
if getattr(self.obj, 'disabled', 0):
return []
return ["()"]
@@ -447,7 +446,7 @@
return meth(self.obj)
class Generator(FunctionMixin, PyCollectorMixin, Collector):
- def run(self):
+ def listdir(self):
self._prepare()
itemlist = self._name2items
return [itemlist["[%d]" % num].name for num in xrange(len(itemlist))]
@@ -473,7 +472,7 @@
return call, args
class DoctestFile(PyCollectorMixin, FSCollector):
- def run(self):
+ def listdir(self):
return [self.fspath.basename]
def join(self, name):
Modified: py/branch/event/py/test2/genitem.py
==============================================================================
--- py/branch/event/py/test2/genitem.py (original)
+++ py/branch/event/py/test2/genitem.py Sun Feb 17 19:49:19 2008
@@ -17,10 +17,11 @@
else:
yield next
else:
+ assert isinstance(next, py.test2.collect.Collector), next
bus.notify(repevent.CollectionStart(next))
excinfo = None
try:
- cols = [next.join(x) for x in next.run()]
+ cols = [next.join(x) for x in next.listdir()]
for x in genitems(config, cols, keywordexpr):
yield x
except sysex:
Modified: py/branch/event/py/test2/item.py
==============================================================================
--- py/branch/event/py/test2/item.py (original)
+++ py/branch/event/py/test2/item.py Sun Feb 17 19:49:19 2008
@@ -1,7 +1,6 @@
import py
-from py.__.test2 import outcome
-from py.__.test2.collect import FunctionMixin
+from py.__.test2.collect import FunctionMixin, Base
_dummy = object()
@@ -30,7 +29,7 @@
col.setup()
self.stack.append(col)
-class Item(py.test2.collect.Collector):
+class Item(Base):
def startcapture(self):
self._config._startcapture(self, path=self.fspath)
Modified: py/branch/event/py/test2/testing/test_collect.py
==============================================================================
--- py/branch/event/py/test2/testing/test_collect.py (original)
+++ py/branch/event/py/test2/testing/test_collect.py Sun Feb 17 19:49:19 2008
@@ -8,11 +8,26 @@
def setup_module(mod):
mod.tmpdir = py.test2.ensuretemp(mod.__name__)
+def test_collect_versus_item():
+ path = setupdata.getexamplefile("filetest.py")
+ col = py.test2.collect.Module(path)
+ assert not isinstance(col, py.test2.collect.Item)
+ item = col.join("test_one")
+ assert not hasattr(item, "join")
+ assert not isinstance(item, py.test2.collect.Collector)
+
+def test_collector_deprecated_run_method():
+ path = setupdata.getexamplefile("filetest.py")
+ col = py.test2.collect.Module(path)
+ res1 = py.test2.deprecated_call(col.run)
+ res2 = col.listdir()
+ assert res1 == res2
+
def test_failing_import_execfile():
dest = setupdata.getexamplefile('failingimport.py')
col = py.test2.collect.Module(dest)
- py.test2.raises(ImportError, col.run)
- py.test2.raises(ImportError, col.run)
+ py.test2.raises(ImportError, col.listdir)
+ py.test2.raises(ImportError, col.listdir)
def test_collect_listnames_and_back():
path = setupdata.getexamplefile("filetest.py")
@@ -31,7 +46,7 @@
def test_finds_tests():
fn = setupdata.getexamplefile('filetest.py')
col = py.test2.collect.Module(fn)
- l = col.run()
+ l = col.listdir()
assert len(l) == 2
assert l[0] == 'test_one'
assert l[1] == 'TestClass'
@@ -41,8 +56,9 @@
tmp.ensure('test_found.py')
tmp.ensure('found_test.py')
- colitem = py.test2.collect.Directory(tmp)
- items = colitem.list()
+ col = py.test2.collect.Directory(tmp)
+ items = [col.join(x) for x in col.listdir()]
+
assert len(items) == 2
assert items[1].name == 'test_found.py'
assert items[0].name == 'found_test.py'
@@ -58,7 +74,7 @@
tmp.ensure('test_found.py')
colitem = py.test2.collect.Directory(tmp)
- items = colitem.run()
+ items = colitem.listdir()
assert len(items) == 2
assert 'normal' in items
assert 'test_found.py' in items
@@ -69,46 +85,46 @@
return p.check(fnmatch='testspecial*.py')
filetest = setupdata.getexamplefile("testspecial_importerror.py")
mydir = MyDirectory(filetest.dirpath())
- l = mydir.run()
+ l = mydir.listdir()
assert len(l) == 1
- item = mydir.join(l[0])
- assert isinstance(item, py.test2.collect.Module)
- py.test2.raises(ImportError, item.run)
+ col = mydir.join(l[0])
+ assert isinstance(col, py.test2.collect.Module)
+ py.test2.raises(ImportError, col.listdir)
def test_module_file_not_found():
fn = tmpdir.join('nada','no')
col = py.test2.collect.Module(fn)
- py.test2.raises(py.error.ENOENT, col.run)
+ py.test2.raises(py.error.ENOENT, col.listdir)
def test_syntax_error_in_module():
modpath = setupdata.getexamplefile("syntax_error.py")
col = py.test2.collect.Module(modpath)
- py.test2.raises(SyntaxError, col.run)
+ py.test2.raises(SyntaxError, col.listdir)
def test_disabled_class():
col = py.test2.collect.Module(setupdata.getexamplefile('disabled.py'))
- l = col.run()
+ l = col.listdir()
assert len(l) == 1
colitem = col.join(l[0])
assert isinstance(colitem, py.test2.collect.Class)
- assert not colitem.run()
+ assert not colitem.listdir()
def test_disabled_module():
p = setupdata.getexamplefile("disabled_module.py")
col = py.test2.collect.Module(p)
- l = col.run()
+ l = col.listdir()
assert len(l) == 0
def test_generative_simple():
tfile = setupdata.getexamplefile('test_generative.py')
col = py.test2.collect.Module(tfile)
- l = col.run()
+ l = col.listdir()
assert len(l) == 2
l = col.multijoin(l)
generator = l[0]
assert isinstance(generator, py.test2.collect.Generator)
- l2 = generator.run()
+ l2 = generator.listdir()
assert len(l2) == 2
l2 = generator.multijoin(l2)
assert isinstance(l2[0], py.test2.collect.Function)
@@ -118,13 +134,13 @@
assert l2[0].obj.func_name == 'func1'
- classlist = l[1].run()
+ classlist = l[1].listdir()
assert len(classlist) == 1
classlist = l[1].multijoin(classlist)
cls = classlist[0]
- generator = cls.join(cls.run()[0])
+ generator = cls.join(cls.listdir()[0])
assert isinstance(generator, py.test2.collect.Generator)
- l2 = generator.run()
+ l2 = generator.listdir()
assert len(l2) == 2
l2 = generator.multijoin(l2)
assert isinstance(l2[0], py.test2.collect.Function)
@@ -201,22 +217,9 @@
tmpdir.ensure('adir', dir=1)
fnames.insert(10, 'adir')
col = py.test2.collect.Directory(tmpdir)
- names = col.run()
+ names = col.listdir()
assert names == fnames
-def test_documentation_virtual_collector_interaction():
- py.test.skip("figure out this test and rewrite independent of py/doc.")
- rootdir = py.path.local(py.__file__).dirpath("doc")
- # HACK
- from py.__.doc import conftest as conf
- old = conf.option.forcegen
- try:
- conf.option.forcegen = 1
- col = py.test2.collect.Directory(rootdir)
- x = list(col._tryiter(yieldtype=py.test2.collect.Function))
- finally:
- conf.option.forcegen = old
-
def test_check_random_inequality():
path = setupdata.getexamplefile("funcexamples.py")
col = py.test2.collect.Module(path)
@@ -266,7 +269,7 @@
self.tmp.ensure("subdir", "conftest.py").write(py.code.Source("""
import py
class Directory(py.test2.collect.Directory):
- def run(self):
+ def listdir(self):
py.test2.skip("intentional")
"""))
items, events = self._genitems()
@@ -397,4 +400,3 @@
items, events = self._genitems(x)
assert len(items) == 1
assert isinstance(items[0], DoctestText)
-
Modified: py/branch/event/py/test2/testing/test_session.py
==============================================================================
--- py/branch/event/py/test2/testing/test_session.py (original)
+++ py/branch/event/py/test2/testing/test_session.py Sun Feb 17 19:49:19 2008
@@ -184,7 +184,7 @@
def test_collect_only_with_various_situations(self):
p = suptest.makeuniquepyfile("""
def test_one():
- pass
+ raise ValueError()
class TestX:
def test_method_one(self):
@@ -203,9 +203,11 @@
assert not sorter.get(repevent.ItemStart)
assert not sorter.get(repevent.ItemFinish)
+ assert not sorter.get(repevent.ItemTestReport)
started = sorter.get(repevent.CollectionStart)
finished = sorter.get(repevent.CollectionFinish)
assert len(started) == len(finished)
+ assert len(started) == 8
failedcollections = sorter.getfailedcollections()
assert len(failedcollections) == 2
More information about the py-svn
mailing list