[Zope-CVS] SVN: zversioning/trunk/src/versioning/tests/ intermediate commit to save work

Uwe Oestermeier uwe_oestermeier at iwm-kmrc.de
Sun Oct 10 07:14:44 EDT 2004


Log message for revision 27886:
  intermediate commit to save work


Changed:
  U   zversioning/trunk/src/versioning/tests/README.txt
  U   zversioning/trunk/src/versioning/tests/repository_setup.py
  U   zversioning/trunk/src/versioning/tests/test_versioncontrol.py


-=-
Modified: zversioning/trunk/src/versioning/tests/README.txt
===================================================================
--- zversioning/trunk/src/versioning/tests/README.txt	2004-10-10 11:05:55 UTC (rev 27885)
+++ zversioning/trunk/src/versioning/tests/README.txt	2004-10-10 11:14:44 UTC (rev 27886)
@@ -3,19 +3,109 @@
 
 
 We start by testing some of the existing infrastructure from zope.app.versioncontrol
-and try to apply the existing versioning to sample data. We take the sample
-folder tree:
+and try to apply the existing versioning to sample data. We take a simple
+folder tree with the following structure :
 
+  sample
+    |--> a <--|
+    |--> b    |
+         |--> c
+     
+
   >>> import zope.app.versioncontrol.interfaces
+  >>> from zope.interface import directlyProvides
   >>> from zope.app.versioncontrol.repository import declare_versioned
-  >>> from zope.app.tests.setup import buildSampleFolderTree
-  >>> folder = buildSampleFolderTree()
-  >>> len(folder.keys())
-  2
-  >>> declare_versioned(folder)
-  >>> zope.app.versioncontrol.interfaces.IVersioned.providedBy(folder)
+  >>> from versioning.tests.repository_setup import registerAdapter
+  >>> from zope.app.folder import Folder, rootFolder
+  >>> registerAdapter()
+  
+  
+  >>> sample = rootFolder()
+  >>> directlyProvides(sample, zope.app.traversing.interfaces.IContainmentRoot)
+  >>> a = sample["a"] = Folder()
+  >>> b = sample["b"] = Folder()
+  >>> c = b["c"] = Folder()
+  >>> for x in (sample, a, b, c) :
+  ...     directlyProvides(x, zope.app.versioncontrol.interfaces.IVersionable)
+  
+The interesting test case is the reference that uses references outside
+the hierarchical ones, which should be naturally handled in Zope3:
+
+  >>> c.refers_to = a
+  >>> a == c.refers_to
   True
 
+In order to show some limitations of the current implementation we use a
+prebuild version control repository :
+
+  >>> from versioning.tests.repository_setup import buildOldStyleRepository, buildDatabaseRoot
+  >>> db_root = buildDatabaseRoot()
+  >>> db_root["sample"] = sample 
+  >>> repository = buildOldStyleRepository()
+  
+The current policy forces us to remove __parent__ and __name__. We'll do that
+by specializing the standard adapter that removes nothing:
+
+  >>> from zope.app.versioncontrol.nonversioned import StandardNonVersionedDataAdapter
+  >>> class NonVersionedAdapter(StandardNonVersionedDataAdapter) :
+  ...     attrs = ("__name__", "__parent__")   # remove __name__ and __parent from versioning
+  
+  
+  >>> from zope.app.tests import ztapi
+  >>> ztapi.provideAdapter(zope.app.versioncontrol.interfaces.IVersionable,
+  ...                       zope.app.versioncontrol.interfaces.INonVersionedData,
+  ...                       NonVersionedAdapter)
+  >>> zope.app.versioncontrol.interfaces.INonVersionedData(a) is not None
+  True
+
+Now we can put our example data under version control:
+
+  >>> repository.applyVersionControl(sample)
+  >>> repository.applyVersionControl(a)
+  >>> repository.applyVersionControl(b)
+  >>> repository.applyVersionControl(c)
+  >>> util.commit()
+  >>> [x for interfaces.IVersioned.providedBy(x) in (sample, a, b, c)]
+  [True, True, True, True]
+    
+
+The implementation in zope.app.versioncontrol breaks any database identity references
+because a pickle version is used that ignores all references that point
+outside the sub tree. In the example above this means, that the version of c loses
+its reference to a because c is not contained in a. (See 
+ zope.app.versioncontrol.version.cloneByPickle)
+
+  >>> a_info = repository.getVersionInfo(a)
+  >>> a_version = a_info._data
+  >>> c_info = repository.getVersionInfo(c)
+  >>> c_version = c_info._data
+  >>> c_version.refers_to == a_version
+  False
+  
+
+
+
+
+
+
+Extensions: We want to define a repository that works as a black box and returns
+only a ticket which guarantees that we get a valid copy back if we use this ticket.
+
+class IRepository(Interface) :
+
+    def register(self, obj) :
+        """ Returns an ITicket. """
+        
+    def retrieve(self, ticket) :
+        """ Returns an object or throws an ObjectNotFound 
+            or ObjectPermanentylDeleted exception.
+        """
+    
+We want to use versioning with object other than standard zope objects that use
+only the standard containment structure meachanism.
+
+
+    
 This package provides a framework for managing multiple versions of objects
 within a ZODB database.  The framework defines several interfaces that objects
 may provide to participate with the framework.  For an object to particpate in
