[svn r57754] * introduce py.test.collect.File (File for py or non-py files)
* introduce py.test.collect.Collector.collect_by_name and special case it for Directories to allow specifying files that would otherwise be ignored because of filters. * fix py/doc/conftest to work with new API * refactor py/doc/test_conftest.py to use suptest helper * avoid old APIs in some more places. --HG-- branch : trunk
This commit is contained in:
+3
-5
@@ -43,15 +43,13 @@ py.apigen
|
||||
|
||||
- make it work again
|
||||
|
||||
- py.apigen tool -> separate runtime-data collection and
|
||||
web page generation. (see M750), provide "py.apigen" tool
|
||||
|
||||
- refactor html renderer to work on intermediate
|
||||
data/files rather than on the live data
|
||||
see apigen_refactorings.txt
|
||||
|
||||
- check out CodeInvestigator
|
||||
http://codeinvestigator.googlepages.com/main
|
||||
|
||||
or other code that collects data from running a program
|
||||
(in our case running the tests)
|
||||
|
||||
ld (review and shift to above)
|
||||
=================================
|
||||
|
||||
+20
-41
@@ -110,12 +110,12 @@ def _checkskip(lpath, htmlpath=None):
|
||||
#return [] # no need to rebuild
|
||||
|
||||
class ReSTSyntaxTest(py.test.collect.Item):
|
||||
def execute(self):
|
||||
def runtest(self):
|
||||
mypath = self.fspath
|
||||
restcheck(py.path.svnwc(mypath))
|
||||
|
||||
class DoctestText(py.test.collect.Item):
|
||||
def execute(self):
|
||||
def runtest(self):
|
||||
s = self._normalize_linesep()
|
||||
l = []
|
||||
prefix = '.. >>> '
|
||||
@@ -158,20 +158,15 @@ class DoctestText(py.test.collect.Item):
|
||||
return s
|
||||
|
||||
class LinkCheckerMaker(py.test.collect.Collector):
|
||||
def listdir(self):
|
||||
l = []
|
||||
def collect(self):
|
||||
l = []
|
||||
for call, tryfn, path, lineno in genlinkchecks(self.fspath):
|
||||
l.append("%s:%d" %(tryfn, lineno))
|
||||
name = "%s:%d" %(tryfn, lineno)
|
||||
l.append(
|
||||
CheckLink(name, parent=self, args=(tryfn, path, lineno), callobj=call)
|
||||
)
|
||||
return l
|
||||
|
||||
def join(self, name):
|
||||
i = name.rfind(':')
|
||||
assert i != -1
|
||||
jname, jlineno = name[:i], int(name[i+1:])
|
||||
for call, tryfn, path, lineno in genlinkchecks(self.fspath):
|
||||
if tryfn == jname and lineno == jlineno:
|
||||
return CheckLink(name, parent=self, args=(tryfn, path, lineno), callobj=call)
|
||||
|
||||
class CheckLink(py.test.collect.Function):
|
||||
def repr_metainfo(self):
|
||||
return self.ReprMetaInfo(fspath=self.fspath, lineno=self._args[2],
|
||||
@@ -181,26 +176,17 @@ class CheckLink(py.test.collect.Function):
|
||||
def teardown(self):
|
||||
pass
|
||||
|
||||
class ReSTChecker(py.test.collect.Module):
|
||||
class DocfileTests(py.test.collect.File):
|
||||
DoctestText = DoctestText
|
||||
ReSTSyntaxTest = ReSTSyntaxTest
|
||||
LinkCheckerMaker = LinkCheckerMaker
|
||||
|
||||
def __repr__(self):
|
||||
return py.test.collect.Collector.__repr__(self)
|
||||
|
||||
def setup(self):
|
||||
pass
|
||||
def teardown(self):
|
||||
pass
|
||||
def listdir(self):
|
||||
return [self.fspath.basename, 'checklinks', 'doctest']
|
||||
def join(self, name):
|
||||
if name == self.fspath.basename:
|
||||
return self.ReSTSyntaxTest(name, parent=self)
|
||||
elif name == 'checklinks':
|
||||
return LinkCheckerMaker(name, self)
|
||||
elif name == 'doctest':
|
||||
return self.DoctestText(name, self)
|
||||
def collect(self):
|
||||
return [
|
||||
self.ReSTSyntaxTest(self.fspath.basename, parent=self),
|
||||
self.LinkCheckerMaker("checklinks", self),
|
||||
self.DoctestText("doctest", self),
|
||||
]
|
||||
|
||||
# generating functions + args as single tests
|
||||
def genlinkchecks(path):
|
||||
@@ -286,20 +272,13 @@ def localrefcheck(tryfn, path, lineno):
|
||||
# hooking into py.test Directory collector's chain ...
|
||||
|
||||
class DocDirectory(py.test.collect.Directory):
|
||||
ReSTChecker = ReSTChecker
|
||||
|
||||
def listdir(self):
|
||||
results = super(DocDirectory, self).listdir()
|
||||
DocfileTests = DocfileTests
|
||||
def collect(self):
|
||||
results = super(DocDirectory, self).collect()
|
||||
for x in self.fspath.listdir('*.txt', sort=True):
|
||||
results.append(x.basename)
|
||||
results.append(self.DocfileTests(x, parent=self))
|
||||
return results
|
||||
|
||||
def join(self, name):
|
||||
if not name.endswith('.txt'):
|
||||
return super(DocDirectory, self).join(name)
|
||||
p = self.fspath.join(name)
|
||||
if p.check(file=1):
|
||||
return self.ReSTChecker(p, parent=self)
|
||||
Directory = DocDirectory
|
||||
|
||||
def resolve_linkrole(name, text, check=True):
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
|
||||
import py
|
||||
failure_demo = py.magic.autopath().dirpath('failure_demo.py')
|
||||
from py.__.doc.test_conftest import countoutcomes
|
||||
|
||||
from py.__.test.testing import suptest
|
||||
from py.__.test import event
|
||||
|
||||
def test_failure_demo_fails_properly():
|
||||
config = py.test.config._reparse([failure_demo])
|
||||
session = config.initsession()
|
||||
failed, passed, skipped = countoutcomes(session)
|
||||
assert failed == 21
|
||||
sorter = suptest.events_from_cmdline([failure_demo])
|
||||
passed, skipped, failed = sorter.countoutcomes()
|
||||
assert passed == 0
|
||||
assert failed == 20, failed
|
||||
colreports = sorter.get(event.CollectionReport)
|
||||
failed = len([x.failed for x in colreports])
|
||||
assert failed == 5
|
||||
|
||||
+62
-95
@@ -1,74 +1,80 @@
|
||||
|
||||
import py
|
||||
from py.__.test import event
|
||||
from py.__.test.testing import suptest
|
||||
from py.__.doc import conftest as doc_conftest
|
||||
|
||||
def setup_module(mod):
|
||||
mod.tmpdir = py.test.ensuretemp('docdoctest')
|
||||
|
||||
def countoutcomes(session):
|
||||
l = []
|
||||
session.bus.subscribe(l.append)
|
||||
session.main()
|
||||
session.bus.unsubscribe(l.append)
|
||||
passed = failed = skipped = 0
|
||||
for ev in l:
|
||||
if isinstance(ev, event.ItemTestReport):
|
||||
if ev.passed:
|
||||
passed += 1
|
||||
elif ev.skipped:
|
||||
skipped += 1
|
||||
else:
|
||||
failed += 1
|
||||
elif isinstance(ev, event.CollectionReport):
|
||||
if ev.failed:
|
||||
failed += 1
|
||||
return failed, passed, skipped
|
||||
class TestDoctest(suptest.InlineCollection):
|
||||
def setup_method(self, method):
|
||||
super(TestDoctest, self).setup_method(method)
|
||||
p = py.path.local(doc_conftest.__file__)
|
||||
if p.ext == ".pyc":
|
||||
p = p.new(ext=".py")
|
||||
p.copy(self.tmpdir.join("conftest.py"))
|
||||
|
||||
def test_doctest_extra_exec(self):
|
||||
xtxt = self.maketxtfile(x="""
|
||||
hello::
|
||||
.. >>> raise ValueError
|
||||
>>> None
|
||||
""")
|
||||
sorter = suptest.events_from_cmdline([xtxt])
|
||||
passed, skipped, failed = sorter.countoutcomes()
|
||||
assert failed == 1
|
||||
|
||||
def test_doctest_extra_exec():
|
||||
# XXX get rid of the next line:
|
||||
py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))
|
||||
xtxt = tmpdir.join('y.txt')
|
||||
xtxt.write(py.code.Source("""
|
||||
hello::
|
||||
.. >>> raise ValueError
|
||||
>>> None
|
||||
"""))
|
||||
config = py.test.config._reparse([xtxt])
|
||||
session = config.initsession()
|
||||
failed, passed, skipped = countoutcomes(session)
|
||||
assert failed == 1
|
||||
def test_doctest_basic(self):
|
||||
xtxt = self.maketxtfile(x="""
|
||||
..
|
||||
>>> from os.path import abspath
|
||||
|
||||
def test_doctest_basic():
|
||||
# XXX get rid of the next line:
|
||||
py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))
|
||||
hello world
|
||||
|
||||
xtxt = tmpdir.join('x.txt')
|
||||
xtxt.write(py.code.Source("""
|
||||
..
|
||||
>>> from os.path import abspath
|
||||
>>> assert abspath
|
||||
>>> i=3
|
||||
>>> print i
|
||||
3
|
||||
|
||||
hello world
|
||||
yes yes
|
||||
|
||||
>>> assert abspath
|
||||
>>> i=3
|
||||
>>> print i
|
||||
3
|
||||
>>> i
|
||||
3
|
||||
|
||||
yes yes
|
||||
end
|
||||
""")
|
||||
sorter = suptest.events_from_cmdline([xtxt])
|
||||
passed, skipped, failed = sorter.countoutcomes()
|
||||
assert failed == 0
|
||||
assert passed + skipped == 2
|
||||
|
||||
>>> i
|
||||
3
|
||||
def test_doctest_eol(self):
|
||||
ytxt = self.maketxtfile(y=".. >>> 1 + 1\r\n 2\r\n\r\n")
|
||||
sorter = suptest.events_from_cmdline([ytxt])
|
||||
passed, skipped, failed = sorter.countoutcomes()
|
||||
assert failed == 0
|
||||
assert passed + skipped == 2
|
||||
|
||||
end
|
||||
"""))
|
||||
config = py.test.config._reparse([xtxt])
|
||||
session = config.initsession()
|
||||
failed, passed, skipped = countoutcomes(session)
|
||||
assert failed == 0
|
||||
assert passed + skipped == 2
|
||||
def test_doctest_indentation(self):
|
||||
footxt = self.maketxtfile(foo=
|
||||
'..\n >>> print "foo\\n bar"\n foo\n bar\n')
|
||||
sorter = suptest.events_from_cmdline([footxt])
|
||||
passed, skipped, failed = sorter.countoutcomes()
|
||||
assert failed == 0
|
||||
assert skipped + passed == 2
|
||||
|
||||
def test_js_ignore(self):
|
||||
xtxt = self.maketxtfile(xtxt="""
|
||||
`blah`_
|
||||
|
||||
.. _`blah`: javascript:some_function()
|
||||
""")
|
||||
sorter = suptest.events_from_cmdline([xtxt])
|
||||
passed, skipped, failed = sorter.countoutcomes()
|
||||
assert failed == 0
|
||||
assert skipped + passed == 3
|
||||
|
||||
def test_deindent():
|
||||
from py.__.doc.conftest import deindent
|
||||
deindent = doc_conftest.deindent
|
||||
assert deindent('foo') == 'foo'
|
||||
assert deindent('foo\n bar') == 'foo\n bar'
|
||||
assert deindent(' foo\n bar\n') == 'foo\nbar\n'
|
||||
@@ -76,45 +82,6 @@ def test_deindent():
|
||||
assert deindent(' foo\n bar\n') == 'foo\n bar\n'
|
||||
assert deindent(' foo\n bar\n') == ' foo\nbar\n'
|
||||
|
||||
def test_doctest_eol():
|
||||
# XXX get rid of the next line:
|
||||
py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))
|
||||
|
||||
ytxt = tmpdir.join('y.txt')
|
||||
ytxt.write(py.code.Source(".. >>> 1 + 1\r\n 2\r\n\r\n"))
|
||||
config = py.test.config._reparse([ytxt])
|
||||
session = config.initsession()
|
||||
failed, passed, skipped = countoutcomes(session)
|
||||
assert failed == 0
|
||||
assert passed + skipped == 2
|
||||
|
||||
def test_doctest_indentation():
|
||||
# XXX get rid of the next line:
|
||||
py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))
|
||||
|
||||
txt = tmpdir.join('foo.txt')
|
||||
txt.write('..\n >>> print "foo\\n bar"\n foo\n bar\n')
|
||||
config = py.test.config._reparse([txt])
|
||||
session = config.initsession()
|
||||
failed, passed, skipped = countoutcomes(session)
|
||||
assert failed == 0
|
||||
assert skipped + passed == 2
|
||||
|
||||
def test_js_ignore():
|
||||
py.magic.autopath().dirpath('conftest.py').copy(tmpdir.join('conftest.py'))
|
||||
tmpdir.ensure('__init__.py')
|
||||
xtxt = tmpdir.join('x.txt')
|
||||
xtxt.write(py.code.Source("""
|
||||
`blah`_
|
||||
|
||||
.. _`blah`: javascript:some_function()
|
||||
"""))
|
||||
config = py.test.config._reparse([xtxt])
|
||||
session = config.initsession()
|
||||
|
||||
failed, passed, skipped = countoutcomes(session)
|
||||
assert failed == 0
|
||||
assert skipped + passed == 3
|
||||
|
||||
def test_resolve_linkrole():
|
||||
from py.__.doc.conftest import get_apigen_relpath
|
||||
|
||||
Reference in New Issue
Block a user