Back to index

plone3  3.1.7
test_utils2.py
Go to the documentation of this file.
00001 ################################################################################
00002 #
00003 # Copyright (c) 2002-2005, Benjamin Saller <bcsaller@ideasuite.com>, and
00004 #                              the respective authors. All rights reserved.
00005 # For a list of Archetypes contributors see docs/CREDITS.txt.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions are met:
00009 #
00010 # * Redistributions of source code must retain the above copyright notice, this
00011 #   list of conditions and the following disclaimer.
00012 # * Redistributions in binary form must reproduce the above copyright notice,
00013 #   this list of conditions and the following disclaimer in the documentation
00014 #   and/or other materials provided with the distribution.
00015 # * Neither the name of the author nor the names of its contributors may be used
00016 #   to endorse or promote products derived from this software without specific
00017 #   prior written permission.
00018 #
00019 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00020 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00022 # FOR A PARTICULAR PURPOSE.
00023 #
00024 ################################################################################
00025 """
00026 """
00027 
00028 
00029 from Products.Archetypes.tests.attestcase import ATTestCase
00030 from Products.Archetypes.utils import OrderedDict
00031 
00032 
00033 class OrderedDictTest( ATTestCase ):
00034 
00035     def afterSetUp(self):
00036         self.d = OrderedDict()
00037         self.d['a'] = '1'
00038         self.d['b'] = '2'
00039         self.d['c'] = '3'
00040 
00041     def test_order(self):
00042         self.failUnless(self.d.keys() == ['a','b','c'])
00043         self.failUnless(self.d.values() == ['1','2','3'])
00044         self.failUnless(self.d.items() == [('a','1'),('b','2'),('c','3')])
00045         self.failUnless(self.d.reverse() == [('c','3'),('b','2'),('a','1')])
00046 
00047     def test_setitem(self):
00048         self.d['d'] = '4'
00049         self.failUnless(self.d.keys() == ['a','b','c','d'])
00050         self.failUnless(self.d.values() == ['1','2','3','4'])
00051         self.failUnless(self.d.items() == [('a','1'),('b','2'),('c','3'),('d','4')])
00052         self.failUnless(self.d.reverse() == [('d','4'),('c','3'),('b','2'),('a','1')])
00053 
00054         self.d['c'] = 'C'
00055         self.failUnless(self.d.keys() == ['a','b','c','d'])
00056         self.failUnless(self.d.values() == ['1','2','C','4'])
00057         self.failUnless(self.d.items() == [('a','1'),('b','2'),('c','C'),('d','4')])
00058         self.failUnless(self.d.reverse() == [('d','4'),('c','C'),('b','2'),('a','1')])
00059 
00060     def test_del(self):
00061         del self.d['b']
00062         self.failUnless(self.d.keys() == ['a','c'])
00063         self.failUnless(self.d.values() == ['1','3'])
00064         self.failUnless(self.d.items() == [('a','1'),('c','3')])
00065         self.failUnless(self.d.reverse() == [('c','3'),('a','1')])
00066         self.failIf(self.d.has_key('b'))
00067         self.failUnless(self.d.get('b',None) == None)
00068 
00069     def test_clear(self):
00070         self.d.clear()
00071         self.failUnless(self.d.keys() == [])
00072         self.failUnless(self.d.values() == [])
00073         self.failUnless(self.d.items() == [])
00074         self.failUnless(self.d.reverse() == [])
00075 
00076     def test_update(self):
00077         d2 = {'b':'B','d':'4'}
00078         self.d.update(d2)
00079         self.failUnless(self.d.keys() == ['a','b','c','d'])
00080         self.failUnless(self.d.values() == ['1','B','3','4'])
00081         self.failUnless(self.d.items() == [('a','1'),('b','B'),('c','3'),('d','4')])
00082         self.failUnless(self.d.reverse() == [('d','4'),('c','3'),('b','B'),('a','1')])
00083 
00084     def test_popitem(self):
00085         (k,v) = self.d.popitem()
00086         self.failUnless(k == 'c')
00087         self.failUnless(v == '3')
00088         
00089 
00090 def test_suite():
00091     from unittest import TestSuite, makeSuite
00092     suite = TestSuite()
00093     suite.addTest(makeSuite(OrderedDictTest))
00094     return suite