[Checkins] SVN: zope.monkeypatches.doctest/trunk/ Added three bugfixes.
Lennart Regebro
regebro at gmail.com
Thu Apr 29 12:58:19 EDT 2010
Log message for revision 111586:
Added three bugfixes.
Changed:
A zope.monkeypatches.doctest/trunk/docs/
A zope.monkeypatches.doctest/trunk/docs/HISTORY.txt
A zope.monkeypatches.doctest/trunk/docs/README.txt
A zope.monkeypatches.doctest/trunk/setup.py
A zope.monkeypatches.doctest/trunk/zope/
A zope.monkeypatches.doctest/trunk/zope/__init__.py
A zope.monkeypatches.doctest/trunk/zope/monkeypatches/
A zope.monkeypatches.doctest/trunk/zope/monkeypatches/__init__.py
A zope.monkeypatches.doctest/trunk/zope/monkeypatches/doctest/
A zope.monkeypatches.doctest/trunk/zope/monkeypatches/doctest/README.txt
A zope.monkeypatches.doctest/trunk/zope/monkeypatches/doctest/__init__.py
-=-
Added: zope.monkeypatches.doctest/trunk/docs/HISTORY.txt
===================================================================
--- zope.monkeypatches.doctest/trunk/docs/HISTORY.txt (rev 0)
+++ zope.monkeypatches.doctest/trunk/docs/HISTORY.txt 2010-04-29 16:58:18 UTC (rev 111586)
@@ -0,0 +1,7 @@
+Changelog
+=========
+
+1.0dev (unreleased)
+-------------------
+
+- Initial release
Added: zope.monkeypatches.doctest/trunk/docs/README.txt
===================================================================
--- zope.monkeypatches.doctest/trunk/docs/README.txt (rev 0)
+++ zope.monkeypatches.doctest/trunk/docs/README.txt 2010-04-29 16:58:18 UTC (rev 111586)
@@ -0,0 +1 @@
+See zope/monkeypatches/doctest/README.txt
Added: zope.monkeypatches.doctest/trunk/setup.py
===================================================================
--- zope.monkeypatches.doctest/trunk/setup.py (rev 0)
+++ zope.monkeypatches.doctest/trunk/setup.py 2010-04-29 16:58:18 UTC (rev 111586)
@@ -0,0 +1,28 @@
+from setuptools import setup, find_packages
+import os
+
+version = '1.0'
+
+setup(name='zope.monkeypatches.doctest',
+ version=version,
+ description="Bugfixes for various bugs in the doctest module.",
+ long_description=open("README.txt").read() + "\n" +
+ open(os.path.join("docs", "HISTORY.txt")).read(),
+ # Get more strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+ classifiers=[
+ "Programming Language :: Python",
+ ],
+ keywords='doctest',
+ author='Zope Foundation and Contributors',
+ author_email='zope-dev at zope.org',
+ url='http://pypi.python.org/pypi/zope.monkeypatches.doctest',
+ license='ZPL 2.1',
+ packages=find_packages(exclude=['ez_setup']),
+ namespace_packages=['zope', 'zope.monkeypatches'],
+ include_package_data=True,
+ test_suite='zope.monkeypatches.doctest.test_suite',
+ zip_safe=False,
+ install_requires=[
+ 'setuptools',
+ ],
+ )
Added: zope.monkeypatches.doctest/trunk/zope/__init__.py
===================================================================
--- zope.monkeypatches.doctest/trunk/zope/__init__.py (rev 0)
+++ zope.monkeypatches.doctest/trunk/zope/__init__.py 2010-04-29 16:58:18 UTC (rev 111586)
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
Added: zope.monkeypatches.doctest/trunk/zope/monkeypatches/__init__.py
===================================================================
--- zope.monkeypatches.doctest/trunk/zope/monkeypatches/__init__.py (rev 0)
+++ zope.monkeypatches.doctest/trunk/zope/monkeypatches/__init__.py 2010-04-29 16:58:18 UTC (rev 111586)
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
Added: zope.monkeypatches.doctest/trunk/zope/monkeypatches/doctest/README.txt
===================================================================
--- zope.monkeypatches.doctest/trunk/zope/monkeypatches/doctest/README.txt (rev 0)
+++ zope.monkeypatches.doctest/trunk/zope/monkeypatches/doctest/README.txt 2010-04-29 16:58:18 UTC (rev 111586)
@@ -0,0 +1,74 @@
+zope.monkeypatches.doctest
+==========================
+
+This product monkeypatches stdlibs doctest to get rid of bugs that
+zope.testing.doctest had fixed. It's useful if you really can't work
+around those bugs other ways.
+
+It achieves the bugfixing via monkey-patches, which is horrid, so in general
+it's better if you don't use this product.
+
+Bugfix: Unicode output
+----------------------
+
+LP #69988 and #144569 both assert that doctests fail when rendering
+non-ASCII output with a UnicodeDecodeError. However, this does not appear
+to be so:
+
+ >>> print u'abc'
+ abc
+
+ >>> print u'\xe9'.encode('utf-8')
+ é
+
+Tests for LP #561568:
+
+ >>> v = u'foo\xe9bar'
+ >>> v # doctest: +ELLIPSIS
+ u'foo...bar'
+
+ >>> v.encode('utf-8') # doctest: +ELLIPSIS
+ 'foo...bar'
+
+
+Bugfix: Inconsistent linefeeds
+------------------------------
+
+Due to the way releases are made on different platforms, we sometimes test
+files on a *nix system with Windows file endings. Unfortunately, that leaves
+some of the test files broken:
+
+ >>> import tempfile
+ >>> import os
+ >>> fd, fn = tempfile.mkstemp()
+ >>> f = os.fdopen(fd, 'wb')
+ >>> f.write('Test:\r\n\r\n >>> x = 1 + 1\r\n\r\nDone.\r\n')
+ >>> f.close()
+
+Let's now run it as a doctest:
+
+ >>> import doctest
+ >>> failed, run = doctest.testfile(fn, False)
+ >>> failed, run
+ (0, 1)
+
+It worked. Let's also try the test file suite:
+
+ >>> import unittest
+ >>> result = unittest.TestResult()
+ >>> doctest.DocFileSuite(fn, module_relative=False).run(result) #doctest: +ELLIPSIS
+ <...TestResult run=1 errors=0 failures=0>
+
+Remove the temporary test:
+
+ >>> os.remove(fn)
+
+
+Bugfix: REPORT_ONLY_FIRST_FAILURE and REPORT_xDIFF flags
+--------------------------------------------------------
+
+If you tell the testrunner that you want to report only the first failure,
+but the test is set up to have a report flag of some sort, like a REPORT_NDIFF,
+the REPORT_ONLY_FIRST_FAILURE will be ignored. That's silly, so we patch that.
+
+XXX/TODO: Write tests for it.
Added: zope.monkeypatches.doctest/trunk/zope/monkeypatches/doctest/__init__.py
===================================================================
--- zope.monkeypatches.doctest/trunk/zope/monkeypatches/doctest/__init__.py (rev 0)
+++ zope.monkeypatches.doctest/trunk/zope/monkeypatches/doctest/__init__.py 2010-04-29 16:58:18 UTC (rev 111586)
@@ -0,0 +1,70 @@
+# Patch to fix an error that makes subsequent tests fail after you have
+# returned unicode in a test.
+import doctest
+
+_org_SpoofOut = doctest._SpoofOut
+class _patched_SpoofOut(_org_SpoofOut):
+ def truncate(self, size=None):
+ _org_SpoofOut.truncate(self, size)
+ if not self.buf:
+ self.buf = ''
+
+doctest._SpoofOut = _patched_SpoofOut
+
+
+# Patch to fix tests that has mixed line endings:
+import os
+
+def _patched_load_testfile(filename, package, module_relative):
+ if module_relative:
+ package = doctest._normalize_module(package, 3)
+ filename = doctest._module_relative_path(package, filename)
+ if hasattr(package, '__loader__'):
+ if hasattr(package.__loader__, 'get_data'):
+ file_contents = package.__loader__.get_data(filename)
+ # get_data() opens files as 'rb', so one must do the equivalent
+ # conversion as universal newlines would do.
+ return file_contents.replace(os.linesep, '\n'), filename
+ return open(filename, 'rU').read(), filename
+
+doctest._load_testfile = _patched_load_testfile
+
+
+# Patch so you can set REPORT_ONLY_FIRST_FAILURE even if you have a DIFF flag
+# on the test.
+import sys
+from StringIO import StringIO
+
+def _patched_runTest(self):
+ test = self._dt_test
+ old = sys.stdout
+ new = StringIO()
+ optionflags = self._dt_optionflags
+
+ if not (optionflags & doctest.REPORTING_FLAGS):
+ # The option flags don't include any reporting flags,
+ # so add the default reporting flags
+ optionflags |= doctest._unittest_reportflags
+
+ # This should work even if you have a diff flag:
+ if doctest._unittest_reportflags & doctest.REPORT_ONLY_FIRST_FAILURE:
+ optionflags |= doctest.REPORT_ONLY_FIRST_FAILURE
+
+ runner = doctest.DocTestRunner(optionflags=optionflags,
+ checker=self._dt_checker, verbose=False)
+
+ try:
+ runner.DIVIDER = "-"*70
+ failures, tries = runner.run(
+ test, out=new.write, clear_globs=False)
+ finally:
+ sys.stdout = old
+
+ if failures:
+ raise self.failureException(self.format_failure(new.getvalue()))
+
+doctest.DocTestCase.runTest = _patched_runTest
+
+
+def test_suite():
+ return doctest.DocFileSuite('README.txt')
\ No newline at end of file
More information about the checkins
mailing list