[CMF-checkins] SVN: CMF/trunk/CMF some cleanup:

Yvo Schubbe y.2005- at wcm-solutions.de
Mon Sep 12 07:56:28 EDT 2005


Log message for revision 38446:
  some cleanup:
  - import cleanup
  - whitespace cleanup
  - removed Zope2.startup(): with Zope 2.8 most tests work without startup()

Changed:
  U   CMF/trunk/CMFCalendar/tests/test_Event.py
  U   CMF/trunk/CMFCore/FSPageTemplate.py
  U   CMF/trunk/CMFCore/interfaces/IOpaqueItems.py
  U   CMF/trunk/CMFCore/tests/test_ActionsTool.py
  U   CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py
  U   CMF/trunk/CMFCore/tests/test_FSDTMLMethod.py
  U   CMF/trunk/CMFCore/tests/test_PortalContent.py
  U   CMF/trunk/CMFDefault/Portal.py
  U   CMF/trunk/CMFDefault/tests/test_NewsItem.py
  U   CMF/trunk/CMFDefault/tests/test_SyndicationTool.py
  U   CMF/trunk/CMFSetup/__init__.py
  U   CMF/trunk/CMFUid/UniqueIdHandlerTool.py
  U   CMF/trunk/CMFUid/interfaces.py
  U   CMF/trunk/CMFUid/tests/test_uidgeneration.py
  U   CMF/trunk/CMFUid/tests/test_uidhandling.py

-=-
Modified: CMF/trunk/CMFCalendar/tests/test_Event.py
===================================================================
--- CMF/trunk/CMFCalendar/tests/test_Event.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFCalendar/tests/test_Event.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -15,18 +15,15 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 from DateTime import DateTime
 
-from Products.CMFCore.tests.base.dummy import DummyTool
 from Products.CMFCore.tests.base.testcase import RequestTest
 
 
-class TestEvent(TestCase):
+class TestEvent(unittest.TestCase):
 
     def _makeOne(self, id, *args, **kw):
         from Products.CMFCalendar.Event import Event
