Merge lp:~justizin/zope.copypastemove/lp_98385 into lp:zope.copypastemove

Proposed by Tres Seaver
Status: Merged
Merge reported by: Tres Seaver
Merged at revision: not available
Proposed branch: lp:~justizin/zope.copypastemove/lp_98385
Merge into: lp:zope.copypastemove
Diff against target: 143 lines (+68/-4)
3 files modified
setup.py (+1/-0)
src/zope/copypastemove/__init__.py (+8/-4)
src/zope/copypastemove/tests/test_rename.py (+59/-0)
To merge this branch: bzr merge lp:~justizin/zope.copypastemove/lp_98385
Reviewer Review Type Date Requested Status
Tres Seaver Pending
Review via email: mp+25657@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Tres Seaver (tseaver) wrote :

I will merge with a couple of tweaks:

- We really prefer not to add any dependencies, even testing dependencies, on
  the 'zope.app' packages from outside that namespace. As it turns out, the
  'zope.container' package provides all these features anywa, which allows me
  to use the new test with a trivial tweak.

- The 'renameItem' methods should *all* return the newName: I'm updating the
  one for ordered containers to do so.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'setup.py'
--- setup.py 2010-05-05 16:58:38 +0000
+++ setup.py 2010-05-20 02:19:23 +0000
@@ -47,6 +47,7 @@
47 test=['zope.principalannotation',47 test=['zope.principalannotation',
48 'zope.testing',48 'zope.testing',
49 'zope.traversing',49 'zope.traversing',
50 'zope.app.container',
50 ]),51 ]),
51 install_requires=['setuptools',52 install_requires=['setuptools',
52 'zope.annotation',53 'zope.annotation',
5354
=== modified file 'src/zope/copypastemove/__init__.py'
--- src/zope/copypastemove/__init__.py 2010-05-19 10:48:49 +0000
+++ src/zope/copypastemove/__init__.py 2010-05-20 02:19:23 +0000
@@ -445,6 +445,7 @@
445 to 'bar':445 to 'bar':
446446
447 >>> renamer.renameItem('foo', 'bar')447 >>> renamer.renameItem('foo', 'bar')
448 u'bar'
448 >>> container['foo'] is foo449 >>> container['foo'] is foo
449 Traceback (most recent call last):450 Traceback (most recent call last):
450 KeyError: 'foo'451 KeyError: 'foo'
@@ -473,6 +474,9 @@
473 self.container = container474 self.container = container
474475
475 def renameItem(self, oldName, newName):476 def renameItem(self, oldName, newName):
477 return self._renameItem(oldName, newName)
478
479 def _renameItem(self, oldName, newName):
476 object = self.container.get(oldName)480 object = self.container.get(oldName)
477 if object is None:481 if object is None:
478 raise ItemNotFoundError(self.container, oldName)482 raise ItemNotFoundError(self.container, oldName)
@@ -481,7 +485,7 @@
481 if newName in self.container:485 if newName in self.container:
482 raise DuplicationError("%s is already in use" % newName)486 raise DuplicationError("%s is already in use" % newName)
483487
484 mover.moveTo(self.container, newName)488 return mover.moveTo(self.container, newName)
485489
486490
487class OrderedContainerItemRenamer(ContainerItemRenamer):491class OrderedContainerItemRenamer(ContainerItemRenamer):
@@ -518,14 +522,14 @@
518 the order is preserved:522 the order is preserved:
519523
520 >>> container.items()524 >>> container.items()
521 [('I', 'Item 1'), ('2', 'Item 2'), ('3', 'Item 3')]525 [(u'I', 'Item 1'), ('2', 'Item 2'), ('3', 'Item 3')]
522526
523 Renaming the other two items also preserves the origina order:527 Renaming the other two items also preserves the origina order:
524528
525 >>> renamer.renameItem('2', 'II')529 >>> renamer.renameItem('2', 'II')
526 >>> renamer.renameItem('3', 'III')530 >>> renamer.renameItem('3', 'III')
527 >>> container.items()531 >>> container.items()
528 [('I', 'Item 1'), ('II', 'Item 2'), ('III', 'Item 3')]532 [(u'I', 'Item 1'), (u'II', 'Item 2'), (u'III', 'Item 3')]
529533
530 As with the standard renamer, trying to rename a non-existent item raises534 As with the standard renamer, trying to rename a non-existent item raises
531 an error:535 an error:
@@ -548,7 +552,7 @@
548552
549 def renameItem(self, oldName, newName):553 def renameItem(self, oldName, newName):
550 order = list(self.container.keys())554 order = list(self.container.keys())
551 super(OrderedContainerItemRenamer, self).renameItem(oldName, newName)555 newName = self._renameItem(oldName, newName)
552 order[order.index(oldName)] = newName556 order[order.index(oldName)] = newName
553 self.container.updateOrder(order)557 self.container.updateOrder(order)
554558
555559
=== modified file 'src/zope/copypastemove/tests/test_rename.py'
--- src/zope/copypastemove/tests/test_rename.py 2010-05-19 10:48:49 +0000
+++ src/zope/copypastemove/tests/test_rename.py 2010-05-20 02:19:23 +0000
@@ -57,11 +57,70 @@
57 eventtesting.setUp()57 eventtesting.setUp()
58 container_setup.setUp()58 container_setup.setUp()
5959
60
61def doctest_namechooser_rename_preserve_order():
62 """Test for OrderedContainerItemRenamer.renameItem
63
64 This is a regression test for
65 http://www.zope.org/Collectors/Zope3-dev/658
66
67 Also: https://bugs.launchpad.net/zope.copypastemove/+bug/98385
68
69 >>> from zope.component import adapts, provideAdapter
70 >>> from zope.copypastemove import ObjectMover
71 >>> provideAdapter(ObjectMover)
72
73 There's an ordered container
74
75 >>> from zope.app.container.ordered import OrderedContainer
76 >>> container = OrderedContainer()
77
78 >>> from zope.app.container.contained import Contained
79 >>> class Obj(Contained):
80 ... def __init__(self, title):
81 ... self.title = title
82 ... def __repr__(self):
83 ... return self.title
84 >>> container['foo'] = Obj('Foo')
85 >>> container['bar'] = Obj('Bar')
86 >>> container['baz'] = Obj('Baz')
87
88 with a custom name chooser
89
90 >>> from zope.interface import implements, Interface
91 >>> from zope.app.container.interfaces import INameChooser
92 >>> class IMyContainer(Interface): pass
93 >>> class MyNameChooser(object):
94 ... adapts(IMyContainer)
95 ... implements(INameChooser)
96 ... def __init__(self, container):
97 ... self.container = container
98 ... def chooseName(self, name, obj):
99 ... return name.encode('rot-13')
100 >>> provideAdapter(MyNameChooser)
101
102 >>> from zope.interface import alsoProvides
103 >>> alsoProvides(container, IMyContainer)
104
105 OrderedContainerItemRenamer renames and preserves the order of items
106
107 >>> from zope.copypastemove import OrderedContainerItemRenamer
108 >>> renamer = OrderedContainerItemRenamer(container)
109 >>> renamer.renameItem('bar', 'quux')
110
111 >>> list(container.keys())
112 ['foo', 'dhhk', 'baz']
113 >>> list(container.values())
114 [Foo, Bar, Baz]
115
116 """
117
60def test_suite():118def test_suite():
61 return unittest.TestSuite((119 return unittest.TestSuite((
62 unittest.makeSuite(RenamerTest),120 unittest.makeSuite(RenamerTest),
63 DocTestSuite('zope.copypastemove',121 DocTestSuite('zope.copypastemove',
64 setUp=setUp, tearDown=testing.tearDown),122 setUp=setUp, tearDown=testing.tearDown),
123 DocTestSuite(setUp=setUp, tearDown=testing.tearDown),
65 ))124 ))
66125
67if __name__=='__main__':126if __name__=='__main__':

Subscribers

People subscribed via source and target branches

to all changes: