[Zope3-checkins] CVS: Zope3/src/zope/context/tests - test_wrapper.py:1.22
Albertas Agejevas
alga@codeworks.lt
Thu, 17 Jul 2003 10:00:35 -0400
Update of /cvs-repository/Zope3/src/zope/context/tests
In directory cvs.zope.org:/tmp/cvs-serv27026/zope/context/tests
Modified Files:
test_wrapper.py
Log Message:
Added a function to get to the descriptors without resolving them.
=== Zope3/src/zope/context/tests/test_wrapper.py 1.21 => 1.22 ===
--- Zope3/src/zope/context/tests/test_wrapper.py:1.21 Sun Jul 13 09:45:26 2003
+++ Zope3/src/zope/context/tests/test_wrapper.py Thu Jul 17 10:00:00 2003
@@ -15,12 +15,15 @@
$Id$
"""
import unittest
+from types import MethodType, FunctionType
from zope.proxy import getProxiedObject
from zope.context import Wrapper, wrapper, ContextMethod, ContextProperty
from zope.proxy.tests.test_proxy import Thing, ProxyTestCase
_marker = object()
+__metaclass__ = type
+
class WrapperProperty(object):
def __init__(self, name, dictname, default=_marker):
self.name = name
@@ -598,7 +601,6 @@
def foo(): pass
ContextMethod(ContextMethod(foo)).__get__(1)
self.assertRaises(TypeError, abuse)
-
class WrapperSubclass(wrapper.Wrapper):
@@ -613,10 +615,37 @@
def new_proxy(self, o, c=None):
return self.proxy_class(o, c)
+
+class Foo:
+ __metaclass__ = type
+ def foo(self):
+ pass
+ s = staticmethod(foo)
+ c = classmethod(foo)
+
+class TestGetDescriptor(unittest.TestCase):
+
+ def test_getdescriptor(self):
+ from zope.context.wrapper import getdescriptor
+ f = Foo()
+
+ self.assertEquals(type(f.foo), MethodType)
+ self.assertEquals(type(f.c), MethodType)
+ self.assertEquals(type(f.s), FunctionType)
+
+ self.assertEquals(type(getdescriptor(f, 'c')), classmethod)
+ self.assertEquals(type(getdescriptor(f, 's')), staticmethod)
+ self.assertEquals(type(getdescriptor(f, 'foo')), FunctionType)
+
+ self.assertEquals(getdescriptor(f, 'foo').__get__(f, Foo), f.foo)
+ self.assertEquals(getdescriptor(f, 's').__get__(f, Foo), f.s)
+ self.assertEquals(getdescriptor(f, 'c').__get__(f, Foo), f.c)
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(WrapperTestCase),
unittest.makeSuite(WrapperSubclassTestCase),
+ unittest.makeSuite(TestGetDescriptor),
))