sorting should be an option collector->child interface

--HG--
branch : trunk
This commit is contained in:
Samuele Pedroni 2009-05-19 18:28:51 +02:00
parent 842d14cd33
commit 3b23b98cb5
5 changed files with 20 additions and 34 deletions

View File

@ -79,13 +79,6 @@ class Node(object):
def __hash__(self):
return hash((self.name, self.parent))
def __cmp__(self, other):
if not isinstance(other, Node):
return -1
s1 = self._getsortvalue()
s2 = other._getsortvalue()
return cmp(s1, s2)
def setup(self):
pass
@ -230,9 +223,6 @@ class Node(object):
return True
return False
def _getsortvalue(self):
return self.name
def _prunetraceback(self, traceback):
return traceback

View File

@ -64,7 +64,17 @@ class FunctionCollector(py.test.collect.Collector):
function = self.parent.Function(name=name, parent=self,
callspec=callspec, callobj=self.obj)
l.append(function)
return l
return l
def reportinfo(self):
try:
return self._fslineno, self.name
except AttributeError:
pass
fspath, lineno = py.code.getfslineno(self.obj)
self._fslineno = fspath, lineno
return fspath, lineno, self.name
class FuncargRequest:
_argprefix = "pytest_funcarg__"

View File

@ -93,7 +93,7 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
return l
name2items = self._buildname2items()
colitems = name2items.values()
colitems.sort()
colitems.sort(key=lambda item: item.reportinfo()[:2])
return colitems
def _buildname2items(self):
@ -205,9 +205,6 @@ class Class(PyCollectorMixin, py.test.collect.Collector):
teardown_class = getattr(teardown_class, 'im_func', teardown_class)
teardown_class(self.obj)
def _getsortvalue(self):
return self._getfslineno()
class Instance(PyCollectorMixin, py.test.collect.Collector):
def _getobj(self):
return self.parent.obj()
@ -230,9 +227,6 @@ class FunctionMixin(PyobjMixin):
""" mixin for the code common to Function and Generator.
"""
def _getsortvalue(self):
return self._getfslineno()
def setup(self):
""" perform setup for this test function. """
if hasattr(self.obj, 'im_self'):

View File

@ -6,7 +6,7 @@ class TestCollector:
assert not issubclass(Collector, Item)
assert not issubclass(Item, Collector)
def test_check_equality_and_cmp_basic(self, testdir):
def test_check_equality(self, testdir):
modcol = testdir.getmodulecol("""
def test_pass(): pass
def test_fail(): assert 0
@ -25,11 +25,7 @@ class TestCollector:
assert isinstance(fn3, py.test.collect.Function)
assert not (fn1 == fn3)
assert fn1 != fn3
assert cmp(fn1, fn3) == -1
assert cmp(fn1, 10) == -1
assert cmp(fn2, 10) == -1
assert cmp(fn3, 10) == -1
for fn in fn1,fn2,fn3:
assert fn != 3
assert fn != modcol

View File

@ -269,7 +269,7 @@ class TestFunction:
assert not (f5 == f5b)
class TestSorting:
def test_check_equality_and_cmp_basic(self, testdir):
def test_check_equality(self, testdir):
modcol = testdir.getmodulecol("""
def test_pass(): pass
def test_fail(): assert 0
@ -288,11 +288,7 @@ class TestSorting:
assert isinstance(fn3, py.test.collect.Function)
assert not (fn1 == fn3)
assert fn1 != fn3
assert cmp(fn1, fn3) == -1
assert cmp(fn1, 10) == -1
assert cmp(fn2, 10) == -1
assert cmp(fn3, 10) == -1
for fn in fn1,fn2,fn3:
assert fn != 3
assert fn != modcol
@ -308,18 +304,18 @@ class TestSorting:
return g
def test_a(y):
pass
test_a = dec(test_a)
def test_b(y):
pass
test_b = dec(test_b)
def test_a(y):
pass
test_a = dec(test_a)
""")
colitems = modcol.collect()
assert len(colitems) == 2
f1, f2 = colitems
assert cmp(f2, f1) > 0
assert [item.name for item in colitems] == ['test_b', 'test_a']
class TestConftestCustomization:
def test_extra_python_files_and_functions(self, testdir):