[Zodb-checkins] CVS: Zope3/src/zope/interface/tests - test_flatten.py:1.1 test_implements.py:1.3

Stephan Richter srichter@cbu.edu
Tue, 7 Jan 2003 07:15:01 -0500


Update of /cvs-repository/Zope3/src/zope/interface/tests
In directory cvs.zope.org:/tmp/cvs-serv9036/interface/tests

Modified Files:
	test_implements.py 
Added Files:
	test_flatten.py 
Log Message:
The flattenInterface() method was buggy, but since no code used it so far, 
it was unnoticed. I added tests checking for the correct functionality. 


=== Added File Zope3/src/zope/interface/tests/test_flatten.py ===
##############################################################################
#
# Copyright (c) 2002, 2003 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.
#
##############################################################################
"""Test flattenInterfaces 

$Id: test_flatten.py,v 1.1 2003/01/07 12:14:56 srichter Exp $
"""
from unittest import TestCase, TestSuite, makeSuite
from zope.interface import Interface
from zope.interface.implements import flattenInterfaces

class I1(Interface):
    pass

class I2(Interface):
    pass

class I3(Interface):
    pass

class I4(Interface):
    pass

class I5(I1, I2):
    pass

class I6(I3, I4):
    pass

class I7(I2, I3):
    pass


class TestFlattenInterface(TestCase):

    def testSingleInterface(self):
        self.assertEqual(flattenInterfaces(I1), [I1, Interface])
        self.assertEqual(flattenInterfaces(I2), [I2, Interface])
        self.assertEqual(flattenInterfaces(I3), [I3, Interface])
        self.assertEqual(flattenInterfaces(I4), [I4, Interface])

    def testSimpleTuple(self):
        flat = list(flattenInterfaces((I1, I2, I3)))
        flat.sort()
        res = [I1, I2, I3, Interface]
        res.sort()
        self.assertEqual(flat, res)
        flat = list(flattenInterfaces((I3, I1, I2)))
        flat.sort()
        self.assertEqual(flat, res)
    
    def testNestedTuple(self):
        flat = list(flattenInterfaces((I1, I2, I6)))
        flat.sort()
        self.assertEqual(flat, [I1, I2, I3, I4, I6, Interface])
        flat = list(flattenInterfaces((I1, I7)))
        flat.sort()
        self.assertEqual(flat, [I1, I2, I3, I7, Interface])

    def testRemoveDuplicates(self):
        flat = list(flattenInterfaces((I1, I2, I5)))
        flat.sort()
        self.assertEqual(flat, [I1, I2, I5, Interface])
        flat = list(flattenInterfaces((I5, I6, I7)))
        flat.sort()
        self.assertEqual(flat, [I1, I2, I3, I4, I5, I6, I7, Interface])

    def testNotRemoveDuplicates(self):
        flat = list(flattenInterfaces((I1, I2, I5), False))
        flat.sort()
        self.assertEqual(flat, [I1, I1, I2, I2, I5, Interface,
                                Interface, Interface, Interface])
        

def test_suite():
    return TestSuite((
        makeSuite(TestFlattenInterface),
        ))


=== Zope3/src/zope/interface/tests/test_implements.py 1.2 => 1.3 ===
--- Zope3/src/zope/interface/tests/test_implements.py:1.2	Wed Dec 25 09:15:12 2002
+++ Zope3/src/zope/interface/tests/test_implements.py	Tue Jan  7 07:14:56 2003
@@ -11,7 +11,10 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""Interface tests
 
+$Id$
+"""
 from zope.interface import Interface
 from zope.interface.implements import implements
 from zope.interface.exceptions import DoesNotImplement, BrokenImplementation