[Checkins] SVN: zope.copypastemove/trunk/ LP #123532

Ilshad Khabibullin astoon.net at gmail.com
Wed May 19 07:48:49 EDT 2010


Log message for revision 112521:
  LP #123532

Changed:
  U   zope.copypastemove/trunk/CHANGES.txt
  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 11:48:10 UTC (rev 112520)
+++ zope.copypastemove/trunk/CHANGES.txt	2010-05-19 11:48:49 UTC (rev 112521)
@@ -5,6 +5,10 @@
 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
+
 - Removed use of 'zope.testing.doctestunit' in favor of stdlib's 'doctest.
 
 - Moved zope.copypastemove related tests from zope.container here.

Modified: zope.copypastemove/trunk/src/zope/copypastemove/__init__.py
===================================================================
--- zope.copypastemove/trunk/src/zope/copypastemove/__init__.py	2010-05-19 11:48:10 UTC (rev 112520)
+++ zope.copypastemove/trunk/src/zope/copypastemove/__init__.py	2010-05-19 11:48:49 UTC (rev 112521)
@@ -200,6 +200,10 @@
         chooser = INameChooser(target)
         new_name = chooser.chooseName(new_name, obj)
 
+        if target is container and new_name == orig_name:
+            # obstinate namechooser
+            return
+
         target[new_name] = obj
         del container[orig_name]
         return new_name

Modified: zope.copypastemove/trunk/src/zope/copypastemove/tests/test_rename.py
===================================================================
--- zope.copypastemove/trunk/src/zope/copypastemove/tests/test_rename.py	2010-05-19 11:48:10 UTC (rev 112520)
+++ zope.copypastemove/trunk/src/zope/copypastemove/tests/test_rename.py	2010-05-19 11:48:49 UTC (rev 112521)
@@ -18,9 +18,38 @@
 import unittest
 
 from doctest import DocTestSuite
-from zope.component import testing, eventtesting
-from zope.container.testing import PlacelessSetup
+from zope.component import testing, eventtesting, provideAdapter, adapts
+from zope.container.testing import PlacelessSetup, ContainerPlacefulSetup
+from zope.copypastemove import ContainerItemRenamer, ObjectMover
+from zope.copypastemove.interfaces import IContainerItemRenamer
+from zope.container.contained import Contained, NameChooser
+from zope.container.sample import SampleContainer
 
+class TestContainer(SampleContainer):
+    pass
+
+class ObstinateNameChooser(NameChooser):
+    adapts(TestContainer)
+
+    def chooseName(self, name, ob):
+        return u'foobar'
+
+class RenamerTest(ContainerPlacefulSetup, unittest.TestCase):
+
+    def setUp(self):
+        ContainerPlacefulSetup.setUp(self)
+        provideAdapter(ObjectMover)
+        provideAdapter(ContainerItemRenamer)
+        provideAdapter(ObstinateNameChooser)
+
+    def test_obstinatenamechooser(self):
+        container = TestContainer()
+        container[u'foobar'] = Contained()
+        renamer = IContainerItemRenamer(container)
+
+        renamer.renameItem(u'foobar', u'newname')
+        self.assertEqual(list(container), [u'foobar'])
+
 container_setup = PlacelessSetup()
 
 def setUp(test):
@@ -30,9 +59,10 @@
 
 def test_suite():
     return unittest.TestSuite((
-        DocTestSuite('zope.copypastemove',
-                     setUp=setUp, tearDown=testing.tearDown),
-        ))
+            unittest.makeSuite(RenamerTest),
+            DocTestSuite('zope.copypastemove',
+                         setUp=setUp, tearDown=testing.tearDown),
+            ))
 
 if __name__=='__main__':
     unittest.main(defaultTest='test_suite')



More information about the checkins mailing list