[Checkins] SVN: zope.interface/branches/regebro-python3/src/zope/interface/ In Python 3 the exception also prints out the module name and not only the exception name. This

Lennart Regebro regebro at gmail.com
Wed Apr 8 06:47:27 EDT 2009


Log message for revision 99004:
  In Python 3 the exception also prints out the module name and not only the exception name. This 
  breaks all doctests. By catching the exceptions and printing the exception we can get a compatible 
  way between 2.x and 3.0.
  

Changed:
  U   zope.interface/branches/regebro-python3/src/zope/interface/README.ru.txt
  U   zope.interface/branches/regebro-python3/src/zope/interface/README.txt
  U   zope.interface/branches/regebro-python3/src/zope/interface/tests/test_advice.py
  U   zope.interface/branches/regebro-python3/src/zope/interface/tests/test_interface.py
  U   zope.interface/branches/regebro-python3/src/zope/interface/verify.txt

-=-
Modified: zope.interface/branches/regebro-python3/src/zope/interface/README.ru.txt
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/README.ru.txt	2009-04-08 09:12:30 UTC (rev 99003)
+++ zope.interface/branches/regebro-python3/src/zope/interface/README.ru.txt	2009-04-08 10:47:27 UTC (rev 99004)
@@ -660,11 +660,13 @@
 будет выкинуто единственное исключение `Invalid` со списком исключений
 как аргументом::
 
+  >>> from zope.interface.exceptions import Invalid
   >>> errors = []
-  >>> IRange.validateInvariants(Range(2,1), errors)
-  Traceback (most recent call last):
-  ...
-  Invalid: [RangeError(Range(2, 1))]
+  >>> try:
+  ...     IRange.validateInvariants(Range(2,1), errors)
+  ... except Invalid, e:
+  ...     str(e)
+  '[RangeError(Range(2, 1))]'
 
 И список будет заполнен индивидуальными исключениями::
 

Modified: zope.interface/branches/regebro-python3/src/zope/interface/README.txt
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/README.txt	2009-04-08 09:12:30 UTC (rev 99003)
+++ zope.interface/branches/regebro-python3/src/zope/interface/README.txt	2009-04-08 10:47:27 UTC (rev 99004)
@@ -662,12 +662,14 @@
 then a single `Invalid` exception will be raised with the list of
 exceptions as it's argument::
 
+  >>> from zope.interface.exceptions import Invalid
   >>> errors = []
-  >>> IRange.validateInvariants(Range(2,1), errors)
-  Traceback (most recent call last):
-  ...
-  Invalid: [RangeError(Range(2, 1))]
-
+  >>> try:
+  ...     IRange.validateInvariants(Range(2,1), errors)
+  ... except Invalid, e:
+  ...     str(e)
+  '[RangeError(Range(2, 1))]'
+  
 And the list will be filled with the individual exceptions::
 
   >>> errors

Modified: zope.interface/branches/regebro-python3/src/zope/interface/tests/test_advice.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/tests/test_advice.py	2009-04-08 09:12:30 UTC (rev 99003)
+++ zope.interface/branches/regebro-python3/src/zope/interface/tests/test_advice.py	2009-04-08 10:47:27 UTC (rev 99004)
@@ -176,7 +176,11 @@
 TestClasses = (AdviceTests, FrameInfoTest)
 
 def test_suite():
-    return TestSuite([makeSuite(t,'check') for t in TestClasses])
+    if sys.version[0] == '2':
+        return TestSuite([makeSuite(t,'check') for t in TestClasses])
+    else:
+        # Advise metaclasses doesn't work in Python 3
+        return []
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')

Modified: zope.interface/branches/regebro-python3/src/zope/interface/tests/test_interface.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/tests/test_interface.py	2009-04-08 09:12:30 UTC (rev 99003)
+++ zope.interface/branches/regebro-python3/src/zope/interface/tests/test_interface.py	2009-04-08 10:47:27 UTC (rev 99004)
@@ -304,12 +304,14 @@
           ...     def __init__(self, min, max):
           ...         self.min, self.max = min, max
 
+          >>> from zope.interface.exceptions import Invalid
           >>> IRange.validateInvariants(Range(1,2))
           >>> IRange.validateInvariants(Range(1,1))
-          >>> IRange.validateInvariants(Range(2,1))
-          Traceback (most recent call last):
-          ...
-          Invalid: max < min
+          >>> try:
+          ...     IRange.validateInvariants(Range(2,1))
+          ... except Invalid, e:
+          ...     str(e)
+          'max < min'
 
 
         """

Modified: zope.interface/branches/regebro-python3/src/zope/interface/verify.txt
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/verify.txt	2009-04-08 09:12:30 UTC (rev 99003)
+++ zope.interface/branches/regebro-python3/src/zope/interface/verify.txt	2009-04-08 10:47:27 UTC (rev 99004)
@@ -35,6 +35,7 @@
 ``__init__`` method, will be recognized:
 
 >>> from zope.interface import Interface, Attribute, implements
+>>> from zope.interface.exceptions import BrokenImplementation
 >>> class IFoo(Interface):
 ...     x = Attribute("The X attribute")
 ...     y = Attribute("The Y attribute")
@@ -55,20 +56,28 @@
 ...     implements(IFoo)
 ...     x = 1
 
->>> verifyObject(IFoo, Foo())
-Traceback (most recent call last):
-BrokenImplementation: An object has failed to implement interface <InterfaceClass __builtin__.IFoo>
-    The y attribute was not provided.
+>>> try: #doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
+...     verifyObject(IFoo, Foo())
+... except BrokenImplementation, e:
+...     print str(e)
+An object has failed to implement interface <InterfaceClass ...IFoo>
+<BLANKLINE>
+        The y attribute was not provided.
+<BLANKLINE>
 
 >>> class Foo(object):
 ...     implements(IFoo)
 ...     def __init__(self):
 ...         self.y = 2
 
->>> verifyObject(IFoo, Foo())
-Traceback (most recent call last):
-BrokenImplementation: An object has failed to implement interface <InterfaceClass __builtin__.IFoo>
-    The x attribute was not provided.
+>>> try: #doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
+...     verifyObject(IFoo, Foo())
+... except BrokenImplementation, e:
+...     print str(e)
+An object has failed to implement interface <InterfaceClass ...IFoo>
+<BLANKLINE>
+        The x attribute was not provided.
+<BLANKLINE>
 
 If an attribute is implemented as a property that raises an AttributeError
 when trying to get its value, the attribute is considered missing:
@@ -82,10 +91,14 @@
 ...     def x(self):
 ...         raise AttributeError
 
->>> verifyObject(IFoo, Foo())
-Traceback (most recent call last):
-BrokenImplementation: An object has failed to implement interface <InterfaceClass __builtin__.IFoo>
-    The x attribute was not provided.
+>>> try: #doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
+...     verifyObject(IFoo, Foo())
+... except BrokenImplementation, e:
+...     print str(e)
+An object has failed to implement interface <InterfaceClass ...IFoo>
+<BLANKLINE>
+        The x attribute was not provided.
+<BLANKLINE>
 
 Any other exception raised by a property will propagate to the caller of
 ``verifyObject``:



More information about the Checkins mailing list