[Zope3-checkins] CVS: Zope3/lib/python/Zope/ContextWrapper/tests - testSimpleMethodWrapper.py:1.8.4.1
Jim Fulton
jim@zope.com
Thu, 5 Dec 2002 11:20:30 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ContextWrapper/tests
In directory cvs.zope.org:/tmp/cvs-serv15574/lib/python/Zope/ContextWrapper/tests
Modified Files:
Tag: ComponentConfiguration-branch
testSimpleMethodWrapper.py
Log Message:
Commiting code on branch so I can work on a different ws
=== Zope3/lib/python/Zope/ContextWrapper/tests/testSimpleMethodWrapper.py 1.8 => 1.8.4.1 ===
--- Zope3/lib/python/Zope/ContextWrapper/tests/testSimpleMethodWrapper.py:1.8 Tue Dec 3 16:54:09 2002
+++ Zope3/lib/python/Zope/ContextWrapper/tests/testSimpleMethodWrapper.py Thu Dec 5 11:20:29 2002
@@ -23,7 +23,8 @@
#
from Zope.ContextWrapper import \
Wrapper, wrapperTypes, ContextMethod, \
- ContextProperty, ContextGetProperty, ContextSetProperty
+ ContextProperty, ContextGetProperty, ContextSetProperty, \
+ ContextSuper
class NewStyleClass(object):
@@ -58,6 +59,9 @@
thisIsAContextGetProperty = ContextGetProperty(_getter, _setter)
thisIsAContextSetProperty = ContextSetProperty(_getter, _setter)
+ def this_is_any_old_method(self):
+ return 'base', self
+
class NewStyleClassWithSlots(object):
__slots__ = ['result']
@@ -93,6 +97,9 @@
thisIsAContextProperty = ContextProperty(_getter, _setter)
thisIsAContextGetProperty = ContextGetProperty(_getter, _setter)
thisIsAContextSetProperty = ContextSetProperty(_getter, _setter)
+
+ def this_is_any_old_method(self):
+ return 'base', self
class ClassicClass:
@@ -131,9 +138,11 @@
class TestClassicClass(unittest.TestCase):
+ _class = ClassicClass
+
def createObject(self):
# to be overridden in tests that subclass this one
- return ClassicClass()
+ return self._class()
def setUp(self):
unittest.TestCase.setUp(self)
@@ -226,12 +235,11 @@
def testNotFound(self):
self.assertRaises(AttributeError,
getattr, self.wrapped, 'noSuchAttribute')
-
+
class TestNewStyleClassWithSlots(TestClassicClass):
- def createObject(self):
- return NewStyleClassWithSlots()
+ _class = NewStyleClassWithSlots
# Setting properties doesn't work with classic classes,
# so this class has extra tests for setting properties in
@@ -262,10 +270,29 @@
self.assert_(result_obj is self.wrapped)
self.assert_(result_value is value)
+
+ def testContextSuper(self):
+
+ def this_is_any_old_method(self):
+ return 'sub', self
+
+ Sub = type('sub', (self._class, ), {
+ 'this_is_any_old_method': this_is_any_old_method,
+ })
+
+ inst = Wrapper(Sub())
+ name, rinst = inst.this_is_any_old_method()
+ self.assertEqual(name, 'sub')
+ self.assert_(rinst is not inst)
+
+ name, rinst = ContextSuper(Sub, inst).this_is_any_old_method()
+ self.assertEqual(name, 'base')
+ self.assert_(rinst is inst)
+
+
class TestNewStyleClass(TestNewStyleClassWithSlots):
- def createObject(self):
- return NewStyleClass()
+ _class = NewStyleClass
def testGetContextProperty_w_name_in_dict(self):
self.obj.__dict__['thisIsAContextProperty'] = False
@@ -406,6 +433,7 @@
self.assert_(hasattr(wrapped, '__getitem__'))
self.assertEqual(wrapped[0], 23)
self.assertEqual(wrapped.__getitem__(0), 23)
+
def test_suite():
return unittest.TestSuite((