@@ -35,69 +125,8 @@
 implementation of INonVersionedData has to deal with these for objects that
 contain their own location information.
 
-  >>> import persistent
-  >>> import zope.interface
-  >>> import zope.app.annotation.attribute
-  >>> import zope.app.annotation.interfaces
-  >>> import zope.app.traversing.interfaces
-  >>> from zope.app.versioncontrol import interfaces
-  
-  >>> marker = object()
 
-  >>> class Sample(persistent.Persistent):
-  ...     zope.interface.implements(
-  ...         interfaces.IVersionable,
-  ...         interfaces.INonVersionedData,
-  ...         zope.app.annotation.interfaces.IAttributeAnnotatable,
-  ...         zope.app.traversing.interfaces.IPhysicallyLocatable,
-  ...         )
-  ...   
-  ...     # Methods defined by INonVersionedData
-  ...     # This is a trivial implementation; using INonVersionedData
-  ...     # is discussed later.
-  ...
-  ...     def listNonVersionedObjects(self):
-  ...         return ()
-  ...
-  ...     def removeNonVersionedData(self):
-  ...         if "__name__" in self.__dict__:
-  ...             del self.__name__
-  ...         if "__parent__" in self.__dict__:
-  ...             del self.__parent__
-  ...
-  ...     def getNonVersionedData(self):
-  ...         return (getattr(self, "__name__", marker),
-  ...                 getattr(self, "__parent__", marker))
-  ...
-  ...     def restoreNonVersionedData(self, data):
-  ...         name, parent = data
-  ...         if name is not marker:
-  ...             self.__name__ = name
-  ...         if parent is not marker:
-  ...             self.__parent__ = parent
-  ...
-  ...     # Method from IPhysicallyLocatable that is actually used:
-  ...     def getPath(self):
-  ...         return '/' + self.__name__
 
-  >>> from zope.app.tests import ztapi
-  >>> ztapi.provideAdapter(zope.app.annotation.interfaces.IAttributeAnnotatable,
-  ...                      zope.app.annotation.interfaces.IAnnotations,
-  ...                      zope.app.annotation.attribute.AttributeAnnotations)
-
-Now we need to create a database with an instance of our sample object to work
-with:
-
-  >>> from ZODB.tests import util
-  >>> db = util.DB()
-  >>> connection = db.open()
-  >>> root = connection.root()
-
-  >>> samp = Sample()
-  >>> samp.__name__ = "samp"
-  >>> root["samp"] = samp
-  >>> util.commit()
-
 Some basic queries may be asked of objects without using an instance of
 `IVersionControl`.  In particular, we can determine whether an object can be
 managed by version control by checking for the `IVersionable` interface:

