[Checkins] SVN: Sandbox/ctheune/zodbupgrade/src/zodbupgrade/ Provide tests for the case where __name__ is missing due to a factory being
Christian Theune
ct at gocept.com
Tue Jun 2 02:56:23 EDT 2009
Log message for revision 100578:
Provide tests for the case where __name__ is missing due to a factory being
registered with copy_reg.
Provide special case where __module__ is missing (seems to be the case for
Zope 2's Missing.Value object). Still looking for a simple test case, though.
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-06-01 18:21:44 UTC (rev 100577)
+++ Sandbox/ctheune/zodbupgrade/src/zodbupgrade/analyze.py 2009-06-02 06:56:22 UTC (rev 100578)
@@ -53,11 +53,14 @@
except (ImportError, AttributeError):
missing_factories.add('%s.%s' % (module_name, symbol))
else:
- # XXX Special case broken objects. They don't have __module__
if not hasattr(factory, '__name__'):
logging.warn(
"factory %r does not have __name__, can't check canonical location" % factory)
continue
+ if not hasattr(factory, '__module__'):
+ logging.warn(
+ "factory %r does not have __module__, can't check canonical location" % factory)
+ continue
if ((factory.__module__, factory.__name__) !=
(module_name, symbol)):
# The factory is reachable but it's not the
Modified: Sandbox/ctheune/zodbupgrade/src/zodbupgrade/tests.py
===================================================================
--- Sandbox/ctheune/zodbupgrade/src/zodbupgrade/tests.py 2009-06-01 18:21:44 UTC (rev 100577)
+++ Sandbox/ctheune/zodbupgrade/src/zodbupgrade/tests.py 2009-06-02 06:56:22 UTC (rev 100578)
@@ -92,6 +92,33 @@
self.assertEquals('module1', self.root['test'].__class__.__module__)
self.assertEquals('NewFactory', self.root['test'].__class__.__name__)
+ def test_factory_registered_with_copy_reg(self):
+ # Factories registered with copy_reg.pickle loose their __name__.
+ # We simply ignore those.
+ class AnonymousFactory(object):
+ def __new__(cls, name):
+ return object.__new__(cls)
+ def __init__(self, name):
+ self._name = name
+ def getName(self):
+ return self._name
+ sys.modules['module1'].AnonymousFactory = AnonymousFactory
+ sys.modules['module1'].AnonymousFactory.__module__ = 'module1'
+ sys.modules['module1'].Anonymous = AnonymousFactory('Anonymous')
+ import copy_reg
+ copy_reg.pickle(AnonymousFactory,
+ AnonymousFactory.getName,
+ AnonymousFactory)
+ self.root['test'] = sys.modules['module1'].Anonymous
+ transaction.commit()
+ self.db.close()
+ self.reopen_storage()
+ zodbupgrade.analyze.update_storage(self.storage)
+
+ self.assertEquals('module1', self.root['test'].__class__.__module__)
+ self.assertEquals('AnonymousFactory', self.root['test'].__class__.__name__)
+
+
def test_suite():
return unittest.makeSuite(ZODBUpgradeTests)
More information about the Checkins
mailing list