[Checkins] SVN: Sandbox/ctheune/zodbupgrade/src/zodbupgrade/ Add simple case of rewriting: rename a class within its module.

Christian Theune ct at gocept.com
Sat May 30 03:46:03 EDT 2009


Log message for revision 100550:
  Add simple case of rewriting: rename a class within its module.
  

Changed:
  U   Sandbox/ctheune/zodbupgrade/src/zodbupgrade/analyze.py
  U   Sandbox/ctheune/zodbupgrade/src/zodbupgrade/tests.py

-=-
Modified: Sandbox/ctheune/zodbupgrade/src/zodbupgrade/analyze.py
===================================================================
--- Sandbox/ctheune/zodbupgrade/src/zodbupgrade/analyze.py	2009-05-30 07:37:37 UTC (rev 100549)
+++ Sandbox/ctheune/zodbupgrade/src/zodbupgrade/analyze.py	2009-05-30 07:46:03 UTC (rev 100550)
@@ -77,7 +77,7 @@
 
     """
     missing_classes = set()
-    rewrites_found = set()
+    rewrites_found = dict()
     oids_rewrite = set()
 
     count = 0
@@ -112,12 +112,12 @@
         raise ValueError(missing_classes)
 
     print "Rewriting database with mapping:"
-    for (old_mod, old_name), (new_mod, new_name) in rewrites_found:
+    for (old_mod, old_name), (new_mod, new_name) in rewrites_found.items():
         print "%s.%s -> %s.%s" % (old_mod, old_name, new_mod, new_name)
 
     print "%i objects need rewriting" % len(oids)
 
-    db = ZODB.DB.DB(storage)
+    db = DB(storage)
     connection = db.open()
     for oid in oids:
         obj = connection.get(oid)
@@ -125,3 +125,4 @@
     t = transaction.get()
     t.note('Class references updated by `zodbupgrade`')
     transaction.commit()
+    db.close()

Modified: Sandbox/ctheune/zodbupgrade/src/zodbupgrade/tests.py
===================================================================
--- Sandbox/ctheune/zodbupgrade/src/zodbupgrade/tests.py	2009-05-30 07:37:37 UTC (rev 100549)
+++ Sandbox/ctheune/zodbupgrade/src/zodbupgrade/tests.py	2009-05-30 07:46:03 UTC (rev 100550)
@@ -69,6 +69,29 @@
         self.assertRaises(ValueError,
                           zodbupgrade.analyze.update_storage, self.storage)
 
+    def test_factory_renamed(self):
+        # Create a ZODB with an object referencing a factory, then 
+        # rename the the factory but keep a reference from the old name in
+        # place. Update the ZODB. Then remove the old reference. We should
+        # then still be able to access the object.
+        self.root['test'] = sys.modules['module1'].Factory()
+        transaction.commit()
+        self.db.close()
 
+        sys.modules['module1'].NewFactory = sys.modules['module1'].Factory
+        sys.modules['module1'].NewFactory.__name__ = 'NewFactory'
+
+        self.db.close()
+        self.reopen_storage()
+        zodbupgrade.analyze.update_storage(self.storage)
+
+        del sys.modules['module1'].Factory
+
+        self.reopen_db()
+
+        self.assertEquals('module1', self.root['test'].__class__.__module__)
+        self.assertEquals('NewFactory', self.root['test'].__class__.__name__)
+
+
 def test_suite():
     return unittest.makeSuite(ZODBUpgradeTests)



More information about the Checkins mailing list