@@ -140,10 +137,10 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(TestEvent),
-        makeSuite(EventPUTTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(TestEvent),
+        unittest.makeSuite(EventPUTTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/trunk/CMFCore/FSPageTemplate.py
===================================================================
--- CMF/trunk/CMFCore/FSPageTemplate.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFCore/FSPageTemplate.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -15,22 +15,21 @@
 $Id$
 """
 
-import re, sys
+import re
 
 import Globals
-from DocumentTemplate.DT_Util import html_quote
 from AccessControl import getSecurityManager, ClassSecurityInfo
 from OFS.Cache import Cacheable
-from Shared.DC.Scripts.Script import Script
 from Products.PageTemplates.PageTemplate import PageTemplate
 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate, Src
+from Shared.DC.Scripts.Script import Script
 
+from DirectoryView import registerFileExtension
+from DirectoryView import registerMetaType
+from FSObject import FSObject
 from permissions import FTPAccess
 from permissions import View
 from permissions import ViewManagementScreens
-from DirectoryView import registerFileExtension
-from DirectoryView import registerMetaType
-from FSObject import FSObject
 from utils import _setCacheHeaders
 from utils import expandpath
 
@@ -39,8 +38,10 @@
 
 
 class FSPageTemplate(FSObject, Script, PageTemplate):
-    "Wrapper for Page Template"
 
+    """Wrapper for Page Template.
+    """
+
     meta_type = 'Filesystem Page Template'
 
     _owner = None  # Unowned

Modified: CMF/trunk/CMFCore/interfaces/IOpaqueItems.py
===================================================================
--- CMF/trunk/CMFCore/interfaces/IOpaqueItems.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFCore/interfaces/IOpaqueItems.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -15,11 +15,11 @@
 $Id$
 """
 
-from Interface import Attribute
 from Interface import Interface
 
 
 class ICallableOpaqueItem(Interface):
+
     """Interface for callable opaque items.
 
     Opaque items are subelements that are contained using something that
@@ -33,26 +33,28 @@
     def __init__(obj, id):
         """Return the opaque item and assign it to 'obj' as attr with 'id'.
         """
-    
+
     def __call__():
         """Return the opaque items value.
         """
-    
+
     def getId():
         """Return the id of the opaque item.
         """
 
 class ICallableOpaqueItemEvents(Interface):
+
     """CMF specific events upon copying, renaming and deletion.
     """
+
     def manage_afterClone(item):
         """After clone event hook.
         """
-    
+
     def manage_beforeDelete(item, container):
         """Before delete event hook.
         """
-    
+
     def manage_afterAdd(item, container):
         """After add event hook.
         """

Modified: CMF/trunk/CMFCore/tests/test_ActionsTool.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_ActionsTool.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFCore/tests/test_ActionsTool.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -15,25 +15,26 @@
 $Id$
 """
 
-from unittest import TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
+from Products.CMFCore.ActionInformation import ActionInformation
+from Products.CMFCore.Expression import Expression
 from Products.CMFCore.MembershipTool import MembershipTool
-from Products.CMFCore.RegistrationTool import RegistrationTool
 from Products.CMFCore.tests.base.testcase import SecurityRequestTest
-from Products.CMFCore.TypesTool import TypesTool
 from Products.CMFCore.URLTool import URLTool
 
 
-class ActionsToolTests( SecurityRequestTest ):
+class ActionsToolTests(SecurityRequestTest):
 
-    def _makeOne(self, *args, **kw):
+    def _getTargetClass(self):
         from Products.CMFCore.ActionsTool import ActionsTool
 
-        return ActionsTool(*args, **kw)
+        return ActionsTool
 
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
+
     def setUp(self):
         SecurityRequestTest.setUp(self)
 
@@ -42,29 +43,26 @@
         root._setObject( 'portal_url', URLTool() )
         root._setObject( 'foo', URLTool() )
         root._setObject('portal_membership', MembershipTool())
-        root._setObject('portal_types', TypesTool())
         self.tool = root.portal_actions
         self.tool.action_providers = ('portal_actions',)
 
     def test_z2interfaces(self):
         from Interface.Verify import verifyClass
-        from Products.CMFCore.ActionsTool import ActionsTool
         from Products.CMFCore.interfaces.portal_actions \
                 import ActionProvider as IActionProvider
         from Products.CMFCore.interfaces.portal_actions \
                 import portal_actions as IActionsTool
 
-        verifyClass(IActionProvider, ActionsTool)
-        verifyClass(IActionsTool, ActionsTool)
+        verifyClass(IActionProvider, self._getTargetClass())
+        verifyClass(IActionsTool, self._getTargetClass())
 
     def test_z3interfaces(self):
         from zope.interface.verify import verifyClass
-        from Products.CMFCore.ActionsTool import ActionsTool
         from Products.CMFCore.interfaces import IActionProvider
         from Products.CMFCore.interfaces import IActionsTool
 
-        verifyClass(IActionProvider, ActionsTool)
-        verifyClass(IActionsTool, ActionsTool)
+        verifyClass(IActionProvider, self._getTargetClass())
+        verifyClass(IActionsTool, self._getTargetClass())
 
     def test_actionProviders(self):
         tool = self.tool
@@ -87,15 +85,23 @@
                           ('portal_actions',))
 
     def test_listActionInformationActions(self):
-        """
-        Check that listFilteredActionsFor works for objects
-        that return ActionInformation objects
-        """
+        # Check that listFilteredActionsFor works for objects that return
+        # ActionInformation objects
         root = self.root
         tool = self.tool
-        root._setObject('portal_registration', RegistrationTool())
-        self.tool.action_providers = ('portal_actions',)
-        self.assertEqual(tool.listFilteredActionsFor(root.portal_registration),
+        tool._actions = (
+              ActionInformation(id='folderContents',
+                                title='Folder contents',
+                                action=Expression(text='string:'
+                                             '${folder_url}/folder_contents'),
+                                condition=Expression(text='python: '
+                                                      'folder is not object'),
+                                permissions=('List folder contents',),
+                                category='folder',
+                                visible=1)
+            ,
+            )
+        self.assertEqual(tool.listFilteredActionsFor(root.foo),
                          {'workflow': [],
                           'user': [],
                           'object': [],
@@ -111,9 +117,9 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(ActionsToolTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(ActionsToolTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -18,16 +18,13 @@
 import unittest
 import Testing
 
-import Zope2
-Zope2.startup()
-
-from zExceptions import NotFound
 from OFS.Folder import Folder
 from OFS.SimpleItem import SimpleItem
-from Products.ZCatalog import CatalogBrains
-from Products.CMFCore.WorkflowTool import WorkflowTool
+
 from Products.CMFCore.CMFCatalogAware import CMFCatalogAware
+from Products.CMFCore.exceptions import NotFound
 from Products.CMFCore.tests.base.testcase import LogInterceptor
+from Products.CMFCore.WorkflowTool import WorkflowTool
 
 CMF_SECURITY_INDEXES = CMFCatalogAware._cmf_security_indexes
 
@@ -87,7 +84,6 @@
             res.append(self.brain_class(ob, obpath))
         return res
 
-
 class TheClass(CMFCatalogAware, Folder):
     def __init__(self, id):
         self._setId(id)
@@ -197,4 +193,4 @@
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/trunk/CMFCore/tests/test_FSDTMLMethod.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_FSDTMLMethod.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFCore/tests/test_FSDTMLMethod.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -14,15 +14,13 @@
 
 $Id: test_FSDTMLMethod.py 37061 2005-06-15 14:17:41Z tseaver $
 """
-from unittest import TestSuite, makeSuite, main
+
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 from os.path import join as path_join
 
 from OFS.Folder import Folder
-from Products.PageTemplates.TALES import Undefined
 from Products.StandardCacheManagers import RAMCacheManager
 
 from Products.CMFCore.FSDTMLMethod import FSDTMLMethod
@@ -118,10 +116,10 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(FSDTMLMethodTests),
-        makeSuite(FSDTMLMethodCustomizationTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(FSDTMLMethodTests),
+        unittest.makeSuite(FSDTMLMethodCustomizationTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/trunk/CMFCore/tests/test_PortalContent.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_PortalContent.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFCore/tests/test_PortalContent.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -15,21 +15,17 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 from AccessControl.SecurityManagement import newSecurityManager
 from AccessControl.SecurityManagement import noSecurityManager
-from AccessControl.User import UnrestrictedUser
 from Acquisition import aq_base
-import transaction
 
 from Products.CMFCore.tests.base.testcase import SecurityRequestTest
 
 
-class PortalContentTests(TestCase):
+class PortalContentTests(unittest.TestCase):
 
     def test_z2interfaces(self):
         from Interface.Verify import verifyClass
@@ -113,10 +109,10 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(PortalContentTests),
-        makeSuite(TestContentCopyPaste),
+    return unittest.TestSuite((
+        unittest.makeSuite(PortalContentTests),
+        unittest.makeSuite(TestContentCopyPaste),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/trunk/CMFDefault/Portal.py
===================================================================
--- CMF/trunk/CMFDefault/Portal.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFDefault/Portal.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -17,7 +17,6 @@
 
 from warnings import warn
 
-from Globals import HTMLFile
 from Globals import InitializeClass
 
 from Products.CMFCore.PortalObject import PortalObjectBase
@@ -64,9 +63,8 @@
                            )
 
 
-class CMFSite ( PortalObjectBase
-              , DefaultDublinCoreImpl
-              ):
+class CMFSite(PortalObjectBase, DefaultDublinCoreImpl):
+
     """
         The *only* function this class should have is to help in the setup
         of a new CMFSite.  It should not assist in the functionality at all.

Modified: CMF/trunk/CMFDefault/tests/test_NewsItem.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_NewsItem.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFDefault/tests/test_NewsItem.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -15,20 +15,17 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 from Products.CMFCore.tests.base.content import BASIC_HTML
 from Products.CMFCore.tests.base.content import BASIC_STRUCTUREDTEXT
 from Products.CMFCore.tests.base.content import DOCTYPE
 from Products.CMFCore.tests.base.content import ENTITY_IN_TITLE
-from Products.CMFCore.tests.base.dummy import DummyTool
 from Products.CMFCore.tests.base.testcase import RequestTest
 
 
-class NewsItemTests(TestCase):
+class NewsItemTests(unittest.TestCase):
 
     def _makeOne(self, id, *args, **kw):
         from Products.CMFDefault.NewsItem import NewsItem
@@ -189,10 +186,10 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(NewsItemTests),
-        makeSuite(NewsItemPUTTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(NewsItemTests),
+        unittest.makeSuite(NewsItemPUTTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/trunk/CMFDefault/tests/test_SyndicationTool.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_SyndicationTool.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFDefault/tests/test_SyndicationTool.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -1,12 +1,34 @@
-from unittest import TestCase, TestSuite, makeSuite, main
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+""" Unit tests for SyndicationTool module.
 
+$Id$
+"""
+
+import unittest
+import Testing
+
 from DateTime.DateTime import DateTime
+
 from Products.CMFCore.tests.base.testcase import SecurityTest
 
+
 class Dummy:
+
     def getId(self):
         return 'dummy'
 
+
 class SyndicationToolTests(SecurityTest):
 
     def _getTargetClass(self):
@@ -171,10 +193,9 @@
 
 
 def test_suite():
-    return TestSuite((
-        makeSuite(SyndicationToolTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(SyndicationToolTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
-
+    unittest.main(defaultTest='test_suite')

Modified: CMF/trunk/CMFSetup/__init__.py
===================================================================
--- CMF/trunk/CMFSetup/__init__.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFSetup/__init__.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -21,17 +21,16 @@
 from permissions import ManagePortal
 from registry import _profile_registry as profile_registry
 
+
 security = ModuleSecurityInfo( 'Products.CMFSetup' )
 security.declareProtected( ManagePortal, 'profile_registry' )
 
 def initialize( context ):
 
-    from Products.CMFCore.utils import ToolInit, registerIcon
+    from Products.CMFCore.utils import ToolInit
     from tool import SetupTool
 
-
     ToolInit( 'CMF Setup Tool'
             , tools=[ SetupTool ]
             , icon='www/tool.png'
             ).initialize( context )
-

Modified: CMF/trunk/CMFUid/UniqueIdHandlerTool.py
===================================================================
--- CMF/trunk/CMFUid/UniqueIdHandlerTool.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFUid/UniqueIdHandlerTool.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -20,24 +20,25 @@
 import Missing
 
 import zLOG
+from AccessControl import ClassSecurityInfo
+from Acquisition import aq_base
 from Globals import InitializeClass
-from AccessControl import ClassSecurityInfo
-from Acquisition import Implicit, aq_base
-
 from OFS.SimpleItem import SimpleItem
 
-from Products.CMFCore.utils import getToolByName, UniqueObject
 from Products.CMFCore.ActionProviderBase import ActionProviderBase
 from Products.CMFCore.permissions import ManagePortal
+from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.utils import UniqueObject
 
+from Products.CMFUid.interfaces import IUniqueIdBrainQuery
 from Products.CMFUid.interfaces import IUniqueIdHandler
-from Products.CMFUid.interfaces import IUniqueIdBrainQuery
 from Products.CMFUid.interfaces import IUniqueIdUnrestrictedQuery
 from Products.CMFUid.interfaces import UniqueIdError
 
 UID_ATTRIBUTE_NAME = 'cmf_uid'
 
 class UniqueIdHandlerTool(UniqueObject, SimpleItem, ActionProviderBase):
+
     __doc__ = __doc__ # copy from module
 
     __implements__ = (
@@ -51,16 +52,16 @@
     id = 'portal_uidhandler'
     alternative_id = "portal_standard_uidhandler"
     meta_type = 'Unique Id Handler Tool'
-    
+
     # make the uid attribute name available for the unit tests
     # not meant to be altered as long you don't know what you do!!!
     UID_ATTRIBUTE_NAME = UID_ATTRIBUTE_NAME
-    
+
     # make the exception class available through the tool
     UniqueIdError = UniqueIdError
-    
+
     security = ClassSecurityInfo()
-    
+
     def _reindexObject(self, obj):
         # add uid index and colums to catalog if not yet done
         UID_ATTRIBUTE_NAME = self.UID_ATTRIBUTE_NAME
@@ -68,7 +69,7 @@
         if UID_ATTRIBUTE_NAME not in catalog.indexes():
             catalog.addIndex(UID_ATTRIBUTE_NAME, 'FieldIndex')
             catalog.addColumn(UID_ATTRIBUTE_NAME)
-        
+
         # reindex
         catalog.reindexObject(obj)
 
@@ -79,7 +80,7 @@
         anno_tool = getToolByName(self, 'portal_uidannotation')
         annotation = anno_tool(obj, self.UID_ATTRIBUTE_NAME)
         annotation.setUid(uid)
-        
+
         # reindex the object
         self._reindexObject(obj)
 
@@ -93,9 +94,9 @@
             generator = getToolByName(self, 'portal_uidgenerator')
             uid = generator()
             self._setUid(obj, uid)
-            
+
         return uid
-    
+
     security.declareProtected(ManagePortal, 'unregister')
     def unregister(self, obj):
         """See IUniqueIdSet.
@@ -104,26 +105,25 @@
         if getattr(aq_base(obj), UID_ATTRIBUTE_NAME, None) is None:
             raise UniqueIdError, \
                   "No unique id available to be unregistered on '%s'" % obj
-            
+
         # delete the uid and reindex
         delattr(obj, UID_ATTRIBUTE_NAME)
         self._reindexObject(obj)
-    
-    
+
     security.declarePublic('queryUid')
     def queryUid(self, obj, default=None):
         """See IUniqueIdQuery.
         """
         uid = getattr(aq_base(obj), self.UID_ATTRIBUTE_NAME, None)
         # If 'obj' is a content object the 'uid' attribute is usually a
-        # callable object. If 'obj' is a catalog brain the uid attribute 
+        # callable object. If 'obj' is a catalog brain the uid attribute
         # is non callable and possibly equals the 'Missing.MV' value.
         if uid is Missing.MV or uid is None:
             return default
         if callable(uid):
             return uid()
         return uid
-    
+
     security.declarePublic('getUid')
     def getUid(self, obj):
         """See IUniqueIdQuery.
@@ -132,7 +132,7 @@
         if uid is None:
             raise UniqueIdError, "No unique id available on '%s'" % obj
         return uid
-    
+
     security.declarePrivate('setUid')
     def setUid(self, obj, uid, check_uniqueness=True):
         """See IUniqueIdSet.
@@ -140,7 +140,7 @@
         # None is the only value a unique id shall never have!
         if uid is None:
             raise UniqueIdError, "It's forbidden to set a unique id to 'None'."
-        
+
         # check for uniqueness if enabled
         if check_uniqueness:
             result = self.queryObject(uid)
@@ -149,21 +149,21 @@
                     uid = uid()
                 raise UniqueIdError, \
                       "The unique id '%s' is already in use" % uid
-        
+
         # everything is ok: set it!
         self._setUid(obj, uid)
-    
+
     def _queryBrain(self, uid, searchMethodName, default=None):
         """This helper method does the "hard work" of querying the catalog
            and interpreting the results.
         """
         if uid is None:
             return default
-        
+
         # convert the uid to the right format
         generator = getToolByName(self, 'portal_uidgenerator')
         uid = generator.convert(uid)
-        
+
         catalog = getToolByName(self, 'portal_catalog')
         searchMethod = getattr(catalog, searchMethodName)
         result = searchMethod({self.UID_ATTRIBUTE_NAME: uid})
@@ -179,21 +179,21 @@
             zLOG.LOG("CMUid ASSERT:", zLOG.INFO,
                      "Uups, %s objects have '%s' as uid!!!" % \
                      (len_result, uid))
-        
+
         return result[0]
-    
+
     security.declarePublic('queryBrain')
     def queryBrain(self, uid, default=None):
         """See IUniqueIdBrainQuery.
         """
         return self._queryBrain(uid, 'searchResults', default)
-        
+
     def _getBrain(self, uid, queryBrainMethod):
         brain = queryBrainMethod(uid, default=None)
         if brain is None:
             raise UniqueIdError, "No object found with '%s' as uid." % uid
         return brain
-    
+
     security.declarePublic('getBrain')
     def getBrain(self, uid):
         """See IUniqueIdBrainQuery.
@@ -214,25 +214,25 @@
             return self.getObject(uid)
         except UniqueIdError:
             return default
-    
+
     security.declarePrivate('unrestrictedQueryBrain')
     def unrestrictedQueryBrain(self, uid, default=None):
         """See IUniqueIdUnrestrictedQuery.
         """
         return self._queryBrain(uid, 'unrestrictedSearchResults', default)
-        
+
     security.declarePrivate('unrestrictedGetBrain')
     def unrestrictedGetBrain(self, uid):
         """See IUniqueIdUnrestrictedQuery.
         """
         return self._getBrain(uid, self.unrestrictedQueryBrain)
-        
+
     security.declarePrivate('unrestrictedGetObject')
     def unrestrictedGetObject(self, uid):
         """See IUniqueIdUnrestrictedQuery.
         """
         return self.unrestrictedGetBrain(uid).getObject()
-    
+
     security.declarePrivate('unrestrictedQueryObject')
     def unrestrictedQueryObject(self, uid, default=None):
         """See IUniqueIdUnrestrictedQuery.
@@ -241,5 +241,5 @@
             return self.unrestrictedGetObject(uid)
         except UniqueIdError:
             return default
-    
+
 InitializeClass(UniqueIdHandlerTool)

Modified: CMF/trunk/CMFUid/interfaces.py
===================================================================
--- CMF/trunk/CMFUid/interfaces.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFUid/interfaces.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -13,24 +13,28 @@
 """Unique Id Generation and Handling
 
 These interfaces are intentionaly kept close to those from Zope3. Additionaly
-handling (IUniqueIdHandler) and generation (IUniqueIdGenerator) of unique ids 
+handling (IUniqueIdHandler) and generation (IUniqueIdGenerator) of unique ids
 are kept separate.
 
 $Id$
 """
 
-from Interface import Interface, Attribute
+from Interface import Interface
 
-from Products.CMFCore.interfaces.IOpaqueItems \
-    import ICallableOpaqueItem, ICallableOpaqueItemEvents
+from Products.CMFCore.interfaces.IOpaqueItems import ICallableOpaqueItem
+from Products.CMFCore.interfaces.IOpaqueItems import ICallableOpaqueItemEvents
 
-class UniqueIdError(Exception): pass
 
+class UniqueIdError(Exception):
 
+    pass
+
+
 class IUniqueIdGenerator(Interface):
+
     """Generate a unique id.
     """
-    
+
     def __call__():
         """Return a unique id value.
         """
@@ -38,166 +42,175 @@
     def convert(uid):
         """Converts the unique id from string type to the appropriate
            uid type.
-           
+
         The resulting type has to be the same as the one '__call__'
         returns.
         """
 
+
 class IUniqueIdAnnotationManagement(Interface):
+
     """Manage unique id annotations.
     """
-    
+
     def __call__(obj, id):
         """Attach an unique id attribute of 'id' to the passed object.
-        
+
         Return a unique id object implementing 'IUniqueIdAnnotation'.
         """
 
+
 class IUniqueIdAnnotation(ICallableOpaqueItem, ICallableOpaqueItemEvents):
+
     """Opaque unique id item handling adding, copying, and deletion events.
     """
-    
+
     def setUid(uid):
         """Set the uid value the unique id annotation shall return.
         """
 
 
 class IUniqueIdSet(Interface):
+
     """(Un)register unique ids on objects.
     """
 
     def register(obj):
         """Register the object and return the unique id generated for it.
-        
-        If the object is already registered, its unique id is returned 
-        anyway.
-        
+
+        If the object is already registered, its unique id is returned anyway.
+
         UniqueIdError is raised if object can not be registered a unique id.
         """
 
     def unregister(obj):
         """Remove the object from the indexes.
-        
+
         UniqueIdError is raised if object was not registered previously.
         """
 
     def setUid(obj, uid, check_uniqueness=True):
         """Set the unique id of an object.
-        
+
         By default a check ensuring uniqueness is enabled. Be aware when
         disabling this check: You really need to know what you do !!!
         """
 
 
 class IUniqueIdQuery(Interface):
+
     """Querying unique ids.
     """
+
     def queryUid(obj, default=None):
         """Return the unique id of the object.
-        
+
         If the object doesn't have a unique, the default value is returned.
         """
-        
+
     def getUid(obj):
         """Return the unique id of the object.
-        
+
         If the object doesn't have a unique, a UniqueIdError is raised.
         """
-        
+
     def queryObject(uid, default=None):
         """Return the object with the given uid.
-        
-        If no object exist with the given unique id, the default value is 
+
+        If no object exist with the given unique id, the default value is
         returned.
         """
-        
+
     def getObject(uid):
         """Return the object with the given uid.
-        
+
         If no object exist with the given unique id, a UniqueIdError is raised.
         """
 
+
 # This is the main API for playing with unique ids
 class IUniqueIdHandler(IUniqueIdSet, IUniqueIdQuery):
+
     """Handle registering, querying unique ids and objects.
     """
 
+
 # This is a secondary API enhancement
 class IUniqueIdBrainQuery(Interface):
+
     """Querying unique ids returning brains for efficiency sake.
-    
-    Returning a brain is more efficient than returning the object.
-    A brain usually exposes only parts of the object and should only 
-    be read from. 
-    
-    If the implementing class doesn't support returning a catalog 
-    brain it may fallback to return the object. To be entirely
-    compatible it must implement the (non existing) interface 
-    catalog brains implement.
+
+    Returning a brain is more efficient than returning the object. A brain
+    usually exposes only parts of the object and should only be read from.
+
+    If the implementing class doesn't support returning a catalog brain it may
+    fallback to return the object. To be entirely compatible it must implement
+    the (non existing) interface catalog brains implement.
     """
-    
+
     def queryBrain(uid, default=None):
         """Return the brain of object with the given uid.
-        
+
         If no object exist with the given unique id, the default value
         is returned.
         """
-        
+
     def getBrain(uid):
         """Return a brain of the object with the given uid.
-        
-        If no object exist with the given unique id, a UniqueIdError 
-        is raised.
+
+        If no object exist with the given unique id, a UniqueIdError is
+        raised.
         """
 
+
 # This is another secondary API enhancement
 class IUniqueIdUnrestrictedQuery(Interface):
+
     """Querying unique ids unrestricted.
-    
-    The below methods return not yet effective and already expired 
+
+    The below methods return not yet effective and already expired
     objects regardless of the roles the caller has.
-    
-    CAUTION: Care must be taken not to open security holes by exposing 
+
+    CAUTION: Care must be taken not to open security holes by exposing
     the results of these methods to non authorized callers!
-        
+
     If you're in doubth if you should use this method signature or
-    the restricted ones ('IUniqueIdQuery' and 'IUniqueIdBrainQuery') 
+    the restricted ones ('IUniqueIdQuery' and 'IUniqueIdBrainQuery')
     use the latter!
-    
-    Returning a brain is more efficient than returning the object.
-    A brain usually exposes only parts of the object and should only 
-    be read from. 
-    
-    If the implementing class doesn't support returning a catalog 
+
+    Returning a brain is more efficient than returning the object. A brain
+    usually exposes only parts of the object and should only be read from.
+
+    If the implementing class doesn't support returning a catalog
     brain it may fallback to return the object. To be entirely
-    compatible it must implement the (non existing) interface 
+    compatible it must implement the (non existing) interface
     catalog brains implement.
     """
-    
+
     def unrestrictedQueryObject(uid, default=None):
         """Return the object with the given uid.
-        
-        If no object exist with the given unique id, the default value 
+
+        If no object exist with the given unique id, the default value
         is returned.
         """
-        
+
     def unrestrictedGetObject(uid):
         """Return a brain of the object with the given uid.
-        
-        If no object exist with the given unique id, a UniqueIdError 
+
+        If no object exist with the given unique id, a UniqueIdError
         is raised.
         """
 
     def unrestrictedQueryBrain(uid, default=None):
         """Return the brain of the object with the given uid.
-        
+
         If no object exist with the given unique id, the default value
         is returned.
         """
-        
+
     def unrestrictedGetBrain(uid):
         """Return a brain of the object with the given uid.
-        
-        If no object exist with the given unique id, a UniqueIdError 
+
+        If no object exist with the given unique id, a UniqueIdError
         is raised.
         """

Modified: CMF/trunk/CMFUid/tests/test_uidgeneration.py
===================================================================
--- CMF/trunk/CMFUid/tests/test_uidgeneration.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFUid/tests/test_uidgeneration.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -15,16 +15,12 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 from BTrees.Length import Length
 from Interface.Verify import verifyObject
 
-from Products.CMFCore.tests.base.dummy import DummyContent
-
 from Products.CMFCore.tests.base.testcase import SecurityTest
 
 from Products.CMFUid.interfaces import IUniqueIdGenerator
@@ -36,18 +32,18 @@
     def setUp(self):
         SecurityTest.setUp(self)
         self.root._setObject('portal_uidgenerator', UniqueIdGeneratorTool())
-    
+
     def test_interface(self):
         generator = self.root.portal_uidgenerator
         verifyObject(IUniqueIdGenerator, generator)
-        
+
     def test_returnedUidsAreValidAndDifferent(self):
         generator = self.root.portal_uidgenerator
         uid1 = generator()
         uid2 = generator()
         self.failIfEqual(uid1, uid2)
         self.failIfEqual(uid1, None)
-        
+
     def test_converter(self):
         generator = self.root.portal_uidgenerator
         uid = generator()
@@ -67,10 +63,11 @@
         self.failUnless(isinstance(generator._uid_counter, int))
         self.failIfEqual(uid1, uid2)
 
+
 def test_suite():
-    return TestSuite((
-        makeSuite(UniqueIdGeneratorTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(UniqueIdGeneratorTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')

Modified: CMF/trunk/CMFUid/tests/test_uidhandling.py
===================================================================
--- CMF/trunk/CMFUid/tests/test_uidhandling.py	2005-09-12 06:44:09 UTC (rev 38445)
+++ CMF/trunk/CMFUid/tests/test_uidhandling.py	2005-09-12 11:56:28 UTC (rev 38446)
@@ -15,40 +15,38 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, makeSuite, main
+import unittest
 import Testing
-import Zope2
-Zope2.startup()
 
 from Interface.Verify import verifyObject
 
-from Products.CMFCore.tests.base.testcase import SecurityTest
-
+from Products.CMFCore.CatalogTool import CatalogTool
 from Products.CMFCore.tests.base.dummy import DummyContent
 from Products.CMFCore.tests.base.dummy import DummyFolder
 from Products.CMFCore.tests.base.dummy import DummySite
+from Products.CMFCore.tests.base.testcase import SecurityTest
 
-from Products.CMFCore.CatalogTool import CatalogTool
-
-from Products.CMFUid.interfaces import IUniqueIdHandler
 from Products.CMFUid.interfaces import IUniqueIdBrainQuery
+from Products.CMFUid.interfaces import IUniqueIdHandler
 from Products.CMFUid.interfaces import IUniqueIdUnrestrictedQuery
-
-from Products.CMFUid.UniqueIdGeneratorTool import UniqueIdGeneratorTool
 from Products.CMFUid.UniqueIdAnnotationTool import UniqueIdAnnotationTool
+from Products.CMFUid.UniqueIdGeneratorTool import UniqueIdGeneratorTool
 from Products.CMFUid.UniqueIdHandlerTool import UniqueIdHandlerTool
 
+
 def removeUnnecessaryIndexes(catalog):
     indexes = [id[0] for id in catalog.enumerateIndexes()]
     columns = catalog.enumerateColumns()
     catalog.manage_delIndex(indexes)
     catalog.manage_delColumn(columns)
 
+
 class DummyUid:
     """A dummy uid that surely is of different type of the generated ones.
     """
     pass
 
+
 class UniqueIdHandlerTests(SecurityTest):
 
     def setUp(self):
@@ -59,59 +57,59 @@
         self.root._setObject('portal_uidhandler', UniqueIdHandlerTool())
         self.root._setObject('dummy', DummyContent(id='dummy'))
         self.root._setObject('dummy2', DummyContent(id='dummy2'))
-        
+
         removeUnnecessaryIndexes(self.root.portal_catalog)
-    
+
     def test_interface(self):
         handler = self.root.portal_uidhandler
         verifyObject(IUniqueIdHandler, handler)
         verifyObject(IUniqueIdBrainQuery, handler)
         verifyObject(IUniqueIdUnrestrictedQuery, handler)
-    
+
     def test_getUidOfNotYetRegisteredObject(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
         UniqueIdError = handler.UniqueIdError
-        
+
         self.assertEqual(handler.queryUid(dummy, None), None)
         self.assertRaises(UniqueIdError, handler.getUid, dummy)
-    
+
     def test_getInvalidUid(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
         UniqueIdError = handler.UniqueIdError
-        
+
         self.assertEqual(handler.queryObject(100, None), None)
         self.assertRaises(UniqueIdError, handler.getObject, 100)
         self.assertEqual(handler.unrestrictedQueryObject(100, None), None)
         self.assertRaises(UniqueIdError, handler.unrestrictedGetObject, 100)
-    
+
         uid = handler.register(dummy)
         self.assertEqual(handler.queryObject(uid+1, None), None)
         self.assertRaises(UniqueIdError, handler.getObject, uid+1)
         self.assertEqual(handler.unrestrictedQueryObject(uid+1, None), None)
         self.assertRaises(UniqueIdError, handler.unrestrictedGetObject, uid+1)
-    
+
     def test_getUidOfRegisteredObject(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
-        
+
         uid = handler.register(dummy)
         self.assertEqual(handler.getUid(dummy), uid)
-    
+
     def test_getRegisteredObjectByUid(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
-        
+
         uid = handler.register(dummy)
         self.assertEqual(handler.getObject(uid), dummy)
         self.assertEqual(handler.unrestrictedGetObject(uid), dummy)
-    
+
     def test_getUnregisteredObject(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
         UniqueIdError = handler.UniqueIdError
-        
+
         uid = handler.register(dummy)
         handler.unregister(dummy)
         self.assertEqual(handler.queryObject(uid, None), None)
@@ -123,7 +121,7 @@
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
         UniqueIdError = handler.UniqueIdError
-        
+
         uid = handler.register(dummy)
         handler.unregister(dummy)
         self.assertEqual(handler.queryUid(dummy, None), None)
@@ -132,7 +130,7 @@
     def test_reregisterObject(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
-        
+
         uid1_reg = handler.register(dummy)
         uid1_get = handler.getUid(dummy)
         uid2_reg = handler.register(dummy)
@@ -140,49 +138,49 @@
         self.assertEqual(uid1_reg, uid2_reg)
         self.assertEqual(uid1_get, uid2_get)
         self.assertEqual(uid1_reg, uid1_get)
-    
+
     def test_unregisterObjectWithoutUid(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
         UniqueIdError = handler.UniqueIdError
-        
+
         self.assertRaises(UniqueIdError, handler.unregister, dummy)
 
     def test_setNewUidByHandWithCheck(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
-        
+
         # registering and unregisterung a object just to get a free uid
         unused_uid = handler.register(dummy)
         handler.unregister(dummy)
-        
+
         handler.setUid(dummy, unused_uid)
-        
+
         result = handler.getUid(dummy)
         self.assertEqual(unused_uid, result)
-        
+
     def test_setSameUidOnSameObjectWithCheck(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
-        
+
         uid = handler.register(dummy)
-        
+
         # just setting the same uid another time is allowed
         handler.setUid(dummy, uid)
-        
+
         result = handler.getUid(dummy)
         self.assertEqual(uid, result)
-        
+
     def test_setExistingUidOnDifferentObjectWithCheckRaisesException(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
         dummy2 = self.root.dummy2
         UniqueIdError = handler.UniqueIdError
-        
+
         # registering and unregisterung a object just to get a free uid
         uid1_reg = handler.register(dummy)
         uid2_reg = handler.register(dummy2)
-        
+
         self.assertRaises(UniqueIdError, handler.setUid, dummy2, uid1_reg)
 
     def test_setExistingUidOnDifferentObjectWithoutCheck(self):
@@ -190,20 +188,20 @@
         dummy = self.root.dummy
         dummy2 = self.root.dummy2
         UniqueIdError = handler.UniqueIdError
-        
+
         # registering and unregisterung a object just to get a free uid
         uid1_reg = handler.register(dummy)
         uid2_reg = handler.register(dummy2)
-        
+
         # now lets double the unique id
         handler.setUid(dummy2, uid1_reg, check_uniqueness=False)
-        
+
         # calling a getter returns one object and generates a log
         # we can't capture. So let's ask the catalog directly.
         catalog = self.root.portal_catalog
         result = catalog({handler.UID_ATTRIBUTE_NAME: uid1_reg})
         self.assertEqual(len(result), 2)
-        
+
         # dummy2 shall not be reachable anymore by uid2_reg
         self.assertRaises(UniqueIdError, handler.getBrain, uid2_reg)
 
@@ -211,28 +209,28 @@
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
         UniqueIdError = handler.UniqueIdError
-        
+
         uid = handler.register(dummy)
-        
+
         self.assertRaises(UniqueIdError, handler.setUid, dummy, None)
 
     def test_setArbitraryKindOfUidRaisesException(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
         UniqueIdError = handler.UniqueIdError
-        
+
         uid = handler.register(dummy)
-        
+
         # As we don't know what kind of exception the implementation
-        # throws lets check for all exceptions! 
+        # throws lets check for all exceptions!
         # IMHO it makes sense here to catch exceptions in general here!
         self.assertRaises(Exception, handler.setUid, dummy, DummyUid())
-        
 
+
 def test_suite():
-    return TestSuite((
-        makeSuite(UniqueIdHandlerTests),
+    return unittest.TestSuite((
+        unittest.makeSuite(UniqueIdHandlerTests),
         ))
 
 if __name__ == '__main__':
-    main(defaultTest='test_suite')
+    unittest.main(defaultTest='test_suite')



More information about the CMF-checkins mailing list