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): def __hash__(self):
return hash((self.name, self.parent)) 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): def setup(self):
pass pass
@ -230,9 +223,6 @@ class Node(object):
return True return True
return False return False
def _getsortvalue(self):
return self.name
def _prunetraceback(self, traceback): def _prunetraceback(self, traceback):
return traceback return traceback

View File

@ -64,7 +64,17 @@ class FunctionCollector(py.test.collect.Collector):
function = self.parent.Function(name=name, parent=self, function = self.parent.Function(name=name, parent=self,
callspec=callspec, callobj=self.obj) callspec=callspec, callobj=self.obj)
l.append(function) 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: class FuncargRequest:
_argprefix = "pytest_funcarg__" _argprefix = "pytest_funcarg__"

View File

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

View File

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

View File

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