[Zope-Checkins] CVS: Zope3/lib/python/Zope/ContextWrapper/tests - testSimpleMethodWrapper.py:1.1.2.3
Steve Alexander
steve@cat-box.net
Tue, 28 May 2002 16:28:15 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/ContextWrapper/tests
In directory cvs.zope.org:/tmp/cvs-serv8407/lib/python/Zope/ContextWrapper/tests
Modified Files:
Tag: Zope-3x-branch
testSimpleMethodWrapper.py
Log Message:
Made ContextWrappers handle the __call__ slot for ContextMethods.
Removed comparisons of objects with Wrapper using isinstance, as this
will fail to work with Python 2.3, when isinstance will respect __class__.
Added wrapperTypes field to the Zope.ContextWrapper module. Now, the
factory for creating ContextWrappers and the types of context wrappers
you might find are handled by different members of Zope.ContextWrapper
module.
This is needed for comparing using type(ob) in wrapperTypes, rather than
isinstance.
=== Zope3/lib/python/Zope/ContextWrapper/tests/testSimpleMethodWrapper.py 1.1.2.2 => 1.1.2.3 ===
# implementation, when that lands.
#
-from Zope.ContextWrapper import Wrapper
-from Zope.ContextWrapper import ContextMethod
-
+from Zope.ContextWrapper import Wrapper, ContextMethod, wrapperTypes
class NewStyleClass(object):
def thisIsAContextMethod(wrapped_self):
- assert isinstance(wrapped_self, Wrapper)
-
+ assert type(wrapped_self) in wrapperTypes
thisIsAContextMethod = ContextMethod(thisIsAContextMethod)
-
+
+ def __call__(wrapped_self):
+ assert type(wrapped_self) in wrapperTypes
+ __call__ = ContextMethod(__call__)
+
def thisIsNotAContextMethod(self):
- assert not isinstance(self, Wrapper)
+ assert type(self) not in wrapperTypes
class ClassicClass:
def thisIsAContextMethod(wrapped_self):
- assert isinstance(wrapped_self, Wrapper)
-
+ assert type(wrapped_self) in wrapperTypes
thisIsAContextMethod = ContextMethod(thisIsAContextMethod)
+ def __call__(wrapped_self, a, b=None):
+ assert type(wrapped_self) in wrapperTypes
+ assert a==1
+ assert b==2
+
+ __call__ = ContextMethod(__call__)
+
+
def thisIsNotAContextMethod(self):
- assert not isinstance(self, Wrapper)
+ assert type(self) not in wrapperTypes
class SimpleMethodWrapperTestCase(unittest.TestCase):
@@ -53,6 +61,7 @@
wrapped.thisIsAContextMethod()
wrapped.thisIsNotAContextMethod()
self.assertRaises(AssertionError, newstyle.thisIsAContextMethod)
+ wrapped()
def testClassicClass(self):
classic = ClassicClass()
@@ -60,8 +69,10 @@
wrapped.thisIsAContextMethod()
wrapped.thisIsNotAContextMethod()
self.assertRaises(AssertionError, classic.thisIsAContextMethod)
-
-
+ wrapped(1,2)
+ wrapped(a=1, b=2)
+ wrapped(1, b=2)
+
def test_suite():
suite = unittest.TestSuite()