[Checkins] SVN: manuel/trunk/ - Manuel no longer uses the now depricated zope.testing.doctest (requires
Benji York
benji at zope.com
Tue May 18 20:50:11 EDT 2010
Log message for revision 112499:
- Manuel no longer uses the now depricated zope.testing.doctest (requires
zope.testing 3.9.1 or newer)
Changed:
U manuel/trunk/CHANGES.txt
U manuel/trunk/buildout.cfg
U manuel/trunk/setup.py
U manuel/trunk/src/manuel/README.txt
U manuel/trunk/src/manuel/bugs.txt
U manuel/trunk/src/manuel/doctest.py
U manuel/trunk/src/manuel/testing.py
U manuel/trunk/src/manuel/tests.py
-=-
Modified: manuel/trunk/CHANGES.txt
===================================================================
--- manuel/trunk/CHANGES.txt 2010-05-18 22:40:05 UTC (rev 112498)
+++ manuel/trunk/CHANGES.txt 2010-05-19 00:50:11 UTC (rev 112499)
@@ -6,6 +6,8 @@
- fix a SyntaxError when running the tests under Python 2.5
- improved error message for improperly indented capture directive
+- Manuel no longer uses the now depricated zope.testing.doctest (requires
+ zope.testing 3.9.1 or newer)
1.0.5 (2010-01-29)
Modified: manuel/trunk/buildout.cfg
===================================================================
--- manuel/trunk/buildout.cfg 2010-05-18 22:40:05 UTC (rev 112498)
+++ manuel/trunk/buildout.cfg 2010-05-19 00:50:11 UTC (rev 112499)
@@ -53,5 +53,6 @@
zc.buildout = 1.2.1
zc.recipe.egg = 1.2.2
zc.recipe.testrunner = 1.2.0
+zope.exceptions = 3.6.0
zope.interface = 3.5.1
-zope.testing = 3.7.5
+zope.testing = 3.9.1
Modified: manuel/trunk/setup.py
===================================================================
--- manuel/trunk/setup.py 2010-05-18 22:40:05 UTC (rev 112498)
+++ manuel/trunk/setup.py 2010-05-19 00:50:11 UTC (rev 112499)
@@ -20,7 +20,7 @@
license='ZPL',
install_requires=[
'setuptools',
- 'zope.testing',
+ 'zope.testing >= 3.9.1',
],
include_package_data=True,
long_description = long_description,
Modified: manuel/trunk/src/manuel/README.txt
===================================================================
--- manuel/trunk/src/manuel/README.txt 2010-05-18 22:40:05 UTC (rev 112498)
+++ manuel/trunk/src/manuel/README.txt 2010-05-19 00:50:11 UTC (rev 112499)
@@ -223,7 +223,7 @@
>>> for region in document:
... print (region.lineno, region.parsed or region.source)
(1, 'This is my\ndoctest.\n\n')
- (4, <zope.testing.doctest.Example instance at 0x...>)
+ (4, <doctest.Example instance at 0x...>)
Now we can evaluate the examples.
Modified: manuel/trunk/src/manuel/bugs.txt
===================================================================
--- manuel/trunk/src/manuel/bugs.txt 2010-05-18 22:40:05 UTC (rev 112498)
+++ manuel/trunk/src/manuel/bugs.txt 2010-05-19 00:50:11 UTC (rev 112499)
@@ -28,68 +28,6 @@
[<manuel.Region object at ...]
-Doctest Doppelganger
---------------------
-
-The manuel.doctest module should be willing to run doctest Examples from either
-the standard library's doctest module, from zope.testing.doctest, or from
-subclasses of those.
-
-Here's a failing test we'll use to make sure this works::
-
- This is my failing doctest.
-
- >>> 1 + 1
- 42
-
-.. -> source
-
- >>> document = manuel.Document(source)
-
-First we'll show that it fails using the normal Manuel pieces.
-
- >>> m = manuel.doctest.Manuel()
- >>> document.process_with(m, globs={})
- >>> print document.formatted(),
- File "<memory>", line 3, in <memory>
- Failed example:
- 1 + 1
- Expected:
- 42
- Got:
- 2
-
-Now we'll create a subclass of zope.testing.doctest.Example, it should work too
-(but didn't at one point).
-
-.. code-block: python
-
- import zope.testing.doctest
-
- class MyExample(zope.testing.doctest.Example):
- pass
-
-Now if we replace the stdlib doctest.Example in the parsed document, the
-failure is still reported.
-
- >>> my_example = MyExample('2+2', '88')
- >>> region = list(document)[1]
- >>> region.parsed = my_example
- >>> region.evaluated = None
- >>> region.formatted = None
- >>> manuel.doctest.evaluate(m, region, document, {})
- >>> print region.evaluated.getvalue()
- <BLANKLINE>
- File "<memory>", line 3, in <memory>
- Failed example:
- 2+2
- Expected:
- 88
- Got:
- 4
- <BLANKLINE>
-
-
Code-block Options
------------------
Modified: manuel/trunk/src/manuel/doctest.py
===================================================================
--- manuel/trunk/src/manuel/doctest.py 2010-05-18 22:40:05 UTC (rev 112498)
+++ manuel/trunk/src/manuel/doctest.py 2010-05-19 00:50:11 UTC (rev 112499)
@@ -1,7 +1,6 @@
import StringIO
import manuel
import os.path
-import zope.testing.doctest
doctest = manuel.absolute_import('doctest')
@@ -46,10 +45,9 @@
def evaluate(m, region, document, globs):
- # If the parsed object is not a doctest Example (from either the stdlib
- # doctest or zope.testing.doctest), then we don't need to handle it.
- if not isinstance(region.parsed, doctest.Example) \
- and not isinstance(region.parsed, zope.testing.doctest.Example):
+ # If the parsed object is not a doctest Example then we don't need to
+ # handle it.
+ if not isinstance(region.parsed, doctest.Example):
return
result = DocTestResult()
Modified: manuel/trunk/src/manuel/testing.py
===================================================================
--- manuel/trunk/src/manuel/testing.py 2010-05-18 22:40:05 UTC (rev 112498)
+++ manuel/trunk/src/manuel/testing.py 2010-05-19 00:50:11 UTC (rev 112499)
@@ -1,8 +1,11 @@
+import doctest
+import inspect
import itertools
import manuel
import os.path
+import sys
import unittest
-import zope.testing.doctest
+import zope.testing.exceptions
__all__ = ['TestSuite']
@@ -36,7 +39,7 @@
results = [r.formatted for r in self.regions if r.formatted]
if results:
DIVIDER = '-'*70 + '\n'
- raise zope.testing.doctest.DocTestFailureException(
+ raise zope.testing.exceptions.DocTestFailureException(
'\n' + DIVIDER + DIVIDER.join(results))
def debug(self):
@@ -100,7 +103,32 @@
# put the region we peeked at back so the inner loop can consume it
document_iter = itertools.chain([region], document_iter)
+# copied from zope.testing.doctest
+def _module_relative_path(module, path):
+ if not inspect.ismodule(module):
+ raise TypeError('Expected a module: %r' % module)
+ if path.startswith('/'):
+ raise ValueError('Module-relative files may not have absolute paths')
+ # Find the base directory for the path.
+ if hasattr(module, '__file__'):
+ # A normal module/package
+ basedir = os.path.split(module.__file__)[0]
+ elif module.__name__ == '__main__':
+ # An interactive session.
+ if len(sys.argv)>0 and sys.argv[0] != '':
+ basedir = os.path.split(sys.argv[0])[0]
+ else:
+ basedir = os.curdir
+ else:
+ # A module w/o __file__ (this includes builtins)
+ raise ValueError("Can't resolve paths relative to the module " +
+ module + " (it has no __file__)")
+
+ # Combine the base directory and the path.
+ return os.path.join(basedir, *(path.split('/')))
+
+
def TestSuite(m, *paths, **kws):
"""A unittest suite that processes files with Manuel
@@ -133,10 +161,10 @@
TestCase_class = kws.pop('TestCase', TestCase)
# walk up the stack frame to find the module that called this function
- for depth in range(2, 5):
+ for depth in range(1, 5):
try:
- calling_module = zope.testing.doctest._normalize_module(
- None, depth=depth)
+ calling_module = \
+ sys.modules[sys._getframe(depth).f_globals['__name__']]
except KeyError:
continue
else:
@@ -146,9 +174,8 @@
if os.path.isabs(path):
abs_path = os.path.normpath(path)
else:
- abs_path = os.path.abspath(
- zope.testing.doctest._module_relative_path(
- calling_module, path))
+ abs_path = \
+ os.path.abspath(_module_relative_path(calling_module, path))
document = manuel.Document(
open(abs_path, 'U').read(), location=abs_path)
Modified: manuel/trunk/src/manuel/tests.py
===================================================================
--- manuel/trunk/src/manuel/tests.py 2010-05-18 22:40:05 UTC (rev 112498)
+++ manuel/trunk/src/manuel/tests.py 2010-05-19 00:50:11 UTC (rev 112499)
@@ -15,16 +15,13 @@
here = os.path.dirname(os.path.abspath(__file__))
def test_suite():
- optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
- checker = renormalizing.RENormalizing([
- (re.compile(r'<zope\.testing\.doctest\.'), '<doctest.'),
- ])
-
tests = ['../index.txt', 'table-example.txt', 'README.txt', 'bugs.txt',
'capture.txt']
+ optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
+
m = manuel.ignore.Manuel()
- m += manuel.doctest.Manuel(optionflags=optionflags, checker=checker)
+ m += manuel.doctest.Manuel(optionflags=optionflags)
m += manuel.codeblock.Manuel()
m += manuel.capture.Manuel()
# The apparently redundant "**dict()" is to make this code compatible with
More information about the checkins
mailing list