示例#1
0
 def test_subobject_w_post_copy_hook(self):
     from zope.copy.interfaces import ICopyHook
     from zope.location.location import Location
     from zope.location.location import locate
     from zope.copy.examples import Subobject
     o = Location()
     s = Subobject()
     o.subobject = s
     locate(s, o, 'subobject')
     self.assertTrue(s.__parent__ is o)
     self.assertEqual(o.subobject(), 0)
     self.assertEqual(o.subobject(), 1)
     self.assertEqual(o.subobject(), 2)
     class Hook(object):
         def __init__(self, context):
             self.context = context
         def __call__(self, obj, register):
             obj = Subobject()
             def reparent(translate):
                 obj.__parent__ = translate(self.context.__parent__)
             register(reparent)
             return obj
     def _adapt(iface, obj):
         if iface is ICopyHook and isinstance(obj, Subobject):
             return Hook(obj)
     _registerAdapterHook(_adapt)
     c = self._callFUT(o)
     self.assertTrue(c.subobject.__parent__ is c)
     self.assertEqual(c.subobject(), 0)
     self.assertEqual(o.subobject(), 3)
示例#2
0
 def test_subobject_wo_post_copy_hook(self):
     from zope.location.location import Location
     from zope.location.location import locate
     from zope.copy.examples import Subobject
     o = Location()
     s = Subobject()
     o.subobject = s
     locate(s, o, 'subobject')
     self.assertTrue(s.__parent__ is o)
     self.assertEqual(o.subobject(), 0)
     self.assertEqual(o.subobject(), 1)
     self.assertEqual(o.subobject(), 2)
     c = self._callFUT(o)
     self.assertTrue(c.subobject.__parent__ is c)
     self.assertEqual(c.subobject(), 3)
     self.assertEqual(o.subobject(), 3)