[Zodb-checkins] CVS: Zope3/src/ZODB/tests - testSerialize.py:1.1.2.2
Fred L. Drake, Jr.
fred at zope.com
Fri Jan 9 16:52:27 EST 2004
Update of /cvs-repository/Zope3/src/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv20149
Modified Files:
Tag: zope3-zodb3-devel-branch
testSerialize.py
Log Message:
- move class used in only one test into the test method
- add test for myhasattr()
=== Zope3/src/ZODB/tests/testSerialize.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/ZODB/tests/testSerialize.py:1.1.2.1 Fri Jan 9 16:25:42 2004
+++ Zope3/src/ZODB/tests/testSerialize.py Fri Jan 9 16:52:26 2004
@@ -32,18 +32,13 @@
def __init__(self, value):
self.value = value
-class TestObjectReader(serialize.BaseObjectReader):
- # A production object reader would optimize this, but we don't need to
- def _get_class(self, module, name):
- __import__(module)
- return getattr(sys.modules[module], name)
-
def make_pickle(ob):
sio = StringIO.StringIO()
p = cPickle.Pickler(sio, 1)
p.dump(ob)
return sio.getvalue()
+
class SerializerTestCase(unittest.TestCase):
# old format: (module, name), None
@@ -77,6 +72,14 @@
def test_getGhost(self):
# Use a TestObjectReader since we need _get_class() to be
# implemented; otherwise this is just a BaseObjectReader.
+
+ class TestObjectReader(serialize.BaseObjectReader):
+ # A production object reader would optimize this, but we
+ # don't need to in a test
+ def _get_class(self, module, name):
+ __import__(module)
+ return getattr(sys.modules[module], name)
+
r = TestObjectReader()
g = r.getGhost(self.old_style_with_newargs)
self.assert_(isinstance(g, ClassWithNewargs))
@@ -87,6 +90,31 @@
self.assert_(isinstance(g, ClassWithNewargs))
g = r.getGhost(self.new_style_without_newargs)
self.assert_(isinstance(g, ClassWithoutNewargs))
+
+ def test_myhasattr(self):
+
+ class OldStyle:
+ bar = "bar"
+ def __getattr__(self, name):
+ if name == "error":
+ raise ValueError("whee!")
+ else:
+ raise AttributeError, name
+
+ class NewStyle(object):
+ bar = "bar"
+ def _raise(self):
+ raise ValueError("whee!")
+ error = property(_raise)
+
+ self.assertRaises(ValueError,
+ serialize.myhasattr, OldStyle(), "error")
+ self.assertRaises(ValueError,
+ serialize.myhasattr, NewStyle(), "error")
+ self.assert_(serialize.myhasattr(OldStyle(), "bar"))
+ self.assert_(serialize.myhasattr(NewStyle(), "bar"))
+ self.assert_(not serialize.myhasattr(OldStyle(), "rat"))
+ self.assert_(not serialize.myhasattr(NewStyle(), "rat"))
def test_suite():
More information about the Zodb-checkins
mailing list