[Zope3-checkins] SVN: zope.testing/branches/regebro-py3-3rdtimelucky/s Python 3.1 support.

Lennart Regebro regebro at gmail.com
Mon Apr 26 04:44:44 EDT 2010


Log message for revision 111414:
  Python 3.1 support.
  

Changed:
  U   zope.testing/branches/regebro-py3-3rdtimelucky/setup.py
  U   zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/doctest/__init__.py
  U   zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/doctest.txt
  U   zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/formparser.txt
  U   zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/module.txt
  U   zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/renormalizing/__init__.py
  U   zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/server.py
  U   zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/setupstack.txt
  U   zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/tests.py
  A   zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/unicode.txt

-=-
Modified: zope.testing/branches/regebro-py3-3rdtimelucky/setup.py
===================================================================
--- zope.testing/branches/regebro-py3-3rdtimelucky/setup.py	2010-04-26 08:35:12 UTC (rev 111413)
+++ zope.testing/branches/regebro-py3-3rdtimelucky/setup.py	2010-04-26 08:44:44 UTC (rev 111414)
@@ -23,6 +23,19 @@
 
 import os
 from setuptools import setup
+import sys
+if sys.version > '3':
+    extras = dict(
+    use_2to3 = True,
+    convert_2to3_doctests = ['src/zope/testing/doctest.txt',
+                             'src/zope/testing/formparser.txt',
+                             'src/zope/testing/module.txt',
+                             'src/zope/testing/setupstack.txt',
+                             ],
+    dependency_links = ['.'], # Only until zope.interface 3.6 and zope.exception 3.6 has been released.
+    )
+else:
+    extras = {}
 
 chapters = '\n'.join([
     open(os.path.join('src', 'zope', 'testing', name)).read()
@@ -58,11 +71,16 @@
         "Programming Language :: Python :: 2.4",
         "Programming Language :: Python :: 2.5",
         "Programming Language :: Python :: 2.6",
+        "Programming Language :: Python :: 2.7",
+        "Programming Language :: Python :: 3.1",
         "Topic :: Software Development :: Libraries :: Python Modules",
         "Topic :: Software Development :: Testing",
         ],
     
-    packages=["zope", "zope.testing"],
+    packages=["zope", 
+              "zope.testing", 
+              "zope.testing.doctest", 
+              "zope.testing.renormalizing"],
     package_dir = {'': 'src'},
     namespace_packages=['zope',],
     install_requires = ['setuptools',
@@ -70,5 +88,6 @@
                         'zope.interface'],
     include_package_data = True,
     zip_safe = False,
-    test_suite = 'zope.testing.tests.test_suite'
+    test_suite = 'zope.testing.tests.test_suite',
+    **extras
 )

Modified: zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/doctest/__init__.py
===================================================================
--- zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/doctest/__init__.py	2010-04-26 08:35:12 UTC (rev 111413)
+++ zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/doctest/__init__.py	2010-04-26 08:44:44 UTC (rev 111414)
@@ -54,20 +54,21 @@
 
 
 # Patch to fix an error that makes subsequent tests fail after you have
-# returned unicode in a test.
+# returned unicode in a test. This is obviously not an issue in Python 3.
 
 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 = ''
+if sys.version < '3':
+    _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
 
-doctest._SpoofOut = _patched_SpoofOut
 
-
 # Patch to fix tests that has mixed line endings:
 import os
 
@@ -145,21 +146,25 @@
     doctest.DocFileTest = _patched_DocFileTest
 else:
     
-    def _patched_load_testfile(filename, package, module_relative):
+    def _patched_load_testfile(filename, package, module_relative, encoding=None):
         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)
+                    if encoding is not None: # Python 3
+                        file_contents = file_contents.decode(encoding)
                     # 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, 'U').read(), filename
+        if encoding: # Python 3:
+            return open(filename, encoding=encoding).read(), filename
+        else:
+            return open(filename, 'U').read(), filename
     
     doctest._load_testfile = _patched_load_testfile
 
-
 # Use a special exception for the test runner:
 from zope.testing.exceptions import DocTestFailureException
 doctest.DocTestCase.failureException = DocTestFailureException

Modified: zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/doctest.txt
===================================================================
--- zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/doctest.txt	2010-04-26 08:35:12 UTC (rev 111413)
+++ zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/doctest.txt	2010-04-26 08:44:44 UTC (rev 111414)
@@ -16,7 +16,7 @@
 
   >>> import tempfile
   >>> fn = tempfile.mktemp()
-  >>> open(fn, 'w').write('Test:\r\n\r\n  >>> x = 1 + 1\r\n\r\nDone.\r\n')
+  >>> foo = open(fn, 'w').write('Test:\r\n\r\n  >>> x = 1 + 1\r\n\r\nDone.\r\n')
 
 Let's now run it as a doctest:
 
@@ -32,28 +32,3 @@
   >>> doctest.DocFileSuite(fn, module_relative=False).run(result) #doctest: +ELLIPSIS
   <...TestResult run=1 errors=0 failures=0>
 
-Regression tests
-----------------
-
-This section is about regression tests of ``zope.testing`` itself.
-
-  >>> from zope.testing.doctest import *
-
-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'

Modified: zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/formparser.txt
===================================================================
--- zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/formparser.txt	2010-04-26 08:35:12 UTC (rev 111413)
+++ zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/formparser.txt	2010-04-26 08:44:44 UTC (rev 111414)
@@ -104,8 +104,8 @@
 represent each instance of the field::
 
   >>> field = forms[1]["multi"]
