[Checkins] SVN: zope.copypastemove/trunk/ Merge lp:~justizin/zope.copypastemove/lp_98385, with tweaks:
Tres Seaver
tseaver at palladion.com
Wed May 19 22:25:23 EDT 2010
Log message for revision 112555:
Merge lp:~justizin/zope.copypastemove/lp_98385, with tweaks:
- Honor the name given by the 'IObjectMover' in
'OrderedContainerItemRenamer.renameItem'. Thanks to Marius Gedminas
for the patch, and to Justin Ryan for the test.
Fixes https://bugs.launchpad.net/zope.copypastemove/+bug/98385.
- Avoid adding a dependency on 'zope.app.container' by using the equivalent
'zope.container' classes.
- Normalize return value from 'OrderedContainerItemRenamer.renameItem' to
match the base class.
- Improve wording, ReST rendering in changelog.
Changed:
U zope.copypastemove/trunk/CHANGES.txt
U zope.copypastemove/trunk/setup.py
U zope.copypastemove/trunk/src/zope/copypastemove/__init__.py
U zope.copypastemove/trunk/src/zope/copypastemove/tests/test_rename.py
-=-
Modified: zope.copypastemove/trunk/CHANGES.txt
===================================================================
--- zope.copypastemove/trunk/CHANGES.txt 2010-05-19 18:14:30 UTC (rev 112554)
+++ zope.copypastemove/trunk/CHANGES.txt 2010-05-20 02:25:22 UTC (rev 112555)
@@ -5,48 +5,53 @@
3.6.1 (unreleased)
------------------
-- additional check for name and container if the namechooser computes a
- name which is the same as the current name. This fixes
- https://bugs.launchpad.net/zope.copypastemove/+bug/123532
+- Honor the name given by the ``IObjectMover`` in
+ ``OrderedContainerItemRenamer.renameItem``. Thanks to Marius Gedminas
+ for the patch, and to Justin Ryan for the test.
+ Fixes https://bugs.launchpad.net/zope.copypastemove/+bug/98385.
-- Removed use of 'zope.testing.doctestunit' in favor of stdlib's 'doctest.
+- Add a check for name and container if the namechooser computes a
+ name which is the same as the current name.
+ Fixes https://bugs.launchpad.net/zope.copypastemove/+bug/123532
-- Moved zope.copypastemove related tests from zope.container here.
+- Remove use of ``zope.testing.doctestunit`` in favor of stdlib's ``doctest``.
+- Moved ``zope.copypastemove``-related tests from ``zope.container`` here.
+
3.6.0 (2009-12-16)
------------------
-- Use zope.principalannotation in favor of its app variant.
+- Favor ``zope.principalannotation`` over its ``zope.app`` variant.
-- Avoid zope.app.component and testing dependencies.
+- Avoid ``zope.app.component`` and testing dependencies.
3.5.2 (2009-08-15)
------------------
-- Fix documentation for the IObjectCopier.copyTo method.
+- Fix documentation for the ``IObjectCopier.copyTo`` method.
-- Added missing dependency on zope.app.component.
+- Add a missing dependency on ``zope.app.component``.
3.5.1 (2009-02-09)
------------------
-- Use the new zope.copy package for ObjectCopier to provide pluggable
- copying mechanism that is not dependent on zope.location hardly.
+- Use the new ``zope.copy`` package for ObjectCopier to provide pluggable
+ copying mechanism that is not dependent on ``zope.location`` hardly.
-- Move the ItemNotFoundError exception to the interfaces module as
- it's part of public API. Old import still works as we actually
+- Move the ``ItemNotFoundError`` exception to the interfaces module as
+ it's part of public API. Old import still works as we actually
use it where it was previously defined, however, the new import
place is preferred.
3.5.0 (2009-01-31)
------------------
-- Use zope.container instead of zope.app.container.
+- Use ``zope.container`` instead of ``zope.app.container``.
3.4.1 (2009-01-26)
------------------
-- Moved the test dependencies to a `test` extra requirement.
+- Move the test dependencies to a ``test`` extra requirement.
3.4.0 (2007-09-28)
------------------
@@ -57,4 +62,4 @@
--------------------
- Initial release as a separate project, corresponds to
- zope.copypastemove from Zope 3.4.0a1
+ ``zope.copypastemove`` from Zope 3.4.0a1
Modified: zope.copypastemove/trunk/src/zope/copypastemove/__init__.py
===================================================================
--- zope.copypastemove/trunk/src/zope/copypastemove/__init__.py 2010-05-19 18:14:30 UTC (rev 112554)
+++ zope.copypastemove/trunk/src/zope/copypastemove/__init__.py 2010-05-20 02:25:22 UTC (rev 112555)
@@ -445,6 +445,7 @@
to 'bar':
>>> renamer.renameItem('foo', 'bar')
+ u'bar'
>>> container['foo'] is foo
Traceback (most recent call last):
KeyError: 'foo'
@@ -473,6 +474,9 @@
self.container = container
def renameItem(self, oldName, newName):
+ return self._renameItem(oldName, newName)
+
+ def _renameItem(self, oldName, newName):
object = self.container.get(oldName)
if object is None:
raise ItemNotFoundError(self.container, oldName)
@@ -481,7 +485,7 @@
if newName in self.container:
raise DuplicationError("%s is already in use" % newName)
- mover.moveTo(self.container, newName)
+ return mover.moveTo(self.container, newName)
class OrderedContainerItemRenamer(ContainerItemRenamer):
@@ -514,18 +518,21 @@
When we rename one of the items:
>>> renamer.renameItem('1', 'I')
+ u'I'
the order is preserved:
>>> container.items()
- [('I', 'Item 1'), ('2', 'Item 2'), ('3', 'Item 3')]
+ [(u'I', 'Item 1'), ('2', 'Item 2'), ('3', 'Item 3')]
Renaming the other two items also preserves the origina order:
>>> renamer.renameItem('2', 'II')
+ u'II'
>>> renamer.renameItem('3', 'III')
+ u'III'
>>> container.items()
- [('I', 'Item 1'), ('II', 'Item 2'), ('III', 'Item 3')]
+ [(u'I', 'Item 1'), (u'II', 'Item 2'), (u'III', 'Item 3')]
As with the standard renamer, trying to rename a non-existent item raises
an error:
@@ -548,9 +555,10 @@
def renameItem(self, oldName, newName):
order = list(self.container.keys())
- super(OrderedContainerItemRenamer, self).renameItem(oldName, newName)
+ newName = self._renameItem(oldName, newName)
order[order.index(oldName)] = newName
self.container.updateOrder(order)
+ return newName
class PrincipalClipboard(object):
Modified: zope.copypastemove/trunk/src/zope/copypastemove/tests/test_rename.py
===================================================================
--- zope.copypastemove/trunk/src/zope/copypastemove/tests/test_rename.py 2010-05-19 18:14:30 UTC (rev 112554)
+++ zope.copypastemove/trunk/src/zope/copypastemove/tests/test_rename.py 2010-05-20 02:25:22 UTC (rev 112555)
@@ -57,11 +57,71 @@
eventtesting.setUp()
container_setup.setUp()
+
+def doctest_namechooser_rename_preserve_order():
+ """Test for OrderedContainerItemRenamer.renameItem
+
+ This is a regression test for
+ http://www.zope.org/Collectors/Zope3-dev/658
+
+ Also: https://bugs.launchpad.net/zope.copypastemove/+bug/98385
+
+ >>> from zope.component import adapts, provideAdapter
+ >>> from zope.copypastemove import ObjectMover
+ >>> provideAdapter(ObjectMover)
+
+ There's an ordered container
+
+ >>> from zope.container.ordered import OrderedContainer
+ >>> container = OrderedContainer()
+
+ >>> from zope.container.contained import Contained
+ >>> class Obj(Contained):
+ ... def __init__(self, title):
+ ... self.title = title
+ ... def __repr__(self):
+ ... return self.title
+ >>> container['foo'] = Obj('Foo')
+ >>> container['bar'] = Obj('Bar')
+ >>> container['baz'] = Obj('Baz')
+
+ with a custom name chooser
+
+ >>> from zope.interface import implements, Interface
+ >>> from zope.container.interfaces import INameChooser
+ >>> class IMyContainer(Interface): pass
+ >>> class MyNameChooser(object):
+ ... adapts(IMyContainer)
+ ... implements(INameChooser)
+ ... def __init__(self, container):
+ ... self.container = container
+ ... def chooseName(self, name, obj):
+ ... return name.encode('rot-13')
+ >>> provideAdapter(MyNameChooser)
+
+ >>> from zope.interface import alsoProvides
+ >>> alsoProvides(container, IMyContainer)
+
+ OrderedContainerItemRenamer renames and preserves the order of items
+
+ >>> from zope.copypastemove import OrderedContainerItemRenamer
+ >>> renamer = OrderedContainerItemRenamer(container)
+ >>> renamer.renameItem('bar', 'quux')
+ 'dhhk'
+
+ >>> list(container.keys())
+ ['foo', 'dhhk', 'baz']
+ >>> list(container.values())
+ [Foo, Bar, Baz]
+
+ """
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(RenamerTest),
DocTestSuite('zope.copypastemove',
setUp=setUp, tearDown=testing.tearDown),
+ DocTestSuite(setUp=setUp, tearDown=testing.tearDown),
))
if __name__=='__main__':
More information about the checkins
mailing list