[Zope3-checkins] CVS: Packages3/Interface/tests - testFlatten.py:1.1

Steve Alexander cvs-admin@zope.org
Fri, 13 Jun 2003 11:03:14 -0400


Update of /cvs-repository/Packages3/Interface/tests
In directory cvs.zope.org:/tmp/cvs-serv32534/tests

Added Files:
	testFlatten.py 
Log Message:
Added testFlatten.py, moved across from zope.interface.tests.test_flatten



=== Added File Packages3/Interface/tests/testFlatten.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: testFlatten.py,v 1.1 2003/06/13 15:03:13 stevea Exp $
"""
import unittest
from zope.interface import Interface
from 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(unittest.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():
    loader = unittest.TestLoader()
    return loader.loadTestsFromTestCase(TestFlattenInterface)

if __name__ == '__main__':
    unittest.TextTestRunner().run(test_suite())