Author: jmorliaguet
Date: Sun Jun 18 10:16:45 2006
New Revision: 3446

Modified:
   cpsskins/branches/paris-sprint-2006/elements/format.py
   cpsskins/branches/paris-sprint-2006/elements/portlet.py
   cpsskins/branches/paris-sprint-2006/storage/formats.py
   cpsskins/branches/paris-sprint-2006/storage/interfaces.py
   cpsskins/branches/paris-sprint-2006/storage/locations.py
   cpsskins/branches/paris-sprint-2006/storage/portlets.py
   cpsskins/branches/paris-sprint-2006/storage/relations.py
   cpsskins/branches/paris-sprint-2006/storage/snapshots.py
   cpsskins/branches/paris-sprint-2006/storage/storage.py
   cpsskins/branches/paris-sprint-2006/tests/test_format.py
   cpsskins/branches/paris-sprint-2006/tests/test_storages.py
   cpsskins/branches/paris-sprint-2006/thememanager.py

Log:

- some cleanup

- made sure that storages implement the promised interface



Modified: cpsskins/branches/paris-sprint-2006/elements/format.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/elements/format.py      (original)
+++ cpsskins/branches/paris-sprint-2006/elements/format.py      Sun Jun 18 
10:16:45 2006
@@ -32,7 +32,13 @@
 from cpsskins.utils import getThemeManager, getRelationStorage, cloneObject
 
 class Format(Element):
+    """Base class for format elements
 
+    >>> from zope.interface.verify import verifyClass
+    >>> verifyClass(IFormat, Format)
+    True
+
+    """
     implements(IFormat)
 
     types = []
@@ -48,30 +54,7 @@
 class Formattable(object):
     """This adapter makes elements formattable.
 
-    A formattable element is an element that is associated to a format:
-
-    - via the hasFormat predicate
-
-    In the Formattable API can be accessed via the path adapter:
-
-    >>> from zope.traversing.interfaces import IPathAdapter
-    >>> from zope.component import getAdapter
-    >>> formattable = getAdapter(element, IPathAdapter, "formattable")
-
-    In a ZPT the path adapter is available under the name 'formattable':
-
-    >>> from zope.app.pagetemplate.engine import Engine
-    >>> from zope.tales.tales import Context
-    >>> context = Context(Engine, {})
-
-    We execute a TALES expression and we make sure that getFormats() is called:
-
-    >>> res = Engine.compile('element/formattable:getFormats')
-    >>> res(context)
-    Traceback (most recent call last):
-    ...
-    AttributeError: 'NoneType' object has no attribute 'getStorage'
-
+    A formattable element is an element that is associated to a format
 
     """
     implements(IFormattable, IPathAdapter, ITraversable)

Modified: cpsskins/branches/paris-sprint-2006/elements/portlet.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/elements/portlet.py     (original)
+++ cpsskins/branches/paris-sprint-2006/elements/portlet.py     Sun Jun 18 
10:16:45 2006
@@ -33,7 +33,14 @@
 from cpsskins.utils import getRelationStorage
 
 class Portlet(Persistent, Contained):
-    """Base class for portlets."""
+    """Base class for portlets.
+
+    >>> from zope.interface.verify import verifyClass
+    >>> verifyClass(IPortlet, Portlet)
+    True
+
+    """
+    implements(IPortlet)
 
     identifier = None
 

Modified: cpsskins/branches/paris-sprint-2006/storage/formats.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/storage/formats.py      (original)
+++ cpsskins/branches/paris-sprint-2006/storage/formats.py      Sun Jun 18 
10:16:45 2006
@@ -28,6 +28,12 @@
     contains(IFormat)
 
 class FormatStorage(Storage):
-    """A BTree-based format container"""
+    """A BTree-based format container
+
+    >>> from zope.interface.verify import verifyClass
+    >>> verifyClass(IFormatStorage, FormatStorage)
+    True
+
+    """
     implements(IFormatStorage)
 

Modified: cpsskins/branches/paris-sprint-2006/storage/interfaces.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/storage/interfaces.py   (original)
+++ cpsskins/branches/paris-sprint-2006/storage/interfaces.py   Sun Jun 18 
10:16:45 2006
@@ -21,13 +21,13 @@
 
 class IStorage(Interface):
 
-    def add(object):
+    def add(object, name):
         """Add an object to the storage. Return the added object."""
 
     def remove(objects):
         """Remove an object from the storage."""
 
-    def duplicate(object):
+    def duplicate(object, name):
         """Duplicated an object in the storage.
         Return the object of the duplication."""
 

Modified: cpsskins/branches/paris-sprint-2006/storage/locations.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/storage/locations.py    (original)
+++ cpsskins/branches/paris-sprint-2006/storage/locations.py    Sun Jun 18 
10:16:45 2006
@@ -29,6 +29,12 @@
     contains(ILocation)
 
 class LocationStorage(Storage):
-    """A BTree-based location storage"""
+    """A BTree-based location storage
+
+    >>> from zope.interface.verify import verifyClass
+    >>> verifyClass(ILocationStorage, LocationStorage)
+    True
+
+    """
     implements(ILocationStorage)
 

Modified: cpsskins/branches/paris-sprint-2006/storage/portlets.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/storage/portlets.py     (original)
+++ cpsskins/branches/paris-sprint-2006/storage/portlets.py     Sun Jun 18 
10:16:45 2006
@@ -29,7 +29,12 @@
     contains(IPortlet)
 
 class PortletStorage(Storage):
-    """A BTree-based portlet container"""
+    """A BTree-based portlet container
 
+    >>> from zope.interface.verify import verifyClass
+    >>> verifyClass(IPortletStorage, PortletStorage)
+    True
+
+    """
     implements(IPortletStorage)
 

Modified: cpsskins/branches/paris-sprint-2006/storage/relations.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/storage/relations.py    (original)
+++ cpsskins/branches/paris-sprint-2006/storage/relations.py    Sun Jun 18 
10:16:45 2006
@@ -264,16 +264,18 @@
         self._unindexRelates(key)
         self._p_changed = True
 
-    def add(self, relation):
-        """Choose a name and add the relation to the store.
-        """
+    def add(self, relation, name=u''):
         chooser = INameChooser(self)
-        name = unicode(relation).replace(u'_', u'').replace(u' ', u'')
+        if not name:
+            name = unicode(relation).replace(u'_', u'').replace(u' ', u'')
         relation_name = chooser.chooseName(name, relation)
         self[relation_name] = relation
         logger.debug("Added a relation '%s': '%s'", relation_name,
                      repr(relation))
 
+    def duplicate(self, relation, name=u''):
+        raise NotImplementedError
+
     def remove(self, ids=None):
         """Remove relations for the storage.
         """

Modified: cpsskins/branches/paris-sprint-2006/storage/snapshots.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/storage/snapshots.py    (original)
+++ cpsskins/branches/paris-sprint-2006/storage/snapshots.py    Sun Jun 18 
10:16:45 2006
@@ -29,7 +29,13 @@
     contains(ISnapshot)
 
 class SnapshotStorage(Storage):
-    """A BTree-based snapshot container"""
+    """A BTree-based snapshot container
+
+    >>> from zope.interface.verify import verifyClass
+    >>> verifyClass(ISnapshotStorage, SnapshotStorage)
+    True
+
+    """
     implements(ISnapshotStorage)
 
 

Modified: cpsskins/branches/paris-sprint-2006/storage/storage.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/storage/storage.py      (original)
+++ cpsskins/branches/paris-sprint-2006/storage/storage.py      Sun Jun 18 
10:16:45 2006
@@ -34,6 +34,11 @@
 
 class Storage(BTreeContainer, Contained):
     """A base storage class.
+
+    >>> from zope.interface.verify import verifyClass
+    >>> verifyClass(IStorage, Storage)
+    True
+
     """
     implements(IStorage)
 
@@ -60,23 +65,25 @@
                 raise KeyError("%s not in the storage." % obj)
             del self[obj]
 
-    def duplicate(self, object):
+    def duplicate(self, object, name=u''):
         """Duplicate an object in the storage.
 
         Return the object of the duplication.
         """
-        name = getName(object)
-        if name not in self:
+        old_name = getName(object)
+        if old_name not in self:
             raise KeyError("%s not in the storage." % object)
 
         copy = cloneObject(object)
         notify(ObjectCopiedEvent(copy, object))
 
-        new_name = INameChooser(self).chooseName(name, copy)
-        self[new_name] = copy
+        if not name:
+            name = old_name
+        name = INameChooser(self).chooseName(name, copy)
+        self[name] = copy
         notify(ObjectAddedEvent(copy))
 
-        return self[new_name]
+        return self[name]
 
     def purge(self):
         self.remove(list(self))

Modified: cpsskins/branches/paris-sprint-2006/tests/test_format.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/tests/test_format.py    (original)
+++ cpsskins/branches/paris-sprint-2006/tests/test_format.py    Sun Jun 18 
10:16:45 2006
@@ -43,8 +43,7 @@
         unittest.makeSuite(TestLayout),
         unittest.makeSuite(TestStyle),
         unittest.makeSuite(TestWidget),
-        # TODO fix test setup
-        # DocTestSuite('cpsskins.elements.format', setUp=setUp),
+        DocTestSuite('cpsskins.elements.format', setUp=setUp),
         DocTestSuite('cpsskins.standard.formats.layout', setUp=setUp),
         DocTestSuite('cpsskins.standard.formats.style', setUp=setUp),
         DocTestSuite('cpsskins.standard.formats.widget', setUp=setUp),

Modified: cpsskins/branches/paris-sprint-2006/tests/test_storages.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/tests/test_storages.py  (original)
+++ cpsskins/branches/paris-sprint-2006/tests/test_storages.py  Sun Jun 18 
10:16:45 2006
@@ -245,7 +245,12 @@
 
 def test_suite():
     return unittest.TestSuite((
+        DocTestSuite('cpsskins.storage.formats'),
+        DocTestSuite('cpsskins.storage.locations'),
+        DocTestSuite('cpsskins.storage.portlets'),
         DocTestSuite('cpsskins.storage.relations'),
+        DocTestSuite('cpsskins.storage.snapshots'),
+        DocTestSuite('cpsskins.storage.storage'),
         unittest.makeSuite(TestStorageNameChooser),
         unittest.makeSuite(TestRelationStorage),
         ))

Modified: cpsskins/branches/paris-sprint-2006/thememanager.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/thememanager.py (original)
+++ cpsskins/branches/paris-sprint-2006/thememanager.py Sun Jun 18 10:16:45 2006
@@ -135,13 +135,17 @@
     def addPerspective(perspective, id):
         """Add a perspective to the storage"""
 
-    def getLocations(self, context):
+    def getLocations(context):
         """Return the list of locations in a given context"""
 
 class ThemeManagementFolder(BTreeContainer, PersistentComponents):
     """A theme management utility that can contain multiple .
     themes
 
+    >>> from zope.interface.verify import verifyClass
+    >>> verifyClass(IThemeManagementFolder, ThemeManagementFolder)
+    True
+
     """
     implements(IThemeManagementFolder, IThemeContainer)
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to