Commit 98c51eb5 authored by Tres Seaver's avatar Tres Seaver

Restore tests for lying about '__class__' in pure Python.

Now that we have the gnarly '__getattribute__', we *can* tell that lie.
parent 9a2d8ad8
...@@ -58,7 +58,7 @@ class PyProxyBase(object): ...@@ -58,7 +58,7 @@ class PyProxyBase(object):
def __unicode__(self): def __unicode__(self):
return unicode(self._wrapped) return unicode(self._wrapped)
def __reduce__(self): def __reduce__(self): #pragma NO COVER (__reduce_ex__ prevents normal)
raise pickle.PicklingError raise pickle.PicklingError
def __reduce_ex__(self, proto): def __reduce_ex__(self, proto):
...@@ -100,7 +100,7 @@ class PyProxyBase(object): ...@@ -100,7 +100,7 @@ class PyProxyBase(object):
except AttributeError: except AttributeError:
mine = _MARKER mine = _MARKER
else: else:
if isinstance(mine, PyNonOverridable): if isinstance(mine, PyNonOverridable): #pragma NO COVER PyPy
return mine.desc.__get__(self) return mine.desc.__get__(self)
try: try:
return getattr(wrapped, name) return getattr(wrapped, name)
...@@ -413,7 +413,7 @@ def py_removeAllProxies(obj): ...@@ -413,7 +413,7 @@ def py_removeAllProxies(obj):
return obj return obj
class PyNonOverridable(object): class PyNonOverridable(object):
def __init__(self, method_desc): def __init__(self, method_desc): #pragma NO COVER PyPy
self.desc = method_desc self.desc = method_desc
try: try:
......
...@@ -179,6 +179,15 @@ class PyProxyBaseTestCase(unittest.TestCase): ...@@ -179,6 +179,15 @@ class PyProxyBaseTestCase(unittest.TestCase):
w1 = self._makeOne(1) w1 = self._makeOne(1)
self.assertEqual(hash(w1), hash(1)) self.assertEqual(hash(w1), hash(1))
def test___getattr__miss_both(self):
class Foo(object):
pass
o = Foo()
w = self._makeOne(o)
def _try():
return w.nonesuch
self.assertRaises(AttributeError, _try)
def test___getattr__delegates_to_wrapped(self): def test___getattr__delegates_to_wrapped(self):
class Foo(object): class Foo(object):
pass pass
...@@ -534,6 +543,11 @@ class PyProxyBaseTestCase(unittest.TestCase): ...@@ -534,6 +543,11 @@ class PyProxyBaseTestCase(unittest.TestCase):
self.assertEqual(a, float(x)) self.assertEqual(a, float(x))
self.assertTrue(b is y) self.assertTrue(b is y)
def test___class__(self):
o = object()
w = self._makeOne(o)
self.assertTrue(w.__class__ is o.__class__)
class ProxyBaseTestCase(PyProxyBaseTestCase): class ProxyBaseTestCase(PyProxyBaseTestCase):
...@@ -541,17 +555,6 @@ class ProxyBaseTestCase(PyProxyBaseTestCase): ...@@ -541,17 +555,6 @@ class ProxyBaseTestCase(PyProxyBaseTestCase):
from zope.proxy import ProxyBase from zope.proxy import ProxyBase
return ProxyBase return ProxyBase
def test___class__(self):
try:
from zope.proxy import _CAPI
except ImportError:
# Pure Python proxies can't lie about their '__class__'
pass
else:
o = object()
w = self._makeOne(o)
self.assertTrue(w.__class__ is o.__class__)
class Test_py_getProxiedObject(unittest.TestCase): class Test_py_getProxiedObject(unittest.TestCase):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment