[Checkins] SVN: zope.lifecycleevent/branches/movedaddedremoved/ - Create a branch with ``IObjectMovedEvent``, ``IObjectAddedEvent``,

Chris McDonough chrism at plope.com
Fri May 15 04:11:45 EDT 2009


Log message for revision 99966:
  - Create a branch with ``IObjectMovedEvent``, ``IObjectAddedEvent``,
    ``IObjectRemovedEvent`` interfaces and ``ObjectMovedEvent``,
    ``ObjectAddedEvent`` and ``ObjectRemovedEvent`` classes copied from
    zope.container (plus tests).  The intent is to allow packages that
    rely on these interfaces or the event classes to rely on
    zope.lifecycleevent (which has few dependencies) instead of
    zope.container (which has many).
  
  

Changed:
  U   zope.lifecycleevent/branches/movedaddedremoved/CHANGES.txt
  U   zope.lifecycleevent/branches/movedaddedremoved/src/zope/lifecycleevent/__init__.py
  U   zope.lifecycleevent/branches/movedaddedremoved/src/zope/lifecycleevent/interfaces.py
  U   zope.lifecycleevent/branches/movedaddedremoved/src/zope/lifecycleevent/tests.py

-=-
Modified: zope.lifecycleevent/branches/movedaddedremoved/CHANGES.txt
===================================================================
--- zope.lifecycleevent/branches/movedaddedremoved/CHANGES.txt	2009-05-15 08:07:29 UTC (rev 99965)
+++ zope.lifecycleevent/branches/movedaddedremoved/CHANGES.txt	2009-05-15 08:11:45 UTC (rev 99966)
@@ -2,10 +2,16 @@
 CHANGES
 =======
 
-3.5.2 (unreleased)
-------------------
+movedaddedremoved-branch (unreleased)
+-------------------------------------
 
-- ...
+- Create a branch with ``IObjectMovedEvent``, ``IObjectAddedEvent``,
+  ``IObjectRemovedEvent`` interfaces and ``ObjectMovedEvent``,
+  ``ObjectAddedEvent`` and ``ObjectRemovedEvent`` classes copied from
+  zope.container (plus tests).  The intent is to allow packages that
+  rely on these interfaces or the event classes to rely on
+  zope.lifecycleevent (which has few dependencies) instead of
+  zope.container (which has many).
 
 3.5.1 (2009-03-09)
 ------------------

