[Zope3-checkins] CVS: Zope3/src/ZODB/tests - testBroken.py:1.1
Jim Fulton
jim at zope.com
Wed Feb 25 07:31:42 EST 2004
Update of /cvs-repository/Zope3/src/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv4843/src/ZODB/tests
Added Files:
testBroken.py
Log Message:
Added broken-object support.
Broken objects are objects who's class has gone away, typically
because modules or classes have been removed or moved.
=== Added File Zope3/src/ZODB/tests/testBroken.py ===
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test broken-object suppport
$Id: testBroken.py,v 1.1 2004/02/25 12:31:41 jim Exp $
"""
import sys
import unittest
import persistent
from transaction import get_transaction
from doctest import DocTestSuite
from ZODB.tests.util import DB
def test_integration():
"""Test the integration of broken object support with the databse:
>>> db = DB()
We'll create a fake module with a class:
>>> class NotThere:
... Atall = type('Atall', (persistent.Persistent, ),
... {'__module__': 'ZODB.not.there'})
And stuff this into sys.modules to simulate a regular module:
>>> sys.modules['ZODB.not.there'] = NotThere
>>> sys.modules['ZODB.not'] = NotThere
Now, we'll create and save an instance, and make sure we can
load it in another connection:
>>> a = NotThere.Atall()
>>> a.x = 1
>>> conn1 = db.open()
>>> conn1.root()['a'] = a
>>> get_transaction().commit()
>>> conn2 = db.open()
>>> a2 = conn2.root()['a']
>>> a2.__class__ is a.__class__
True
>>> a2.x
1
Now, we'll uninstall the module, simulating having the module
go away:
>>> del sys.modules['ZODB.not.there']
and we'll try to load the object in another connection:
>>> conn3 = db.open()
>>> a3 = conn3.root()['a']
>>> a3
<persistent broken ZODB.not.there.Atall instance """ \
r"""'\x00\x00\x00\x00\x00\x00\x00\x01'>
>>> a3.__Broken_state__
{'x': 1}
>>> db.close()
"""
def test_suite():
return unittest.TestSuite((
DocTestSuite('ZODB.broken'),
DocTestSuite(),
))
if __name__ == '__main__': unittest.main()
More information about the Zope3-Checkins
mailing list