[Checkins] SVN: Products.ZCatalog/trunk/src/Products/ZCatalog/ modernize catalog.delColumn and tests a bit

Hano Schlichting cvs-admin at zope.org
Sat Apr 7 11:08:38 UTC 2012


Log message for revision 125058:
  modernize catalog.delColumn and tests a bit
  

Changed:
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py

-=-
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py	2012-04-07 11:00:05 UTC (rev 125057)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py	2012-04-07 11:08:35 UTC (rev 125058)
@@ -204,11 +204,9 @@
         del names[_index]
 
         # rebuild the schema
-        i = 0
         schema = {}
-        for name in names:
+        for i, name in enumerate(names):
             schema[name] = i
-            i = i + 1
 
         self.schema = schema
         self.names = tuple(names)

Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py	2012-04-07 11:00:05 UTC (rev 125057)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py	2012-04-07 11:08:35 UTC (rev 125058)
@@ -85,24 +85,37 @@
         self._catalog = None
 
 
-class TestAddDelColumn(CatalogBase, unittest.TestCase):
+class TestAddDelColumn(unittest.TestCase):
 
-    def testAdd(self):
-        self._catalog.addColumn('id')
-        self.assertEqual('id' in self._catalog.schema, True,
-                         'add column failed')
+    def _makeOne(self):
+        from Products.ZCatalog.Catalog import Catalog
+        return Catalog()
 
-    def testAddBad(self):
+    def test_add(self):
+        catalog = self._makeOne()
+        catalog.addColumn('id')
+        self.assertEqual('id' in catalog.schema, True, 'add column failed')
+
+    def test_add_bad(self):
         from Products.ZCatalog.Catalog import CatalogError
-        self.assertRaises(CatalogError, self._catalog.addColumn, '_id')
+        catalog = self._makeOne()
+        self.assertRaises(CatalogError, catalog.addColumn, '_id')
 
-    def testDel(self):
-        self._catalog.addColumn('id')
-        self._catalog.delColumn('id')
-        self.assert_('id' not in self._catalog.schema,
-                     'del column failed')
+    def test_del(self):
+        catalog = self._makeOne()
+        catalog.addColumn('id')
+        catalog.delColumn('id')
+        self.assert_('id' not in catalog.schema, 'del column failed')
 
+    def test_del_remaining(self):
+        catalog = self._makeOne()
+        catalog.addColumn('id')
+        catalog.addColumn('id2')
+        catalog.addColumn('id3')
+        catalog.delColumn('id2')
+        self.assert_('id2' not in catalog.schema, 'del column failed')
 
+
 class TestAddDelIndexes(CatalogBase, unittest.TestCase):
 
     def testAddFieldIndex(self):



More information about the checkins mailing list