[z3-checkins] r10885 - z3/Five/branch/philikon-restructuring/tests
philikon at codespeak.net
philikon at codespeak.net
Tue Apr 19 23:48:01 MEST 2005
Author: philikon
Date: Tue Apr 19 23:48:01 2005
New Revision: 10885
Added:
z3/Five/branch/philikon-restructuring/tests/bridge.txt (contents, props changed)
Modified:
z3/Five/branch/philikon-restructuring/tests/test_bridge.py (contents, props changed)
Log:
All the tests pass now after the restructuring, now go on beautifying
the tests:
The bridge functionality is a good example of a very Pythonic
component that can easily be tested without any ZopeTestCase climbim
in a Pythonic doctest.
Added: z3/Five/branch/philikon-restructuring/tests/bridge.txt
==============================================================================
--- (empty file)
+++ z3/Five/branch/philikon-restructuring/tests/bridge.txt Tue Apr 19 23:48:01 2005
@@ -0,0 +1,122 @@
+======
+Bridge
+======
+
+The ``Five.bridge`` module provides functionality to convert a Zope 2
+interface into a Zope 3 one. First we'll import all we know about
+interfaces from the two generations:
+
+ >>> from Interface import Interface as Z2_Interface
+ >>> from Interface import Attribute as Z2_Attribute
+
+ >>> from zope.interface import Interface as Z3_Interface
+ >>> from zope.interface import Attribute as Z3_Attribute
+ >>> from zope.interface import Attribute as Z3_Method
+
+
+An empty interface
+------------------
+
+ >>> class IEmpty(Z2_Interface):
+ ... pass
+
+ >>> from Products.Five.bridge import fromZ2Interface
+ >>> converted = fromZ2Interface(IEmpty)
+
+ >>> Z3_Interface.isEqualOrExtendedBy(converted)
+ True
+ >>> len(converted.names())
+ 0
+
+
+Attributes
+----------
+
+ >>> class IAttributes(Z2_Interface):
+ ... one = Z2_Attribute('one', 'One attribute')
+ ... another = Z2_Attribute('another', 'Another attribute')
+
+ >>> converted = fromZ2Interface(IAttributes)
+
+ >>> Z3_Interface.isEqualOrExtendedBy(converted)
+ True
+ >>> len(converted.names())
+ 2
+ >>> 'one' in converted.names()
+ True
+ >>> 'another' in converted.names()
+ True
+
+ >>> one = converted.getDescriptionFor('one')
+ >>> isinstance(one, Z3_Attribute)
+ True
+ >>> one.getName()
+ 'one'
+ >>> one.getDoc()
+ 'One attribute'
+
+ >>> another = converted.getDescriptionFor('another')
+ >>> isinstance(another, Z3_Attribute)
+ True
+ >>> another.getName()
+ 'another'
+ >>> another.getDoc()
+ 'Another attribute'
+
+
+Methods
+-------
+
+ >>> class IMethods(Z2_Interface):
+ ... def one():
+ ... """One method."""
+ ... def another(arg1, arg2):
+ ... """Another method, taking arguments."""
+
+ >>> converted = fromZ2Interface(IMethods)
+
+ >>> Z3_Interface.isEqualOrExtendedBy(converted)
+ True
+ >>> len(converted.names())
+ 2
+ >>> 'one' in converted.names()
+ True
+ >>> 'another' in converted.names()
+ True
+
+ >>> one = converted.getDescriptionFor('one')
+ >>> isinstance(one, Z3_Method)
+ True
+ >>> one.getName()
+ 'one'
+ >>> one.getDoc()
+ 'One method.'
+
+ >>> another = converted.getDescriptionFor('another')
+ >>> isinstance(another, Z3_Method)
+ True
+ >>> another.getName()
+ 'another'
+ >>> another.getDoc()
+ 'Another method, taking arguments.'
+
+
+Invalid parameters
+------------------
+
+ >>> fromZ2Interface(None)
+ Traceback (most recent call last):
+ ...
+ ValueError: Not a Zope 2 interface!
+
+ >>> fromZ2Interface(object())
+ Traceback (most recent call last):
+ ...
+ ValueError: Not a Zope 2 interface!
+
+ >>> class IZ3_NotAllowed(Z3_Interface):
+ ... pass
+ >>> fromZ2Interface(IZ3_NotAllowed)
+ Traceback (most recent call last):
+ ...
+ ValueError: Not a Zope 2 interface!
Modified: z3/Five/branch/philikon-restructuring/tests/test_bridge.py
==============================================================================
--- z3/Five/branch/philikon-restructuring/tests/test_bridge.py (original)
+++ z3/Five/branch/philikon-restructuring/tests/test_bridge.py Tue Apr 19 23:48:01 2005
@@ -8,114 +8,17 @@
##############################################################################
""" Unit tests for Z2 -> Z3 bridge utilities.
-$Id:$
+$Id$
"""
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
import unittest
-
-#------------------------------------------------------------------------------
-# Running these tests
-# ===================
-#
-# I (Tres) can't figure out your testing framework. These tests run
-# in a "normal" Z27 + Z3 + Five instance home via the following:
-#
-# $ bin/zopectl run Products/Five/tests/test_bridge.py
-#------------------------------------------------------------------------------
-
-from Interface import Interface as Z2_Interface
-from Interface import Attribute as Z2_Attribute
-
-from zope.interface import Interface as Z3_Interface
-from zope.interface import Attribute as Z3_Attribute
-from zope.interface import Attribute as Z3_Method
-
-class BridgeTests(unittest.TestCase):
-
- def test_fromZ2Interface_invalid(self):
-
- from Products.Five.bridge import fromZ2Interface
-
- self.assertRaises(ValueError, fromZ2Interface, None)
- self.assertRaises(ValueError, fromZ2Interface, object())
-
- class IZ3_NotAllowed(Z3_Interface):
- pass
-
- self.assertRaises(ValueError, fromZ2Interface, IZ3_NotAllowed)
-
- def test_fromZ2Interface_empty(self):
-
- from Products.Five.bridge import fromZ2Interface
-
- class IEmpty(Z2_Interface):
- pass
-
- converted = fromZ2Interface(IEmpty)
-
- self.failUnless(Z3_Interface.isEqualOrExtendedBy(converted))
- self.assertEqual(len(converted.names()), 0)
-
- def test_fromZ2Interface_attributes(self):
-
- from Products.Five.bridge import fromZ2Interface
-
- class IAttributes(Z2_Interface):
- one = Z2_Attribute('one', 'One attribute')
- another = Z2_Attribute('another', 'Another attribute')
-
- converted = fromZ2Interface(IAttributes)
-
- self.failUnless(Z3_Interface.isEqualOrExtendedBy(converted))
- self.assertEqual(len(converted.names()), 2)
- self.failUnless('one' in converted.names())
- self.failUnless('another' in converted.names())
-
- one = converted.getDescriptionFor('one')
- self.failUnless(isinstance(one, Z3_Attribute))
- self.assertEqual(one.getName(), 'one')
- self.assertEqual(one.getDoc(), 'One attribute')
-
- another = converted.getDescriptionFor('another')
- self.failUnless(isinstance(another, Z3_Attribute))
- self.assertEqual(another.getName(), 'another')
- self.assertEqual(another.getDoc(), 'Another attribute')
-
- def test_fromZ2Interface_methods(self):
-
- from Products.Five.bridge import fromZ2Interface
-
- class IMethods(Z2_Interface):
-
- def one():
- """One method."""
-
- def another(arg1, arg2):
- """Another method, taking arguments."""
-
- converted = fromZ2Interface(IMethods)
-
- self.failUnless(Z3_Interface.isEqualOrExtendedBy(converted))
- self.assertEqual(len(converted.names()), 2)
- self.failUnless('one' in converted.names())
- self.failUnless('another' in converted.names())
-
- one = converted.getDescriptionFor('one')
- self.failUnless(isinstance(one, Z3_Method))
- self.assertEqual(one.getName(), 'one')
- self.assertEqual(one.getDoc(), 'One method.')
-
- another = converted.getDescriptionFor('another')
- self.failUnless(isinstance(another, Z3_Method))
- self.assertEqual(another.getName(), 'another')
- self.assertEqual(another.getDoc(), 'Another method, taking arguments.')
+from Testing.ZopeTestCase import ZopeDocFileSuite
def test_suite():
-
- return unittest.defaultTestLoader.loadTestsFromTestCase( BridgeTests )
+ return ZopeDocFileSuite('bridge.txt', package="Products.Five.tests")
if __name__ == '__main__':
framework()
More information about the z3-checkins
mailing list