[svn r47584] Implement very sophisticated algorith for -k TestClass.test to work
--HG-- branch : trunk
This commit is contained in:
parent
aabae96514
commit
b97ff86b0f
|
@ -150,8 +150,8 @@ class Collector(object):
|
||||||
cur = next
|
cur = next
|
||||||
return cur
|
return cur
|
||||||
|
|
||||||
def _haskeyword(self, keyword):
|
def _keywords(self):
|
||||||
return keyword in self.name
|
return [self.name]
|
||||||
|
|
||||||
def _getmodpath(self):
|
def _getmodpath(self):
|
||||||
""" return dotted module path (relative to the containing). """
|
""" return dotted module path (relative to the containing). """
|
||||||
|
@ -176,17 +176,30 @@ class Collector(object):
|
||||||
if not keyword:
|
if not keyword:
|
||||||
return
|
return
|
||||||
chain = self.listchain()
|
chain = self.listchain()
|
||||||
for key in filter(None, keyword.split()):
|
for key in filter(None, keyword.split()):
|
||||||
eor = key[:1] == '-'
|
eor = key[:1] == '-'
|
||||||
if eor:
|
if eor:
|
||||||
key = key[1:]
|
key = key[1:]
|
||||||
if not (eor ^ self._matchonekeyword(key, chain)):
|
if not (eor ^ self._matchonekeyword(key, chain)):
|
||||||
py.test.skip("test not selected by keyword %r" %(keyword,))
|
py.test.skip("test not selected by keyword %r" %(keyword,))
|
||||||
|
|
||||||
def _matchonekeyword(self, key, chain):
|
def _matchonekeyword(self, key, chain):
|
||||||
for subitem in chain:
|
elems = key.split(".")
|
||||||
if subitem._haskeyword(key):
|
# XXX O(n^2), anyone cares?
|
||||||
return True
|
chain = [item._keywords() for item in chain if item._keywords()]
|
||||||
|
for start, _ in enumerate(chain):
|
||||||
|
if start + len(elems) > len(chain):
|
||||||
|
return False
|
||||||
|
for num, elem in enumerate(elems):
|
||||||
|
for keyword in chain[num + start]:
|
||||||
|
ok = False
|
||||||
|
if elem in keyword:
|
||||||
|
ok = True
|
||||||
|
break
|
||||||
|
if not ok:
|
||||||
|
break
|
||||||
|
if num == len(elems) - 1 and ok:
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _tryiter(self, yieldtype=None):
|
def _tryiter(self, yieldtype=None):
|
||||||
|
@ -425,7 +438,9 @@ class Instance(PyCollectorMixin, Collector):
|
||||||
return self.parent.obj()
|
return self.parent.obj()
|
||||||
def Function(self):
|
def Function(self):
|
||||||
return getattr(self.obj, 'Function',
|
return getattr(self.obj, 'Function',
|
||||||
Collector.Function.__get__(self)) # XXX for python 2.2
|
Collector.Function.__get__(self)) # XXX for python 2.2
|
||||||
|
def _keywords(self):
|
||||||
|
return []
|
||||||
Function = property(Function)
|
Function = property(Function)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ class AbstractSession(object):
|
||||||
|
|
||||||
class Session(AbstractSession):
|
class Session(AbstractSession):
|
||||||
"""
|
"""
|
||||||
A Session gets test Items from Collectors, # executes the
|
A Session gets test Items from Collectors, executes the
|
||||||
Items and sends the Outcome to the Reporter.
|
Items and sends the Outcome to the Reporter.
|
||||||
"""
|
"""
|
||||||
def shouldclose(self):
|
def shouldclose(self):
|
||||||
|
|
|
@ -55,20 +55,24 @@ def test_is_not_boxed_by_default():
|
||||||
assert not config.option.boxed
|
assert not config.option.boxed
|
||||||
|
|
||||||
class TestKeywordSelection:
|
class TestKeywordSelection:
|
||||||
def test_select_simple(self):
|
def test_select_simple(self):
|
||||||
for keyword in ['test_one', 'est_on']:
|
def check(keyword, name):
|
||||||
config = py.test.config._reparse([datadir/'filetest.py',
|
config = py.test.config._reparse([datadir/'filetest.py',
|
||||||
'-k', keyword])
|
'-s', '-k', keyword])
|
||||||
session = config._getsessionclass()(config, py.std.sys.stdout)
|
session = config._getsessionclass()(config, py.std.sys.stdout)
|
||||||
session.main()
|
session.main()
|
||||||
l = session.getitemoutcomepairs(Failed)
|
l = session.getitemoutcomepairs(Failed)
|
||||||
assert len(l) == 1
|
assert len(l) == 1
|
||||||
item = l[0][0]
|
item = l[0][0]
|
||||||
assert item.name == 'test_one'
|
assert item.name == name
|
||||||
l = session.getitemoutcomepairs(Skipped)
|
l = session.getitemoutcomepairs(Skipped)
|
||||||
assert len(l) == 1
|
assert len(l) == 1
|
||||||
|
|
||||||
def test_select_extra_keywords(self):
|
for keyword in ['test_one', 'est_on']:
|
||||||
|
check(keyword, 'test_one')
|
||||||
|
check('TestClass.test', 'test_method_one')
|
||||||
|
|
||||||
|
def test_select_extra_keywords(self):
|
||||||
o = tmpdir.ensure('selecttest', dir=1)
|
o = tmpdir.ensure('selecttest', dir=1)
|
||||||
tfile = o.join('test_select.py').write(py.code.Source("""
|
tfile = o.join('test_select.py').write(py.code.Source("""
|
||||||
def test_1():
|
def test_1():
|
||||||
|
@ -80,14 +84,13 @@ class TestKeywordSelection:
|
||||||
conftest = o.join('conftest.py').write(py.code.Source("""
|
conftest = o.join('conftest.py').write(py.code.Source("""
|
||||||
import py
|
import py
|
||||||
class Class(py.test.collect.Class):
|
class Class(py.test.collect.Class):
|
||||||
def _haskeyword(self, keyword):
|
def _keywords(self):
|
||||||
return keyword == 'xxx' or \
|
return ['xxx', self.name]
|
||||||
super(Class, self)._haskeyword(keyword)
|
|
||||||
"""))
|
"""))
|
||||||
for keyword in ('xxx', 'xxx test_2', 'TestClass', 'xxx -test_1',
|
for keyword in ('xxx', 'xxx test_2', 'TestClass', 'xxx -test_1',
|
||||||
'TestClass test_2', 'xxx TestClass test_2',):
|
'TestClass test_2', 'xxx TestClass test_2',):
|
||||||
f = py.std.StringIO.StringIO()
|
f = py.std.StringIO.StringIO()
|
||||||
config = py.test.config._reparse([o, '-k', keyword])
|
config = py.test.config._reparse([o, '-s', '-k', keyword])
|
||||||
session = config._getsessionclass()(config, f)
|
session = config._getsessionclass()(config, f)
|
||||||
session.main()
|
session.main()
|
||||||
print "keyword", repr(keyword)
|
print "keyword", repr(keyword)
|
||||||
|
|
Loading…
Reference in New Issue