[Zope3-checkins] SVN: zope.testing/trunk/src/zope/testing/ Fixed a bug which prevented error reporting when there were unicode characters

Christian Zagrodnick cz at gocept.com
Wed May 23 11:36:36 EDT 2007


Log message for revision 75909:
  Fixed a bug which prevented error reporting when there were unicode characters
  in the error. By prevented I mean the testrunner to die. 
  
  

Changed:
  U   zope.testing/trunk/src/zope/testing/doctest.py
  U   zope.testing/trunk/src/zope/testing/testrunner-errors.txt
  A   zope.testing/trunk/src/zope/testing/testrunner-ex/unicode.py
  A   zope.testing/trunk/src/zope/testing/testrunner-ex/unicode.txt

-=-
Modified: zope.testing/trunk/src/zope/testing/doctest.py
===================================================================
--- zope.testing/trunk/src/zope/testing/doctest.py	2007-05-23 15:01:53 UTC (rev 75908)
+++ zope.testing/trunk/src/zope/testing/doctest.py	2007-05-23 15:36:35 UTC (rev 75909)
@@ -2300,11 +2300,15 @@
 
         runner = DocTestRunner(optionflags=optionflags,
                                checker=self._dt_checker, verbose=False)
+        def write(value):
+            if isinstance(value, unicode):
+                value = value.encode('utf8')
+            new.write(value)
 
         try:
             runner.DIVIDER = "-"*70
             failures, tries = runner.run(
-                test, out=new.write, clear_globs=False)
+                test, out=write, clear_globs=False)
         finally:
             sys.stdout = old
 

Modified: zope.testing/trunk/src/zope/testing/testrunner-errors.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-errors.txt	2007-05-23 15:01:53 UTC (rev 75908)
+++ zope.testing/trunk/src/zope/testing/testrunner-errors.txt	2007-05-23 15:36:35 UTC (rev 75909)
@@ -894,6 +894,46 @@
       sample2.sample23.sampletests_i
     True
 
+
+Unicode Errors
+--------------
+
+There was a bug preventing decent error reporing when a result contained
+unicode and another not::
+
+    >>> sys.argv = 'test --tests-pattern ^unicode$ -uv'.split()
+    >>> testrunner.run(defaults)
+    Running tests at level 1
+    Running unit tests:
+      Running:
+    ..
+    <BLANKLINE>
+    Failure testrunner-ex/unicode.txt
+    Failed doctest test for unicode.txt
+     testrunner-ex/unicode.txt", line 0
+    <BLANKLINE>
+    ----------------------------------------------------------------------
+    File testrunner-ex/unicode.txt", Line NNN, in unicode.txt
+    Failed example:
+        print get_unicode()
+    Expected:
+        oink
+    Got:
+        foo — bar
+    ----------------------------------------------------------------------
+    File testrunner-ex/unicode.txt", Line NNN, in unicode.txt
+    Failed example:
+        'xyz'
+    Expected:
+        123
+    Got:
+        'xyz'
+    <BLANKLINE>
+    <BLANKLINE>
+      Ran 2 tests with 1 failures and 0 errors in N.NNN seconds.
+    True
+
+ 
 Reporting Errors to Calling Processes
 -------------------------------------
 

Added: zope.testing/trunk/src/zope/testing/testrunner-ex/unicode.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-ex/unicode.py	                        (rev 0)
+++ zope.testing/trunk/src/zope/testing/testrunner-ex/unicode.py	2007-05-23 15:36:35 UTC (rev 75909)
@@ -0,0 +1,18 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+from zope.testing import doctest
+
+def test_suite():
+    return doctest.DocFileSuite('unicode.txt')


Property changes on: zope.testing/trunk/src/zope/testing/testrunner-ex/unicode.py
___________________________________________________________________
Name: svn:keywords
   + Id Rev Date
Name: svn:eol-style
   + native

Added: zope.testing/trunk/src/zope/testing/testrunner-ex/unicode.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-ex/unicode.txt	                        (rev 0)
+++ zope.testing/trunk/src/zope/testing/testrunner-ex/unicode.txt	2007-05-23 15:36:35 UTC (rev 75909)
@@ -0,0 +1,18 @@
+=========================
+Errors Containing Unicode
+=========================
+
+There was a unicode bug. Create a function which returns a unicode string with
+non us-ascii characters::
+
+    >>> def get_unicode():
+    ...    return u'foo \u2014 bar'
+    >>> print get_unicode()
+    oink
+
+Get some normal output as well::
+
+    >>> 'xyz'
+    123
+
+


Property changes on: zope.testing/trunk/src/zope/testing/testrunner-ex/unicode.txt
___________________________________________________________________
Name: svn:keywords
   + Id Rev Date
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list