[Zope3-checkins] CVS: Zope3/src/zope/proxy/tests - test_proxy.py:1.8.4.1

Grégoire Weber zope@i-con.ch
Sun, 22 Jun 2003 10:24:20 -0400


Update of /cvs-repository/Zope3/src/zope/proxy/tests
In directory cvs.zope.org:/tmp/cvs-serv24874/src/zope/proxy/tests

Modified Files:
      Tag: cw-mail-branch
	test_proxy.py 
Log Message:
Synced up with HEAD

=== Zope3/src/zope/proxy/tests/test_proxy.py 1.8 => 1.8.4.1 ===
--- Zope3/src/zope/proxy/tests/test_proxy.py:1.8	Sat May 10 05:24:28 2003
+++ Zope3/src/zope/proxy/tests/test_proxy.py	Sun Jun 22 10:23:49 2003
@@ -17,9 +17,8 @@
 """
 import pickle
 import unittest
-
-from zope.proxy import proxy
-
+from zope.testing.doctestunit import DocTestSuite
+from zope.proxy import ProxyBase
 
 class Thing:
     pass
@@ -58,7 +57,7 @@
 
 class ProxyTestCase(unittest.TestCase):
 
-    proxy_class = proxy.proxy
+    proxy_class = ProxyBase
 
     def setUp(self):
         self.x = Thing()
@@ -74,9 +73,6 @@
         self.assertRaises(TypeError, self.proxy_class, key='value')
 
     def test_subclass_constructor(self):
-        # NB This leaks due to a bug in Python 2.2.2.
-        #    The leak is fixed in the release22-maint branch in Python CVS
-        #    (and this in Python 2.2.3), and in Python 2.3.
         class MyProxy(self.proxy_class):
             def __new__(cls, *args, **kwds):
                 return super(MyProxy, cls).__new__(cls, *args, **kwds)
@@ -116,11 +112,6 @@
         w = self.new_proxy(o)
         self.assert_(w.foo == 1)
 
-    def test_getobject(self):
-        obj1 = object()
-        w = self.new_proxy(obj1)
-        self.assert_(proxy.getobject(w) is obj1)
-
     def test___class__(self):
         o = object()
         w = self.new_proxy(o)
@@ -347,9 +338,171 @@
         self.failUnless(b is y)
 
 
-def test_suite():
-    return unittest.makeSuite(ProxyTestCase)
+def test_isProxy():
+    """
+    >>> from zope.proxy import ProxyBase, isProxy
+    >>> class P1(ProxyBase):
+    ...     pass
+    >>> class P2(ProxyBase):
+    ...     pass
+    >>> class C:
+    ...     pass
+    >>> c = C()
+    >>> int(isProxy(c))
+    0
+    >>> p = P1(c)
+    >>> int(isProxy(p))
+    1
+    >>> int(isProxy(p, P1))
+    1
+    >>> int(isProxy(p, P2))
+    0
+    >>> p = P2(p)
+    >>> int(isProxy(p, P1))
+    1
+    >>> int(isProxy(p, P2))
+    1
+
+    """
+
+def test_getProxiedObject():
+    """
+    >>> from zope.proxy import ProxyBase, getProxiedObject
+    >>> class C:
+    ...     pass
+    >>> c = C()
+    >>> int(getProxiedObject(c) is c)
+    1
+    >>> p = ProxyBase(c)
+    >>> int(getProxiedObject(p) is c)
+    1
+    >>> p2 = ProxyBase(p)
+    >>> int(getProxiedObject(p2) is p)
+    1
+
+    """
+
+def test_removeAllProxies():
+    """
+    >>> from zope.proxy import ProxyBase, removeAllProxies
+    >>> class C:
+    ...     pass
+    >>> c = C()
+    >>> int(removeAllProxies(c) is c)
+    1
+    >>> p = ProxyBase(c)
+    >>> int(removeAllProxies(p) is c)
+    1
+    >>> p2 = ProxyBase(p)
+    >>> int(removeAllProxies(p2) is c)
+    1
+
+    """
+
+def test_queryProxy():
+    """
+    >>> from zope.proxy import ProxyBase, queryProxy
+    >>> class P1(ProxyBase):
+    ...    pass
+    >>> class P2(ProxyBase):
+    ...    pass
+    >>> class C:
+    ...     pass
+    >>> c = C()
+    >>> queryProxy(c, P1)
+    >>> queryProxy(c, P1, 42)
+    42
+    >>> p1 = P1(c)
+    >>> int(queryProxy(p1, P1) is p1)
+    1
+    >>> queryProxy(c, P2)
+    >>> queryProxy(c, P2, 42)
+    42
+    >>> p2 = P2(p1)
+    >>> int(queryProxy(p2, P1) is p1)
+    1
+    >>> int(queryProxy(p2, P2) is p2)
+    1
+    >>> int(queryProxy(p2, ProxyBase) is p2)
+    1
+    
+    """
+
+def test_queryInnerProxy():
+    """
+    >>> from zope.proxy import ProxyBase, queryProxy, queryInnerProxy
+    >>> class P1(ProxyBase):
+    ...    pass
+    >>> class P2(ProxyBase):
+    ...    pass
+    >>> class C:
+    ...     pass
+    >>> c = C()
+    >>> queryInnerProxy(c, P1)
+    >>> queryInnerProxy(c, P1, 42)
+    42
+    >>> p1 = P1(c)
+    >>> int(queryProxy(p1, P1) is p1)
+    1
+    >>> queryInnerProxy(c, P2)
+    >>> queryInnerProxy(c, P2, 42)
+    42
+    >>> p2 = P2(p1)
+    >>> int(queryInnerProxy(p2, P1) is p1)
+    1
+    >>> int(queryInnerProxy(p2, P2) is p2)
+    1
+    >>> int(queryInnerProxy(p2, ProxyBase) is p1)
+    1
+
+    >>> p3 = P1(p2)
+    >>> int(queryProxy(p3, P1) is p3)
+    1
+    >>> int(queryInnerProxy(p3, P1) is p1)
+    1
+    >>> int(queryInnerProxy(p3, P2) is p2)
+    1
+    
+    """
+
+def test_sameProxiedObjects():
+    """
+    >>> from zope.proxy import ProxyBase, sameProxiedObjects
+    >>> class C:
+    ...     pass
+    >>> c1 = C()
+    >>> c2 = C()
+    >>> int(sameProxiedObjects(c1, c1))
+    1
+    >>> int(sameProxiedObjects(ProxyBase(c1), c1))
+    1
+    >>> int(sameProxiedObjects(ProxyBase(c1), ProxyBase(c1)))
+    1
+    >>> int(sameProxiedObjects(ProxyBase(ProxyBase(c1)), c1))
+    1
+    >>> int(sameProxiedObjects(c1, ProxyBase(c1)))
+    1
+    >>> int(sameProxiedObjects(c1, ProxyBase(ProxyBase(c1))))
+    1
+    >>> int(sameProxiedObjects(c1, c2))
+    0
+    >>> int(sameProxiedObjects(ProxyBase(c1), c2))
+    0
+    >>> int(sameProxiedObjects(ProxyBase(c1), ProxyBase(c2)))
+    0
+    >>> int(sameProxiedObjects(ProxyBase(ProxyBase(c1)), c2))
+    0
+    >>> int(sameProxiedObjects(c1, ProxyBase(c2)))
+    0
+    >>> int(sameProxiedObjects(c1, ProxyBase(ProxyBase(c2))))
+    0
+    """
+
 
+def test_suite():
+    suite = unittest.makeSuite(ProxyTestCase)
+    suite.addTest(DocTestSuite())
+    return suite
 
 if __name__ == "__main__":
     import sys