You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_sorting.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ##############################################################################
  2. #
  3. # Copyright (c) 2001, 2002 Zope Foundation and Contributors.
  4. # All Rights Reserved.
  5. #
  6. # This software is subject to the provisions of the Zope Public License,
  7. # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
  8. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
  9. # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  10. # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
  11. # FOR A PARTICULAR PURPOSE.
  12. #
  13. ##############################################################################
  14. """Test interface sorting
  15. """
  16. import unittest
  17. from zope.interface import Interface
  18. class I1(Interface): pass
  19. class I2(I1): pass
  20. class I3(I1): pass
  21. class I4(Interface): pass
  22. class I5(I4): pass
  23. class I6(I2): pass
  24. class Test(unittest.TestCase):
  25. def test(self):
  26. l = [I1, I3, I5, I6, I4, I2]
  27. l.sort()
  28. self.assertEqual(l, [I1, I2, I3, I4, I5, I6])
  29. def test_w_None(self):
  30. l = [I1, None, I3, I5, I6, I4, I2]
  31. l.sort()
  32. self.assertEqual(l, [I1, I2, I3, I4, I5, I6, None])
  33. def test_w_equal_names(self):
  34. # interfaces with equal names but different modules should sort by
  35. # module name
  36. from zope.interface.tests.m1 import I1 as m1_I1
  37. l = [I1, m1_I1]
  38. l.sort()
  39. self.assertEqual(l, [m1_I1, I1])