Modified: zope.lifecycleevent/branches/movedaddedremoved/src/zope/lifecycleevent/__init__.py
===================================================================
--- zope.lifecycleevent/branches/movedaddedremoved/src/zope/lifecycleevent/__init__.py	2009-05-15 08:07:29 UTC (rev 99965)
+++ zope.lifecycleevent/branches/movedaddedremoved/src/zope/lifecycleevent/__init__.py	2009-05-15 08:11:45 UTC (rev 99966)
@@ -17,17 +17,21 @@
 """
 __docformat__ = 'restructuredtext'
 
-import zope.component.interfaces
+from zope.component.interfaces import ObjectEvent
 from zope.interface import implements
 from zope.event import notify
 
 from zope.lifecycleevent.interfaces import IObjectCreatedEvent
 from zope.lifecycleevent.interfaces import IObjectModifiedEvent
 from zope.lifecycleevent.interfaces import IObjectCopiedEvent
-from zope.lifecycleevent.interfaces import IAttributes, ISequence
+from zope.lifecycleevent.interfaces import IObjectMovedEvent
+from zope.lifecycleevent.interfaces import IObjectAddedEvent
+from zope.lifecycleevent.interfaces import IObjectRemovedEvent
+from zope.lifecycleevent.interfaces import IAttributes
+from zope.lifecycleevent.interfaces import ISequence
 
 
-class ObjectCreatedEvent(zope.component.interfaces.ObjectEvent):
+class ObjectCreatedEvent(ObjectEvent):
     """An object has been created"""
 
     implements(IObjectCreatedEvent)
@@ -72,7 +76,7 @@
         self.interface = interface
         self.keys = keys
 
-class ObjectModifiedEvent(zope.component.interfaces.ObjectEvent):
+class ObjectModifiedEvent(ObjectEvent):
     """An object has been modified"""
 
     implements(IObjectModifiedEvent)
@@ -108,3 +112,40 @@
     def __init__(self, object, original):
         super(ObjectCopiedEvent, self).__init__(object)
         self.original = original
+
+class ObjectMovedEvent(ObjectEvent):
+    """An object has been moved"""
+
+    implements(IObjectMovedEvent)
+
+    def __init__(self, object, oldParent, oldName, newParent, newName):
+        ObjectEvent.__init__(self, object)
+        self.oldParent = oldParent
+        self.oldName = oldName
+        self.newParent = newParent
+        self.newName = newName
+
+class ObjectAddedEvent(ObjectMovedEvent):
+    """An object has been added to a container"""
+
+    implements(IObjectAddedEvent)
+
+    def __init__(self, object, newParent=None, newName=None):
+        if newParent is None:
+            newParent = object.__parent__
+        if newName is None:
+            newName = object.__name__
+        ObjectMovedEvent.__init__(self, object, None, None, newParent, newName)
+
+class ObjectRemovedEvent(ObjectMovedEvent):
+    """An object has been removed from a container"""
+
+    implements(IObjectRemovedEvent)
+
+    def __init__(self, object, oldParent=None, oldName=None):
+        if oldParent is None:
+            oldParent = object.__parent__
+        if oldName is None:
+            oldName = object.__name__
+        ObjectMovedEvent.__init__(self, object, oldParent, oldName, None, None)
+

Modified: zope.lifecycleevent/branches/movedaddedremoved/src/zope/lifecycleevent/interfaces.py
===================================================================
--- zope.lifecycleevent/branches/movedaddedremoved/src/zope/lifecycleevent/interfaces.py	2009-05-15 08:07:29 UTC (rev 99965)
+++ zope.lifecycleevent/branches/movedaddedremoved/src/zope/lifecycleevent/interfaces.py	2009-05-15 08:11:45 UTC (rev 99966)
@@ -58,3 +58,33 @@
 
     interface = Attribute("The involved interface.")
     keys = Attribute("A sequence of modified keys.")
+
+
+##############################################################################
+# Moving Objects
+
+class IObjectMovedEvent(zope.component.interfaces.IObjectEvent):
+    """An object has been moved."""
+
+    oldParent = Attribute("The old location parent for the object.")
+    oldName = Attribute("The old location name for the object.")
+    newParent = Attribute("The new location parent for the object.")
+    newName = Attribute("The new location name for the object.")
+
+
+##############################################################################
+# Adding objects
+
+class IObjectAddedEvent(IObjectMovedEvent):
+    """An object has been added to a container."""
+
+
+##############################################################################
+# Removing objects
+
+
+class IObjectRemovedEvent(IObjectMovedEvent):
+    """An object has been removed from a container."""
+
+
+

Modified: zope.lifecycleevent/branches/movedaddedremoved/src/zope/lifecycleevent/tests.py
===================================================================
--- zope.lifecycleevent/branches/movedaddedremoved/src/zope/lifecycleevent/tests.py	2009-05-15 08:07:29 UTC (rev 99965)
+++ zope.lifecycleevent/branches/movedaddedremoved/src/zope/lifecycleevent/tests.py	2009-05-15 08:11:45 UTC (rev 99966)
@@ -31,6 +31,128 @@
     def testGetObject(self):
         self.assertEqual(self.event.object, self.object)
 
+class TestObjectMovedEvent(unittest.TestCase):
+
+    def _getTargetClass(self):
+        from zope.lifecycleevent import ObjectMovedEvent
+        return ObjectMovedEvent
+
+    def _makeOne(self, *arg):
+        return self._getTargetClass()(*arg)
+
+    def test_it(self):
+        ob = Context()
+        old_parent = Context()
+        new_parent = Context()
+        event = self._makeOne(ob, old_parent, 'old_name', new_parent,
+                              'new_name')
+        self.assertEqual(event.object, ob)
+        self.assertEqual(event.oldParent, old_parent)
+        self.assertEqual(event.newParent, new_parent)
+        self.assertEqual(event.newName, 'new_name')
+        self.assertEqual(event.oldName, 'old_name')
+
+    def test_verifyClass(self):
+        from zope.interface.verify import verifyClass
+        from zope.lifecycleevent.interfaces import IObjectMovedEvent
+        verifyClass(IObjectMovedEvent, self._getTargetClass())
+        
+    def test_verifyObject(self):
+        from zope.interface.verify import verifyObject
+        from zope.lifecycleevent.interfaces import IObjectMovedEvent
+        verifyObject(IObjectMovedEvent,
+                     self._makeOne(None, None, None, None, None)
+                    )
+
+class TestObjectAddedEvent(unittest.TestCase):
+
+    def _getTargetClass(self):
+        from zope.lifecycleevent import ObjectAddedEvent
+        return ObjectAddedEvent
+
+    def _makeOne(self, *arg):
+        return self._getTargetClass()(*arg)
+
+    def test_it(self):
+        ob = Context()
+        new_parent = Context()
+        event = self._makeOne(ob, new_parent, 'new_name')
+        self.assertEqual(event.object, ob)
+        self.assertEqual(event.newParent, new_parent)
+        self.assertEqual(event.newName, 'new_name')
+        self.assertEqual(event.oldParent, None)
+        self.assertEqual(event.oldName, None)
+
+    def test_it_Nones(self):
+        ob = Context()
+        new_parent = Context()
+        ob.__parent__ = new_parent
+        ob.__name__ = 'new_name'
+        event = self._makeOne(ob, None, None)
+        self.assertEqual(event.object, ob)
+        self.assertEqual(event.newParent, new_parent)
+        self.assertEqual(event.newName, 'new_name')
+        self.assertEqual(event.oldParent, None)
+        self.assertEqual(event.oldName, None)
+
+    def test_verifyClass(self):
+        from zope.interface.verify import verifyClass
+        from zope.lifecycleevent.interfaces import IObjectAddedEvent
+        verifyClass(IObjectAddedEvent, self._getTargetClass())
+        
+    def test_verifyObject(self):
+        from zope.interface.verify import verifyObject
+        from zope.lifecycleevent.interfaces import IObjectAddedEvent
+        parent = Context()
+        ob = Context()
+        verifyObject(IObjectAddedEvent, self._makeOne(ob, parent, 'new_name'))
+
+class TestObjectRemovedEvent(unittest.TestCase):
+
+    def _getTargetClass(self):
+        from zope.lifecycleevent import ObjectRemovedEvent
+        return ObjectRemovedEvent
+
+    def _makeOne(self, *arg):
+        return self._getTargetClass()(*arg)
+
+    def test_it(self):
+        ob = Context()
+        parent = Context()
+        event = self._makeOne(ob, parent, 'name')
+        self.assertEqual(event.object, ob)
+        self.assertEqual(event.newParent, None)
+        self.assertEqual(event.newName, None)
+        self.assertEqual(event.oldParent, parent)
+        self.assertEqual(event.oldName, 'name')
+
+    def test_it_Nones(self):
+        ob = Context()
+        parent = Context()
+        ob.__parent__ = parent
+        ob.__name__ = 'name'
+        event = self._makeOne(ob, None, None)
+        self.assertEqual(event.object, ob)
+        self.assertEqual(event.newParent, None)
+        self.assertEqual(event.newName,  None)
+        self.assertEqual(event.oldParent, parent)
+        self.assertEqual(event.oldName, 'name')
+
+    def test_verifyClass(self):
+        from zope.interface.verify import verifyClass
+        from zope.lifecycleevent.interfaces import IObjectRemovedEvent
+        verifyClass(IObjectRemovedEvent, self._getTargetClass())
+        
+    def test_verifyObject(self):
+        from zope.interface.verify import verifyObject
+        from zope.lifecycleevent.interfaces import IObjectRemovedEvent
+        parent = object()
+        ob = object()
+        verifyObject(IObjectRemovedEvent, self._makeOne(ob, parent, 'new_name'))
+
+class Context:
+    pass
+
 def setUpDoctest(test):
     from zope.annotation.attribute import AttributeAnnotations
     from zope.dublincore.interfaces import IWriteZopeDublinCore
@@ -42,6 +164,9 @@
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(TestObjectModifiedEvent),
+        unittest.makeSuite(TestObjectMovedEvent),
+        unittest.makeSuite(TestObjectAddedEvent),
+        unittest.makeSuite(TestObjectRemovedEvent),
         doctest.DocFileSuite('README.txt', setUp=setUpDoctest,
                              tearDown=zope.component.testing.tearDown),
         ))



More information about the Checkins mailing list