Commit 70551073 authored by Jim Fulton's avatar Jim Fulton

Added missing test cleanup code

parent 7f49a29f
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Broken object support """Broken object support
$Id: broken.py,v 1.2 2004/02/27 21:40:20 jeremy Exp $ $Id: broken.py,v 1.3 2004/03/04 22:41:52 jim Exp $
""" """
import sys import sys
...@@ -87,6 +87,9 @@ class Broken(object): ...@@ -87,6 +87,9 @@ class Broken(object):
>>> a2.__Broken_state__ >>> a2.__Broken_state__
{'x': 1} {'x': 1}
Cleanup::
>>> broken_cache.clear()
""" """
__Broken_state__ = __Broken_initargs__ = None __Broken_state__ = __Broken_initargs__ = None
...@@ -120,7 +123,10 @@ class Broken(object): ...@@ -120,7 +123,10 @@ class Broken(object):
def __setattr__(self, name, value): def __setattr__(self, name, value):
raise BrokenModified("Can't change broken objects") raise BrokenModified("Can't change broken objects")
def find_global(modulename, globalname, Broken=Broken): def find_global(modulename, globalname,
# These are *not* optimizations. Callers can override these.
Broken=Broken, type=type,
):
"""Find a global object, returning a broken class if it can't be found. """Find a global object, returning a broken class if it can't be found.
This function looks up global variable in modules:: This function looks up global variable in modules::
...@@ -167,6 +173,9 @@ def find_global(modulename, globalname, Broken=Broken): ...@@ -167,6 +173,9 @@ def find_global(modulename, globalname, Broken=Broken):
>>> find_global('ZODB.not.there', 'atall') is broken >>> find_global('ZODB.not.there', 'atall') is broken
True True
Cleanup::
>>> broken_cache.clear()
""" """
try: try:
__import__(modulename) __import__(modulename)
...@@ -217,6 +226,10 @@ def rebuild(modulename, globalname, *args): ...@@ -217,6 +226,10 @@ def rebuild(modulename, globalname, *args):
>>> del sys.modules['ZODB.notthere'] >>> del sys.modules['ZODB.notthere']
Cleanup::
>>> broken_cache.clear()
""" """
class_ = find_global(modulename, globalname) class_ = find_global(modulename, globalname)
return class_.__new__(class_, *args) return class_.__new__(class_, *args)
...@@ -280,6 +293,10 @@ class PersistentBroken(Broken, persistent.Persistent): ...@@ -280,6 +293,10 @@ class PersistentBroken(Broken, persistent.Persistent):
>>> a.__getstate__() >>> a.__getstate__()
{'y': 2} {'y': 2}
Cleanup::
>>> broken_cache.clear()
""" """
def __new__(class_, *args): def __new__(class_, *args):
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Test broken-object suppport """Test broken-object suppport
$Id: testBroken.py,v 1.2 2004/02/25 13:06:12 jim Exp $ $Id: testBroken.py,v 1.3 2004/03/04 22:41:53 jim Exp $
""" """
import sys import sys
...@@ -71,8 +71,15 @@ def test_integration(): ...@@ -71,8 +71,15 @@ def test_integration():
>>> a3.__Broken_state__ >>> a3.__Broken_state__
{'x': 1} {'x': 1}
Let's clean up:
>>> db.close() >>> db.close()
>>> del sys.modules['ZODB.not']
Cleanup:
>>> import ZODB.broken
>>> ZODB.broken.broken_cache.clear()
""" """
def test_suite(): def test_suite():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment