[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_registrationmanager.py:1.2.6.2

Fred L. Drake, Jr. fred at zope.com
Tue Sep 9 14:02:46 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv26351

Modified Files:
      Tag: parentgeddon-branch
	test_registrationmanager.py 
Log Message:
remove assumptions about the names generated by setObject(); just test
that the set of names is maintained in the right order and represents
the right set of objects


=== Zope3/src/zope/app/services/tests/test_registrationmanager.py 1.2.6.1 => 1.2.6.2 ===
--- Zope3/src/zope/app/services/tests/test_registrationmanager.py:1.2.6.1	Mon Sep  8 14:21:49 2003
+++ Zope3/src/zope/app/services/tests/test_registrationmanager.py	Tue Sep  9 13:02:46 2003
@@ -40,10 +40,14 @@
     def setUp(self):
         PlacelessSetup.setUp(self)
         self.__manager = manager = RegistrationManager()
-        for l in 'abcdefghijklmnop':
-            manager.setObject('', l)
-        del manager['8']
-        del manager['10']
+        self.names = []
+        self.stateDict = {}
+        for ltr in 'abcdefghijklmnop':
+            name = manager.setObject('', ltr)
+            self.names.append(name)
+            self.stateDict[name] = ltr
+        n = self.names.pop(9); del manager[n]; del self.stateDict[n] # 'str10'
+        n = self.names.pop(7); del manager[n]; del self.stateDict[n] # 'str8'
 
     def test_implements_IRegistrationManager(self):
         verifyObject(IRegistrationManager, self.__manager)
@@ -51,11 +55,7 @@
     def _IEnumerableMapping__stateDict(self):
         # Hook needed by BaseTestIEnumerableMapping
         # also, effectively test setObject and __delitem__.
-        return {
-            '1': 'a', '2': 'b', '3': 'c', '4': 'd', '5': 'e',
-            '6': 'f', '7': 'g', '9': 'i', '11': 'k', '12': 'l',
-            '13': 'm', '14': 'n', '15': 'o', '16': 'p',
-            }
+        return self.stateDict
 
     def _IEnumerableMapping__sample(self):
         # Hook needed by BaseTestIEnumerableMapping
@@ -74,62 +74,70 @@
         self.__manager.moveTop([])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            self.names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveTop_1_no_effect(self):
-        self.__manager.moveTop(['1'])
+        self.__manager.moveTop([self.names[0]])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            self.names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveTop_many_no_effect(self):
-        self.__manager.moveTop(['1', '88', '3', '2', '99'])
+        names = self.names
+        self.__manager.moveTop([names[0], 'str88',
+                                names[2], names[1], 'str99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveTop_1(self):
-        self.__manager.moveTop(['3'])
+        names = self.names[:]
+        name = names.pop(2)
+        names.insert(0, name)
+        self.__manager.moveTop([name])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['3', '1', '2', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveTop_many(self):
-        self.__manager.moveTop(['1', '3', '88', '4', '11', '15', '16', '99'])
+        names = self.names[:]
+        n14 = names.pop(13)
+        n13 = names.pop(12)
+        n9 = names.pop(9)
+        n3 = names.pop(3)
+        n2 = names.pop(2)
+        n0 = names.pop(0)
+        move_names = [n0, n2, 'str88', n3, n9, n13, n14, 'str99']
+        self.__manager.moveTop(move_names)
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '3', '4', '11', '15', '16', '2', '5', '6', '7', '9',
-             '12', '13', '14'],
+            [n0, n2, n3, n9, n13, n14] + names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveTop_one_element_container(self):
         manager = RegistrationManager()
-        manager.setObject('', 'a')
-        manager.moveTop(['1'])
-        self.assertEqual(list(manager.items()), [('1', 'a')])
+        name = manager.setObject('', 'a')
+        manager.moveTop([name])
+        self.assertEqual(list(manager.items()), [(name, 'a')])
 
     #########################################################
     # Move Bottom
@@ -138,63 +146,70 @@
         self.__manager.moveBottom([])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            self.names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveBottom_1_no_effect(self):
-        self.__manager.moveBottom(['16'])
+        self.__manager.moveBottom([self.names[-1]])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            self.names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveBottom_many_no_effect(self):
-        self.__manager.moveBottom(['14', '88', '16', '15', '99'])
+        names = self.names
+        self.__manager.moveBottom([names[11], 'str88',
+                                   names[13], names[12], 'str99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            self.names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveBottom_1(self):
-        self.__manager.moveBottom(['3'])
+        names = self.names[:]
+        name = names.pop(2)
+        names.append(name)
+        self.__manager.moveBottom([name])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16', '3'],
+            names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveBottom_many(self):
+        names = self.names[:]
+        n13 = names.pop(13)
+        n12 = names.pop(12)
+        n9 = names.pop(9)
+        n3 = names.pop(3)
+        n2 = names.pop(2)
+        n0 = names.pop(0)
         self.__manager.moveBottom(
-            ['1', '3', '88', '4', '11', '16', '15', '99'])
+            [n0, n2, 'str88', n3, n9, n13, n12, 'str99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['2', '5', '6', '7', '9',
-             '12', '13', '14', '1', '3', '4', '11', '15', '16'],
+            names + [n0, n2, n3, n9, n12, n13],
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveBottom_one_element_container(self):
         manager = RegistrationManager()
-        manager.setObject('', 'a')
-        manager.moveBottom(['1'])
-        self.assertEqual(list(manager.items()), [('1', 'a')])
+        name = manager.setObject('', 'a')
+        manager.moveBottom([name])
+        self.assertEqual(list(manager.items()), [(name, 'a')])
 
     #########################################################
     # Move Up
@@ -203,63 +218,66 @@
         self.__manager.moveUp([])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            self.names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveUp_1_no_effect(self):
-        self.__manager.moveUp(['1'])
+        self.__manager.moveUp([self.names[0]])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            self.names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveUp_many_no_effect(self):
-        self.__manager.moveUp(['1', '88', '3', '2', '99'])
+        names = self.names
+        self.__manager.moveUp([names[0], 'str88', names[2], names[1], 'str99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            self.names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveUp_1(self):
-        self.__manager.moveUp(['3'])
+        names = self.names[:]
+        n2 = names.pop(2)
+        names.insert(1, n2)
+        self.__manager.moveUp([n2])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '3', '2', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveUp_many(self):
+        names = self.names
         self.__manager.moveUp(
-            ['1', '3', '88', '4', '11', '16', '15', '99'])
+            [names[0], names[2], 'str88', names[3], names[8],
+             names[13], names[12], 'str99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '3', '4', '2', '5', '6', '7', '11', '9',
-             '12', '13', '15', '16', '14'],
+            [names[0], names[2], names[3], names[1], names[4],
+             names[5], names[6], names[8], names[7], names[9],
+             names[10], names[12], names[13], names[11]],
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveUp_one_element_container(self):
         manager = RegistrationManager()
-        manager.setObject('', 'a')
-        manager.moveUp(['1'])
-        self.assertEqual(list(manager.items()), [('1', 'a')])
+        name = manager.setObject('', 'a')
+        manager.moveUp([name])
+        self.assertEqual(list(manager.items()), [(name, 'a')])
 
     #########################################################
     # Move Down
@@ -268,63 +286,67 @@
         self.__manager.moveDown([])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            self.names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveDown_1_no_effect(self):
-        self.__manager.moveDown(['16'])
+        self.__manager.moveDown([self.names[-1]])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            self.names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveDown_many_no_effect(self):
-        self.__manager.moveDown(['16', '88', '14', '15', '99'])
+        names = self.names
+        self.__manager.moveDown([names[13], 'str88',
+                                 names[11], names[12], '99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '3', '4', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            self.names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveDown_1(self):
-        self.__manager.moveDown(['3'])
+        names = self.names[:]
+        n2 = names.pop(2)
+        names.insert(3, n2)
+        self.__manager.moveDown([n2])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['1', '2', '4', '3', '5', '6', '7', '9',
-             '11', '12', '13', '14', '15', '16'],
+            names,
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveDown_many(self):
+        names = self.names
         self.__manager.moveDown(
-            ['1', '3', '88', '4', '11', '16', '15', '99'])
+            [names[0], names[2], 'str88', names[3],
+             names[8], names[13], names[12], 'str99'])
         self.assertEqual(
             list(self.__manager.keys()),
-            ['2', '1', '5', '3', '4', '6', '7', '9',
-             '12', '11', '13', '14', '15', '16'],
+            [names[1], names[0], names[4], names[2], names[3],
+             names[5], names[6], names[7], names[9], names[8],
+             names[10], names[11], names[12], names[13]],
             )
 
-        # Make sure we still have thye right items
+        # Make sure we still have the right items
         self.test_items()
 
     def test_moveDown_one_element_container(self):
         manager = RegistrationManager()
-        manager.setObject('', 'a')
-        manager.moveDown(['1'])
-        self.assertEqual(list(manager.items()), [('1', 'a')])
+        name = manager.setObject('', 'a')
+        manager.moveDown([name])
+        self.assertEqual(list(manager.items()), [(name, 'a')])
 
     #########################################################
 
@@ -343,14 +365,14 @@
         default = traverse(sm, 'default')
         self.assertEqual(default.getRegistrationManager(),
                          default['RegistrationManager'])
-        default.setObject('xxx', RegistrationManager())
+        name = default.setObject('xxx', RegistrationManager())
         del default['RegistrationManager']
         self.assertEqual(default.getRegistrationManager(),
-                         default['xxx'])
+                         default[name])
 
 
 #       Can't test empty because there's no way to make it empty.
-##         del default['xxx']
+##         del default[name]
 ##         self.assertRaises(Exception,
 ##                           default.getRegistrationManager)
 




More information about the Zope3-Checkins mailing list