-  >>> type(field)
-  <type 'list'>
+  >>> isinstance(field, list)
+  True
   >>> [o.value for o in field]
   ['', '']
   >>> [o.size for o in field]

Modified: zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/module.txt
===================================================================
--- zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/module.txt	2010-04-26 08:35:12 UTC (rev 111413)
+++ zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/module.txt	2010-04-26 08:44:44 UTC (rev 111414)
@@ -8,8 +8,8 @@
   >>> class Foo(object):
   ...    pass
 
-  >>> Foo.__module__
-  '__builtin__'
+  >>> 'builtin' in Foo.__module__ 
+  True
 
 By using ``zope.testing.module.setUp`` this can be
 controlled. Normally you set up your tests with it, but in this case
@@ -48,8 +48,8 @@
 
   >>> class Foo(object):
   ...    pass
-  >>> Foo.__module__
-  '__builtin__'
+  >>> 'builtin' in Foo.__module__ 
+  True
 
 Importing
 ---------

Modified: zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/renormalizing/__init__.py
===================================================================
--- zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/renormalizing/__init__.py	2010-04-26 08:35:12 UTC (rev 111413)
+++ zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/renormalizing/__init__.py	2010-04-26 08:44:44 UTC (rev 111414)
@@ -226,13 +226,14 @@
     ... ''' + want
     >>> example = doctest.Example(source, want)
     >>> print checker.output_difference(example, got,
-    ...                                 doctest.REPORT_NDIFF),
+    ...                                 doctest.REPORT_NDIFF)
     Differences (ndiff with -expected +actual):
           usage: thundermonkey [options] [url]
         - <blankline>
         + <BLANKLINE>
           options:
               -h    display this help message
+    <BLANKLINE>
 
 
 It is possible to combine RENormalizing checkers for easy reuse:
@@ -250,10 +251,10 @@
 
 Combining a checker with something else does not work:
 
-    >>> lowercase_checker + 5
+    >>> lowercase_checker + 5 #doctest: +ELLIPSIS
     Traceback (most recent call last):
         ...
-    TypeError: unsupported operand type(s) for +: 'instance' and 'int'
+    TypeError: unsupported operand type(s) for +: ...
 
 """
 
@@ -273,7 +274,7 @@
         return RENormalizing(self.transformers + other.transformers)
 
     def _cook(self, pattern):
-        if callable(pattern):
+        if hasattr(pattern, '__call__'):
             return pattern
         regexp, replacement = pattern
         return lambda text: regexp.sub(replacement, text)

Modified: zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/server.py
===================================================================
--- zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/server.py	2010-04-26 08:35:12 UTC (rev 111413)
+++ zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/server.py	2010-04-26 08:44:44 UTC (rev 111414)
@@ -24,7 +24,7 @@
 
 $Id$
 """
-import urllib2
+import urlparse
 import webbrowser
 from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
 import sys
@@ -80,10 +80,10 @@
         'http://localhost:555/index.html'
 
     """
-    (scheme, netloc, url, query, fragment) = urllib2.urlparse.urlsplit(url)
+    (scheme, netloc, url, query, fragment) = urlparse.urlsplit(url)
     netloc = netloc.split(':')[0]
     netloc = "%s:%s" % (netloc, port)
-    url = urllib2.urlparse.urlunsplit((scheme, netloc, url, query, fragment))
+    url = urlparse.urlunsplit((scheme, netloc, url, query, fragment))
     return url
 
 

Modified: zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/setupstack.txt
===================================================================
--- zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/setupstack.txt	2010-04-26 08:35:12 UTC (rev 111413)
+++ zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/setupstack.txt	2010-04-26 08:44:44 UTC (rev 111414)
@@ -76,7 +76,7 @@
 
 We can create files to out heart's content:
 
-    >>> open('Data.fs', 'w').write('xxx')
+    >>> foo = open('Data.fs', 'w').write('xxx')
     >>> os.path.exists('Data.fs')
     True
 

Modified: zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/tests.py
===================================================================
--- zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/tests.py	2010-04-26 08:35:12 UTC (rev 111413)
+++ zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/tests.py	2010-04-26 08:44:44 UTC (rev 111414)
@@ -14,6 +14,7 @@
 $Id$
 """
 
+import sys
 import re
 import unittest
 import warnings
@@ -27,7 +28,7 @@
 
 
 def test_suite():
-    return unittest.TestSuite((
+    suite = unittest.TestSuite((
         doctest.DocTestSuite('zope.testing.loggingsupport'),
         doctest.DocTestSuite('zope.testing.renormalizing'),
         doctest.DocTestSuite('zope.testing.server'),
@@ -44,3 +45,7 @@
                  'No module named unlikelymodulename')])),
         doctest.DocFileSuite('setupstack.txt'),
         ))
+
+    if sys.version < '3':
+        suite.addTests(doctest.DocFileSuite('unicode.txt'))
+    return suite

Added: zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/unicode.txt
===================================================================
--- zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/unicode.txt	                        (rev 0)
+++ zope.testing/branches/regebro-py3-3rdtimelucky/src/zope/testing/unicode.txt	2010-04-26 08:44:44 UTC (rev 111414)
@@ -0,0 +1,27 @@
+=============
+Unicode tests
+=============
+
+This section is about regression tests of ``zope.testing`` itself.
+None of these tests make sense in Python 3.
+
+  >>> from zope.testing.doctest import *
+
+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'



More information about the Zope3-Checkins mailing list