[pypy-svn] r28791 - in pypy/dist/pypy: doc translator
hpk at codespeak.net
hpk at codespeak.net
Wed Jun 14 20:37:21 CEST 2006
Author: hpk
Date: Wed Jun 14 20:37:20 2006
New Revision: 28791
Modified:
pypy/dist/pypy/doc/conftest.py
pypy/dist/pypy/doc/getting-started.txt
pypy/dist/pypy/translator/interactive.py
Log:
adding an "--enable-doctests" option which
looks into .txt files and runs doctests.
See getting-started for examples, but note
that not all tests are passing. It's only
rough support but it helps already to find
bugs ... and i recommend to pipe-to-less and
read from top-to-button :)
The support calls doctests internally, of course.
i also took the freedom to unify translator.js_source()
(to prevent it from printing directly to stdout),
makes one more doctest pass :)
Modified: pypy/dist/pypy/doc/conftest.py
==============================================================================
--- pypy/dist/pypy/doc/conftest.py (original)
+++ pypy/dist/pypy/doc/conftest.py Wed Jun 14 20:37:20 2006
@@ -6,13 +6,18 @@
Option('--generate-redirections', action="store_true",
dest="generateredirections",
default=False, help="Generate the redirecting HTML files"),
+ Option('--enable-doctests', action="store_true",
+ dest="doctests",
+ default=False, help="enable doctests in .txt files"),
)
class PyPyDoctestText(DoctestText):
def run(self):
+ if not option.doctests:
+ py.test.skip("specify --enable-doctests to run doctests")
# XXX refine doctest support with respect to scoping
- return
+ return super(PyPyDoctestText, self).run()
def execute(self, module, docstring):
# XXX execute PyPy prompts as well
Modified: pypy/dist/pypy/doc/getting-started.txt
==============================================================================
--- pypy/dist/pypy/doc/getting-started.txt (original)
+++ pypy/dist/pypy/doc/getting-started.txt Wed Jun 14 20:37:20 2006
@@ -422,10 +422,12 @@
Please see the pypy/translator/js/test directory for example unittests.
Here is a simple example to try::
+.. >>> from pypy.translator.interactive import Translation
+.. >>> from pypy.translator.test import snippet
>>> t = Translation(snippet.my_gcd)
>>> a = t.annotate([int, int])
- >>> t.source_js()
+ >>> source = t.source_js()
A slightly larger example
+++++++++++++++++++++++++
Modified: pypy/dist/pypy/translator/interactive.py
==============================================================================
--- pypy/dist/pypy/translator/interactive.py (original)
+++ pypy/dist/pypy/translator/interactive.py Wed Jun 14 20:37:20 2006
@@ -171,7 +171,7 @@
self.update_options(argtypes, kwds)
self.ensure_backend('js')
self.driver.source_js()
- print open(str(self.driver.gen.filename)).read()
+ return open(str(self.driver.gen.filename)).read()
def source_cl(self, argtypes=None, **kwds):
self.update_options(argtypes, kwds)
More information about the Pypy-commit
mailing list