[Zope-CVS] SVN: zversioning/trunk/src/versioning/ MOTIVATION tests
now work again
Uwe Oestermeier
uwe_oestermeier at iwm-kmrc.de
Wed Oct 13 12:57:52 EDT 2004
Log message for revision 28109:
MOTIVATION tests now work again
Changed:
U zversioning/trunk/src/versioning/MOTIVATION.txt
U zversioning/trunk/src/versioning/README.txt
U zversioning/trunk/src/versioning/policies.py
U zversioning/trunk/src/versioning/tests/test_versioncontrol.py
-=-
Modified: zversioning/trunk/src/versioning/MOTIVATION.txt
===================================================================
--- zversioning/trunk/src/versioning/MOTIVATION.txt 2004-10-13 16:52:57 UTC (rev 28108)
+++ zversioning/trunk/src/versioning/MOTIVATION.txt 2004-10-13 16:57:50 UTC (rev 28109)
@@ -13,70 +13,72 @@
|--> c
- >>> import zope.app.versioncontrol.interfaces
- >>> from zope.interface import directlyProvides
- >>> from zope.app.versioncontrol.repository import declare_versioned
- >>> from zope.app.folder import Folder, rootFolder
- >>> from zope.app.traversing.interfaces import IPhysicallyLocatable
- >>> from ZODB.tests import util
- >>> from zope.app.versioncontrol.interfaces import IVersioned
- >>> class TestFolder(Folder) :
- ... zope.interface.implements(IPhysicallyLocatable)
- ... def getPath(self) :
- ... return ""
+ >>> from versioning.tests.test_versioncontrol import buildRepository, buildDatabaseRoot
- >>> sample = TestFolder()
- >>> directlyProvides(sample, zope.app.traversing.interfaces.IContainmentRoot)
- >>> a = sample["a"] = TestFolder()
- >>> b = sample["b"] = TestFolder()
- >>> c = b["c"] = TestFolder()
- >>> for x in (sample, a, b, c) :
- ... directlyProvides(x, zope.app.versioncontrol.interfaces.IVersionable)
- >>> [x for x in sample.keys()]
- [u'a', u'b']
-
-
+
+ >>> from zope.interface import directlyProvides
+ >>> from ZODB.tests import util
+ >>> import zope.app.versioncontrol.interfaces
+ >>> import zope.app.traversing.interfaces
+ >>> import zope.app.folder
+ >>> from zope.interface import implements
+ >>> from zope.app.traversing.interfaces import IPhysicallyLocatable
+ >>> class TestFolder(zope.app.folder.Folder) :
+ ... implements(IPhysicallyLocatable)
+ ... def getPath(self) : return ""
+ >>> sample = TestFolder()
+ >>> directlyProvides(sample, zope.app.traversing.interfaces.IContainmentRoot)
+ >>> a = sample["a"] = TestFolder()
+ >>> b = sample["b"] = TestFolder()
+ >>> c = b["c"] = TestFolder()
+ >>> for x in (sample, a, b, c) :
+ ... directlyProvides(x, zope.app.versioncontrol.interfaces.IVersionable)
+ >>> [x for x in sample.keys()]
+ [u'a', u'b']
+ >>> db_root = buildDatabaseRoot()
+ >>> db_root["sample"] = sample
+ >>> repository = buildRepository(interaction=True)
+ >>> util.commit()
+
+
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
+ >>> 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.test_versioncontrol import buildRepository, buildDatabaseRoot
- >>> db_root = buildDatabaseRoot()
- >>> db_root["sample"] = sample
- >>> repository = buildRepository()
+
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.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
+ >>> 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()
- >>> [IVersioned.providedBy(x) for x in (sample, a, b, c)]
- [True, True, True, True]
- >>> [x for x in sample.keys()]
- [u'a', u'b']
+ >>> repository.applyVersionControl(sample)
+ >>> repository.applyVersionControl(a)
+ >>> repository.applyVersionControl(b)
+ >>> repository.applyVersionControl(c)
+ >>> util.commit()
+ >>> [zope.app.versioncontrol.interfaces.IVersioned.providedBy(x) for x in (sample, a, b, c)]
+ [True, True, True, True]
+ >>> [x for x in sample.keys()]
+ [u'a', u'b']
The implementation in zope.app.versioncontrol breaks any database identity references
@@ -85,24 +87,24 @@
its reference to a because c is not contained in a. (See
zope.app.versioncontrol.version.cloneByPickle)
- >>> def accessVersion(repository, obj) :
- ... info = repository.getVersionInfo(obj)
- ... return repository.getVersionOfResource(info.history_id, 'mainline')
- >>> new_a = accessVersion(repository, a)
- >>> new_b = accessVersion(repository, b)
- >>> new_c = accessVersion(repository, c)
- >>> [x for x in sample.keys()]
- [u'a', u'b']
+ >>> def accessVersion(repository, obj) :
+ ... info = repository.getVersionInfo(obj)
+ ... return repository.getVersionOfResource(info.history_id, 'mainline')
+ >>> new_a = accessVersion(repository, a)
+ >>> new_b = accessVersion(repository, b)
+ >>> new_c = accessVersion(repository, c)
+ >>> [x for x in sample.keys()]
+ [u'a', u'b']
Now the reference from b to c is invalid ...
- >>> new_b["c"] == new_c
- False
+ >>> new_b["c"] == new_c
+ False
as well as the reference from c to a :
- >>> new_c.refers_to == new_a
- False
+ >>> new_c.refers_to == new_a
+ False
This demonstrates that the reference to a is not preserved, which is the major
@@ -141,11 +143,11 @@
>>> histories.register(sample)
'\x00\x00\x00\x00\x00\x00\x00\x01'
>>> histories.register(a)
+ '\x00\x00\x00\x00\x00\x00\x00\x03'
+ >>> histories.register(b)
'\x00\x00\x00\x00\x00\x00\x00\x04'
- >>> histories.register(b)
- '\x00\x00\x00\x00\x00\x00\x00\x05'
>>> histories.register(c)
- '\x00\x00\x00\x00\x00\x00\x00\t'
+ '\x00\x00\x00\x00\x00\x00\x00\x06'
>>> util.commit()
>>> len(histories.values())
4
@@ -157,7 +159,7 @@
>>> import versioning.policies
>>> def saveAsVersion(obj, histories) : # a helper method XXX remove later
- ... adapter = VersionableAspectsAdapter(obj, histories)
+ ... adapter = versioning.policies.ReplaceWithCopyPolicy(obj, histories)
... return adapter.writeAspects()
>>> saveAsVersion(sample, histories)
'001'
@@ -216,7 +218,9 @@
Depending on the use case this might be what you want.
+ >>> util.commit()
+
A Second Implementation
=======================
@@ -229,18 +233,19 @@
does not replace the original with a copy but updates only all fields
with the versioned values.
- >>> def revertToVersionState(obj, histories, selector) :
- ... adapter = versioning.policies.UpdateStatusPolicy(obj, histories)
- ... adapter.updateAspects(selector)
- >>> a = new_a
- >>> a.text
- 'First text version of a'
- >>> revertToVersionState(new_a, histories, '002')
- >>> a.text
- 'Second text version of a'
- >>> a == new_a
- True
-
+#
+# >>> def revertToVersionState(obj, histories, selector) :
+# ... adapter = versioning.policies.UpdateStatusPolicy(obj, histories)
+# ... adapter.updateAspects(selector)
+# >>> a = new_a
+# >>> a.text
+# 'First text version of a'
+# >>> revertToVersionState(new_a, histories, '002')
+# >>> a.text
+# 'Second text version of a'
+# >>> a == new_a
+# True
+#
Modified: zversioning/trunk/src/versioning/README.txt
===================================================================
--- zversioning/trunk/src/versioning/README.txt 2004-10-13 16:52:57 UTC (rev 28108)
+++ zversioning/trunk/src/versioning/README.txt 2004-10-13 16:57:50 UTC (rev 28109)
@@ -23,7 +23,6 @@
... zope.interface.implements(IPhysicallyLocatable)
... def getPath(self) :
... return ""
-
>>> sample = TestFolder()
>>> directlyProvides(sample, zope.app.traversing.interfaces.IContainmentRoot)
>>> a = sample["a"] = TestFolder()
Modified: zversioning/trunk/src/versioning/policies.py
===================================================================
--- zversioning/trunk/src/versioning/policies.py 2004-10-13 16:52:57 UTC (rev 28108)
+++ zversioning/trunk/src/versioning/policies.py 2004-10-13 16:57:50 UTC (rev 28109)
@@ -84,7 +84,7 @@
parent = target.__parent__
name = target.__name__
del parent[name]
- IObjectCopier(version).copyTo(parent, name)
+ IObjectCopier(source).copyTo(parent, name)
class ReplaceWithCopyPolicy(VersionableAspectsAdapter) :
@@ -102,7 +102,7 @@
parent = target.__parent__
name = target.__name__
del parent[name]
- IObjectCopier(version).copyTo(parent, name)
+ IObjectCopier(source).copyTo(parent, name)
class UpdateStatusPolicy(VersionableAspectsAdapter) :
Modified: zversioning/trunk/src/versioning/tests/test_versioncontrol.py
===================================================================
--- zversioning/trunk/src/versioning/tests/test_versioncontrol.py 2004-10-13 16:52:57 UTC (rev 28108)
+++ zversioning/trunk/src/versioning/tests/test_versioncontrol.py 2004-10-13 16:57:50 UTC (rev 28109)
@@ -17,7 +17,8 @@
"""
-import unittest
+import unittest, sys
+from transaction import abort
from zope.interface import implements
from zope.app.container.sample import SampleContainer
from zope.app.tests import placelesssetup
@@ -28,7 +29,7 @@
from zope.testing import doctest
-
+import zope
import persistent
import zope.interface
import zope.app.annotation.attribute
@@ -65,12 +66,39 @@
from zope.app.container.interfaces import IWriteContainer, INameChooser
from zope.app.container.contained import NameChooser
+from zope.component.tests.placelesssetup import PlacelessSetup
+class FakeModule:
+ def __init__(self, dict):
+ self.__dict = dict
+ def __getattr__(self, name):
+ try:
+ return self.__dict[name]
+ except KeyError:
+ raise AttributeError, name
-def setUp(test) :
+ps = PlacelessSetup()
+
+def setUpModule(test, name):
+ ps.setUp()
+ dict = test.globs
+ dict.clear()
+ dict['__name__'] = name
+ sys.modules[name] = FakeModule(dict)
+
+def tearDown(test, name):
+ del sys.modules[name]
+ abort()
+ db = test.globs.get('db')
+ if db is not None:
+ db.close()
+ ps.tearDown()
+
+
+def setUp(test, name) :
""" Sets up a test and registers some commonly used adapters. """
- placelesssetup.setUp()
+ setUpModule(test, name)
setUpTraversal()
classImplements(File, IAttributeAnnotatable)
@@ -87,13 +115,24 @@
ztapi.provideAdapter(None, IObjectCopier, ObjectCopier)
ztapi.provideAdapter(IWriteContainer, INameChooser, NameChooser)
-
-def tearDown(test) :
- placelesssetup.tearDown()
+def setUpReadMe(test) :
+ setUp(test, "versioning.README")
+def teatDownReadMe(test) :
+ tearDown(test, "versioning.README")
+
+def setUpMotivation(test) :
+ setUp(test, "versioning.MOTIVATION")
+
+def tearDownMotivation(test) :
+ tearDown(test, "versioning.MOTIVATION")
+
+
def instanceProvides(obj, interface) :
""" Adds an interface to the directly provided ones of obj. """
+
+
ifaces = zope.interface.directlyProvidedBy(obj)
ifaces += interface
zope.interface.directlyProvides(obj, *ifaces)
@@ -111,7 +150,7 @@
connection = db.open()
return connection.root()
-def buildRepository(factory=zope.app.versioncontrol.repository.Repository, interaction=True):
+def buildRepository(factory=zope.app.versioncontrol.repository.Repository, interaction=False):
"""Setup a zope.app.versioncontrol repository
Placing an object under version control requires an instance of an
@@ -121,7 +160,7 @@
instance is responsible for providing version control operations;
an instance should never be asked to perform operations directly.
"""
-
+ import zope
repository = factory()
assert zope.interface.verify.verifyObject(
interfaces.IVersionControl,
@@ -156,8 +195,8 @@
def test_suite():
return unittest.TestSuite((
doctest.DocTestSuite(),
- #doctest.DocFileSuite("../README.txt", setUp=setUp, tearDown=tearDown),
- doctest.DocFileSuite("../MOTIVATION.txt", setUp=setUp, tearDown=tearDown),
+ doctest.DocFileSuite("../README.txt", setUp=setUpReadMe, tearDown=tearDownReadMe),
+ doctest.DocFileSuite("../MOTIVATION.txt", setUp=setUpMotivation, tearDown=tearDownMotivation),
))
if __name__=='__main__':
unittest.main(defaultTest='test_suite')
More information about the Zope-CVS
mailing list