[py-svn] r33638 - in py/dist/py/test: . rsession rsession/testing
fijal at codespeak.net
fijal at codespeak.net
Tue Oct 24 11:22:26 CEST 2006
Author: fijal
Date: Tue Oct 24 11:22:24 2006
New Revision: 33638
Modified:
py/dist/py/test/defaultconftest.py
py/dist/py/test/rsession/local.py
py/dist/py/test/rsession/rsession.py
py/dist/py/test/rsession/testing/test_lsession.py
Log:
Added some new runners. Warning, for apigen runner this is intermediate checkin (it can go away as well).
Modified: py/dist/py/test/defaultconftest.py
==============================================================================
--- py/dist/py/test/defaultconftest.py (original)
+++ py/dist/py/test/defaultconftest.py Tue Oct 24 11:22:24 2006
@@ -22,9 +22,9 @@
Option('-s', '--nocapture',
action="store_true", dest="nocapture", default=False,
help="disable catching of sys.stdout/stderr output."),
- Option('-k',
+ Option('-k',
action="store", dest="keyword", default='',
- help="only run test items matching the given (google-style) keyword expression"),
+ help="only run test items matching the given (google-style) keyword expression"),
Option('-l', '--showlocals',
action="store_true", dest="showlocals", default=False,
help="show locals in tracebacks (disabled by default)"),
@@ -40,13 +40,17 @@
help="don't cut any tracebacks (default is to cut)"),
Option('', '--nomagic',
action="store_true", dest="nomagic", default=False,
- help="refrain from using magic as much as possible"),
+ help="refrain from using magic as much as possible"),
Option('', '--collectonly',
action="store_true", dest="collectonly", default=False,
help="only collect tests, don't execute them. "),
Option('', '--traceconfig',
action="store_true", dest="traceconfig", default=False,
- help="trace considerations of conftest.py files. "),
+ help="trace considerations of conftest.py files. "),
+ Option('', '--apigen',
+ action="store_true", dest="apigen", default=False,
+ help="Generated API docs out of tests. Needs to have defined"\
+ "__package__ for module or overwritten in conftest")
)
py.test.Config.addoptions('test-session related options',
Option('', '--tkinter',
Modified: py/dist/py/test/rsession/local.py
==============================================================================
--- py/dist/py/test/rsession/local.py (original)
+++ py/dist/py/test/rsession/local.py Tue Oct 24 11:22:24 2006
@@ -6,21 +6,44 @@
from py.__.test.rsession import report
from py.__.test.rsession.outcome import ReprOutcome
-def box_runner(item, config, reporter):
+# XXX copied from session.py
+def startcapture(session):
+ if not session.config.option.nocapture and not session.config.option.usepdb:
+ # XXX refactor integrate capturing
+ from py.__.misc.simplecapture import SimpleOutErrCapture
+ session._capture = SimpleOutErrCapture()
+
+def finishcapture(session):
+ if hasattr(session, '_capture'):
+ capture = session._capture
+ del session._capture
+ return capture.reset()
+ return "", ""
+
+def box_runner(item, session, reporter):
r = BoxExecutor(item)
return ReprOutcome(r.execute())
-def plain_runner(item, config, reporter):
- r = RunExecutor(item, usepdb=config.option.usepdb, reporter=reporter)
- return ReprOutcome(r.execute().make_repr())
+def plain_runner(item, session, reporter):
+ # box executor is doing stdout/err catching for us, let's do it here
+ startcapture(session)
+ r = RunExecutor(item, usepdb=session.config.option.usepdb, reporter=reporter)
+ outcome = r.execute()
+ outcome = ReprOutcome(outcome.make_repr())
+ outcome.stdout, outcome.stderr = finishcapture(session)
+ return outcome
-def benchmark_runner(item, config, reporter):
+def benchmark_runner(item, session, reporter):
raise NotImplementedError()
-def apigen_runner(item, config, reporter):
- raise NotImplementedError()
+def apigen_runner(item, session, reporter):
+ r = RunExecutor(item, reporter=reporter)
+ session.tracer.start_tracing()
+ retval = plain_runner(item, session, reporter)
+ session.tracer.end_tracing()
+ return retval
-def exec_runner(item, config, reporter):
+def exec_runner(item, session, reporter):
raise NotImplementedError()
# runner interface is here to perform several different types of run
@@ -30,15 +53,18 @@
#-3. exec_runner - for running under different interpreter
#-4. benchmark_runner - for running with benchmarking
#-5. apigen_runner - for running under apigen to generate api out of it.
-def local_loop(reporter, itemgenerator, shouldstop, config, runner=None):
+def local_loop(session, reporter, itemgenerator, shouldstop, config, runner=None):
if runner is None:
- runner = box_runner
+ if session.config.option.apigen:
+ runner = apigen_runner
+ else:
+ runner = box_runner
while 1:
try:
item = itemgenerator.next()
if shouldstop():
return
- outcome = runner(item, config, reporter)
+ outcome = runner(item, session, reporter)
reporter(report.ReceivedItemOutcome(None, item, outcome))
except StopIteration:
break
Modified: py/dist/py/test/rsession/rsession.py
==============================================================================
--- py/dist/py/test/rsession/rsession.py (original)
+++ py/dist/py/test/rsession/rsession.py Tue Oct 24 11:22:24 2006
@@ -42,6 +42,7 @@
self.failed = dict([(host, 0) for host in hosts])
self.skipped = dict([(host, 0) for host in hosts])
self.passed = dict([(host, 0) for host in hosts])
+ # XXX: This is for tests to work
self.count = 0
self.lgt = 1000
@@ -421,9 +422,11 @@
""" Local version of session
"""
def main(self, args, reporter=None, runner=None, shouldstop=None):
+ # check out if used options makes any sense
+
if not args:
args = [py.path.local()]
-
+
sshhosts = ['localhost'] # this is just an info to reporter
if not self.config.option.nomagic:
@@ -438,6 +441,15 @@
pkgdir = self.getpkgdir(args[0])
colitems = self.make_colitems(args, baseon=pkgdir.dirpath())
reporter(report.RsyncFinished())
+
+ if self.config.option.apigen:
+ from py.__.apigen.tracer.docstorage import DocStorage
+ from py.__.apigen.tracer.tracer import Tracer
+ # XXX
+ module = py
+ #module = __import__(str(pkgdir.join('__init__.py')))
+ self.docstorage = DocStorage().from_pkg(module)
+ self.tracer = Tracer(self.docstorage)
keyword = self.config.option.keyword
@@ -450,9 +462,9 @@
#assert 0, "\n".join([",".join(x.listnames()) for x in
# list(itemgenerator)])
# XXX: We have to decide which runner to use at this point
- if runner is None and self.config.option.usepdb:
+ if runner is None and (self.config.option.usepdb or self.config.option.nocapture):
runner = plain_runner
- local_loop(reporter, itemgenerator, checkfun, self.config, runner=runner)
+ local_loop(self, reporter, itemgenerator, checkfun, self.config, runner=runner)
reporter(report.TestFinished())
if startserverflag:
@@ -462,3 +474,8 @@
#py.test.Function.state.teardown_all()
if not self.config.option.nomagic:
py.magic.revoke(assertion=1)
+
+ if self.config.option.apigen:
+ from py.__.apigen.rest.genrest import DirectPaste, RestGen, DirWriter
+ RestGen(self.docstorage, DirectPaste(), DirWriter()).write()
+
Modified: py/dist/py/test/rsession/testing/test_lsession.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_lsession.py (original)
+++ py/dist/py/test/rsession/testing/test_lsession.py Tue Oct 24 11:22:24 2006
@@ -243,3 +243,24 @@
assert len(failevents) == 1
assert len(testevents) == 1
assert failevents[0].outcome.excinfo.value == 'assert [0] == [1, 2]'
+
+ def test_nocapture(self):
+ tmpdir = tmp
+ tmpdir.ensure("sub7", "__init__.py")
+ tmpdir.ensure("sub7", "test_nocap.py").write(py.code.Source("""
+ def test_one():
+ print 1
+ print 2
+ print 3
+ """))
+ args = [str(tmpdir.join("sub7"))]
+ config, args = py.test.Config.parse(args)
+ lsession = LSession(config)
+ allevents = []
+ lsession.main(args, reporter=allevents.append, runner=plain_runner)
+ testevents = [x for x in allevents
+ if isinstance(x, report.ReceivedItemOutcome)]
+ assert len(testevents) == 1
+ assert testevents[0].outcome.passed
+ assert testevents[0].outcome.stderr == ""
+ assert testevents[0].outcome.stdout == "1\n2\n3\n"
More information about the pytest-commit
mailing list