Modified: zversioning/trunk/src/versioning/tests/repository_setup.py
===================================================================
--- zversioning/trunk/src/versioning/tests/repository_setup.py	2004-10-10 11:05:55 UTC (rev 27885)
+++ zversioning/trunk/src/versioning/tests/repository_setup.py	2004-10-10 11:14:44 UTC (rev 27886)
@@ -7,26 +7,48 @@
 import zope.app.annotation.interfaces
 import zope.app.traversing.interfaces
 from zope.app.versioncontrol import interfaces
+from zope.app.tests import ztapi
 
-def buildDatabaseRoot():
-    """Opens a connection to a test database and returns the root object
-    """
-    from zope.app.tests import ztapi
-    ztapi.provideAdapter(zope.app.annotation.interfaces.IAttributeAnnotatable,
-                         zope.app.annotation.interfaces.IAnnotations,
-                         zope.app.annotation.attribute.AttributeAnnotations,
-    ztapi.provideAdapter(zope.app.traversing.interfaces.IPhysicallyLocatable,
-                         zope.app.location.interfaces.ILocation,
-                         zope.app.location.traversing.LocationPhysicallyLocatable)
+from zope.interface import classImplements
 
-  <adapter 
-      for="zope.app.location.interfaces.ILocation"
-      provides="zope.app.traversing.interfaces.IPhysicallyLocatable"
-      factory="zope.app.location.traversing.LocationPhysicallyLocatable" 
-      />
+from zope.app.traversing.interfaces import ITraversable, ITraverser
+from zope.app.traversing.interfaces import IPhysicallyLocatable
+from zope.app.traversing.interfaces import IContainmentRoot
+from zope.app.traversing.adapters import DefaultTraversable
+from zope.app.location.traversing import LocationPhysicallyLocatable
+from zope.app.traversing.adapters import RootPhysicallyLocatable
+from zope.app.traversing.adapters import Traverser
 
+from zope.app.annotation.interfaces import IAttributeAnnotatable
+from zope.app.annotation.attribute import AttributeAnnotations
+from zope.app.dublincore.interfaces import IZopeDublinCore
+from zope.app.dublincore.annotatableadapter import ZDCAnnotatableAdapter
+from zope.app.annotation.interfaces import IAnnotatable, IAnnotations
+from zope.app.container.interfaces import IContainer
+from zope.app.file.interfaces import IFile
+from zope.app.file.file import File
+from zope.app.folder.folder import Folder
 
 
+def registerAdapter() :
+    """ Register some common adapter. """ 
+
+    classImplements(File, IAttributeAnnotatable)
+    classImplements(Folder, IAttributeAnnotatable)
+
+    ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations, AttributeAnnotations)
+    ztapi.provideAdapter(None, ITraverser, Traverser)
+    ztapi.provideAdapter(None, ITraversable, DefaultTraversable)
+    ztapi.provideAdapter(None, IPhysicallyLocatable, LocationPhysicallyLocatable)
+    ztapi.provideAdapter(IContainmentRoot, IPhysicallyLocatable, RootPhysicallyLocatable)
+    ztapi.provideAdapter(IAnnotatable, IZopeDublinCore, ZDCAnnotatableAdapter)
+
+
+
+def buildDatabaseRoot():
+    """Opens a connection to a test database and returns the root object
+    """
+     
     # Now we need to create a database with an instance of our sample object 
     # to work with:
     
@@ -75,3 +97,5 @@
     zope.security.management.newInteraction(participation)
 
     return repository
+
+

Modified: zversioning/trunk/src/versioning/tests/test_versioncontrol.py
===================================================================
--- zversioning/trunk/src/versioning/tests/test_versioncontrol.py	2004-10-10 11:05:55 UTC (rev 27885)
+++ zversioning/trunk/src/versioning/tests/test_versioncontrol.py	2004-10-10 11:14:44 UTC (rev 27886)
@@ -32,7 +32,7 @@
 
 from zope.app.tests.setup import buildSampleFolderTree
 
-def buildSite(items=None) :
+def setUpOldStyleVersionControl() :
     """ Returns s small test site of original content objects:
     
         >>> folders = buildSampleFolderTree()



More information about the Zope-CVS mailing list