diff options
Diffstat (limited to 'src/zope/security/tests/test_proxy.py')
-rw-r--r-- | src/zope/security/tests/test_proxy.py | 220 |
1 files changed, 144 insertions, 76 deletions
diff --git a/src/zope/security/tests/test_proxy.py b/src/zope/security/tests/test_proxy.py index cecac86..ef664ee 100644 --- a/src/zope/security/tests/test_proxy.py +++ b/src/zope/security/tests/test_proxy.py @@ -17,18 +17,21 @@ import unittest from zope.security._compat import PYTHON2, PURE_PYTHON + def _skip_if_not_Py2(testfunc): return unittest.skipUnless(PYTHON2, "Only on Py2")(testfunc) # pylint:disable=protected-access,eval-used,too-many-lines,too-many-public-methods -if not PYTHON2: # pragma: no cover (Python 3) + +if not PYTHON2: # pragma: PY3 def coerce(*args): raise NotImplementedError("Not on Python 3") cmp = coerce long = int unicode = str + class AbstractProxyTestBase(object): # pylint:disable=no-member,blacklisted-name @@ -67,6 +70,7 @@ class AbstractProxyTestBase(object): def test___getattr___w_checker_unauthorized(self): from zope.security.interfaces import Unauthorized + class Foo(object): bar = 'Bar' target = Foo() @@ -77,6 +81,7 @@ class AbstractProxyTestBase(object): def test___getattr___w_checker_forbidden_attribute(self): from zope.security.interfaces import ForbiddenAttribute + class Foo(object): bar = 'Bar' target = Foo() @@ -90,6 +95,7 @@ class AbstractProxyTestBase(object): def test__getattr__w_checker_ok_dynamic_attribute_called_once(self): class Dynamic(object): count = 0 + def __getattr__(self, name): self.count += 1 if self.count == 1: @@ -118,6 +124,7 @@ class AbstractProxyTestBase(object): def test___setattr___w_checker_unauthorized(self): from zope.security.interfaces import Unauthorized + class Foo(object): bar = 'Bar' target = Foo() @@ -128,6 +135,7 @@ class AbstractProxyTestBase(object): def test___setattr___w_checker_forbidden_attribute(self): from zope.security.interfaces import ForbiddenAttribute + class Foo(object): bar = 'Bar' target = Foo() @@ -150,6 +158,7 @@ class AbstractProxyTestBase(object): def test___delattr___w_checker_unauthorized(self): from zope.security.interfaces import Unauthorized + class Foo(object): def __init__(self): self.bar = 'Bar' @@ -162,6 +171,7 @@ class AbstractProxyTestBase(object): def test___delattr___w_checker_forbidden_attribute(self): from zope.security.interfaces import ForbiddenAttribute + class Foo(object): def __init__(self): self.bar = 'Bar' @@ -192,9 +202,10 @@ class AbstractProxyTestBase(object): def test___str___fails_return(self): from zope.security.interfaces import ForbiddenAttribute + class CustomStr(object): def __str__(self): - "<CustomStr>" # Docstring, not a return + "<CustomStr>" # Docstring, not a return target = CustomStr() checker = DummyChecker(ForbiddenAttribute, allowed=('__str__')) @@ -224,12 +235,14 @@ class AbstractProxyTestBase(object): def test___str___falls_through_to_repr_when_both_allowed(self): from zope.security.interfaces import ForbiddenAttribute + class CustomRepr(object): def __repr__(self): return "<CustomRepr>" target = CustomRepr() - checker = DummyChecker(ForbiddenAttribute, allowed=("__str__", '__repr__')) + checker = DummyChecker( + ForbiddenAttribute, allowed=("__str__", '__repr__')) proxy = self._makeOne(target, checker) self.assertEqual(repr(proxy), "<CustomRepr>") self.assertEqual(str(target), "<CustomRepr>") @@ -237,6 +250,7 @@ class AbstractProxyTestBase(object): def test___str___doesnot_fall_through_to_repr_when_str_not_allowed(self): from zope.security.interfaces import ForbiddenAttribute + class CustomRepr(object): def __repr__(self): return "<CustomRepr>" @@ -250,6 +264,7 @@ class AbstractProxyTestBase(object): def test___str___doesnot_fall_through_to_repr_when_repr_not_allowed(self): from zope.security.interfaces import ForbiddenAttribute + class CustomRepr(object): def __repr__(self): return "<CustomRepr>" @@ -263,9 +278,10 @@ class AbstractProxyTestBase(object): def test___str___falls_through_to_repr_but_repr_fails_return(self): from zope.security.interfaces import ForbiddenAttribute + class CustomRepr(object): def __repr__(self): - "<CustomRepr>" # Docstring, not a return + "<CustomRepr>" # Docstring, not a return target = CustomRepr() checker = DummyChecker(ForbiddenAttribute, allowed=('__repr__')) @@ -276,62 +292,62 @@ class AbstractProxyTestBase(object): repr(proxy) @_skip_if_not_Py2 - def test___cmp___w_self(self): + def test___cmp___w_self(self): # pragma: no cover target = object() - checker = object() # checker not consulted + checker = object() # checker not consulted proxy = self._makeOne(target, checker) self.assertEqual(cmp(proxy, proxy), 0) @_skip_if_not_Py2 - def test___cmp___w_target(self): + def test___cmp___w_target(self): # pragma: no cover target = object() - checker = object() # checker not consulted + checker = object() # checker not consulted proxy = self._makeOne(target, checker) self.assertEqual(cmp(proxy, target), 0) @_skip_if_not_Py2 - def test___cmp___w_other(self): + def test___cmp___w_other(self): # pragma: no cover target = object() other = object() - checker = object() # checker not consulted + checker = object() # checker not consulted proxy = self._makeOne(target, checker) self.assertNotEqual(cmp(proxy, other), 0) @_skip_if_not_Py2 - def test___cmp___w_other_proxy(self): + def test___cmp___w_other_proxy(self): # pragma: no cover target = object() - checker = object() # checker not consulted + checker = object() # checker not consulted proxy = self._makeOne(target, checker) o_proxy = self._makeOne(target, checker) self.assertEqual(cmp(proxy, o_proxy), 0) def test__le__(self): target = 1 - checker = object() # checker not consulted + checker = object() # checker not consulted proxy = self._makeOne(target, checker) self.assertTrue(proxy <= 1) def test__ne__(self): target = 1 - checker = object() # checker not consulted + checker = object() # checker not consulted proxy = self._makeOne(target, checker) self.assertFalse(proxy != 1) def test__ge__(self): target = 1 - checker = object() # checker not consulted + checker = object() # checker not consulted proxy = self._makeOne(target, checker) self.assertTrue(proxy >= 1) def test__gt__(self): target = 1 - checker = object() # checker not consulted + checker = object() # checker not consulted proxy = self._makeOne(target, checker) self.assertTrue(proxy > 0) def test___hash___w_self(self): target = object() - checker = object() # checker not consulted + checker = object() # checker not consulted proxy = self._makeOne(target, checker) self.assertEqual(hash(proxy), hash(target)) @@ -348,6 +364,7 @@ class AbstractProxyTestBase(object): def test___call___w_checker_unauthorized(self): from zope.security.interfaces import Unauthorized + class Foo(object): def __call__(self): raise AssertionError("Never called") @@ -359,6 +376,7 @@ class AbstractProxyTestBase(object): def test___call___w_checker_forbidden_attribute(self): from zope.security.interfaces import ForbiddenAttribute + class Foo(object): def __call__(self): raise AssertionError("Never called") @@ -399,7 +417,7 @@ class AbstractProxyTestBase(object): self.assertEqual(checker._checked, '__float__') @_skip_if_not_Py2 - def test___long___w_checker_allows(self): + def test___long___w_checker_allows(self): # pragma: no cover target = 3.0 checker = DummyChecker() proxy = self._makeOne(target, checker) @@ -407,7 +425,7 @@ class AbstractProxyTestBase(object): self.assertEqual(checker._checked, '__long__') @_skip_if_not_Py2 - def test___long___w_checker_forbids(self): + def test___long___w_checker_forbids(self): # pragma: no cover from zope.security.interfaces import ForbiddenAttribute target = 3 checker = DummyChecker(ForbiddenAttribute) @@ -416,7 +434,7 @@ class AbstractProxyTestBase(object): self.assertEqual(checker._checked, '__long__') @_skip_if_not_Py2 - def test___oct___w_checker_allows(self): + def test___oct___w_checker_allows(self): # pragma: no cover target = 3 checker = DummyChecker() proxy = self._makeOne(target, checker) @@ -424,7 +442,7 @@ class AbstractProxyTestBase(object): self.assertEqual(checker._checked, '__oct__') @_skip_if_not_Py2 - def test___oct___w_checker_forbids(self): + def test___oct___w_checker_forbids(self): # pragma: no cover from zope.security.interfaces import ForbiddenAttribute target = 3 checker = DummyChecker(ForbiddenAttribute) @@ -433,7 +451,7 @@ class AbstractProxyTestBase(object): self.assertEqual(checker._checked, '__oct__') @_skip_if_not_Py2 - def test___hex___w_checker_allows(self): + def test___hex___w_checker_allows(self): # pragma: no cover target = 3 checker = DummyChecker() proxy = self._makeOne(target, checker) @@ -441,7 +459,7 @@ class AbstractProxyTestBase(object): self.assertEqual(checker._checked, '__hex__') @_skip_if_not_Py2 - def test___hex___w_checker_forbids(self): + def test___hex___w_checker_forbids(self): # pragma: no cover from zope.security.interfaces import ForbiddenAttribute target = 3 checker = DummyChecker(ForbiddenAttribute) @@ -599,20 +617,24 @@ class AbstractProxyTestBase(object): self.assertRaises(ForbiddenAttribute, lambda: pow(x, proxy)) self.assertEqual(checker._checked, '__rpow__') - def test___pow___w_z_proxied_allowed(self): + @unittest.expectedFailure + def test___pow___w_z_proxied_allowed2(self): + # There is no method `__3pow__` - is this test obsolete? x, y, z = 3, 4, 7 checker = DummyChecker() proxy = self._makeOne(z, checker) self.assertEqual(pow(x, y, proxy), pow(x, y, z)) - self.assertEqual(checker._checked, '__3pow__') + self.assertEqual(checker._checked, '__3pow__') # pragma: no cover - def test___pow___w_z_proxied_forbidden(self): + @unittest.expectedFailure + def test___pow___w_z_proxied_forbidden2(self): + # There is no method `__3pow__` - is this test obsolete? from zope.security.interfaces import ForbiddenAttribute x, y, z = 3, 4, 7 checker = DummyChecker(ForbiddenAttribute) proxy = self._makeOne(z, checker) self.assertRaises(ForbiddenAttribute, lambda: pow(x, y, proxy)) - self.assertEqual(checker._checked, '__3pow__') + self.assertEqual(checker._checked, '__3pow__') # pragma: no cover def test___neg___w_checker_allows(self): target = 3 @@ -756,7 +778,7 @@ class AbstractProxyTestBase(object): self.assertEqual(checker._checked, '__or__') @_skip_if_not_Py2 - def test___coerce___w_checker_allows(self): + def test___coerce___w_checker_allows(self): # pragma: no cover target = 3 checker = DummyChecker() proxy = self._makeOne(target, checker) @@ -764,7 +786,7 @@ class AbstractProxyTestBase(object): self.assertEqual(checker._checked, '__coerce__') @_skip_if_not_Py2 - def test___coerce___w_checker_forbids(self): + def test___coerce___w_checker_forbids(self): # pragma: no cover from zope.security.interfaces import ForbiddenAttribute target = 3 checker = DummyChecker(ForbiddenAttribute) @@ -785,6 +807,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __iadd__(self, rhs): self.value += rhs return self @@ -818,6 +841,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __isub__(self, rhs): self.value -= rhs return self @@ -851,6 +875,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __imul__(self, rhs): self.value *= rhs return self @@ -884,6 +909,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __idiv__(self, rhs): self.value /= rhs return self @@ -918,6 +944,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __itruediv__(self, rhs): self.value /= rhs return self @@ -952,6 +979,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __ifloordiv__(self, rhs): self.value //= rhs return self @@ -985,6 +1013,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __imod__(self, rhs): self.value %= rhs return self @@ -1018,6 +1047,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __ipow__(self, rhs): self.value **= rhs return self @@ -1051,6 +1081,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __ilshift__(self, rhs): self.value <<= rhs return self @@ -1084,6 +1115,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __irshift__(self, rhs): self.value >>= rhs return self @@ -1117,6 +1149,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __iand__(self, rhs): self.value &= rhs return self @@ -1150,6 +1183,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __ixor__(self, rhs): self.value ^= rhs return self @@ -1185,6 +1219,7 @@ class AbstractProxyTestBase(object): class Foo(object): def __init__(self, value): self.value = value + def __ior__(self, rhs): self.value |= rhs return self @@ -1290,6 +1325,7 @@ class AbstractProxyTestBase(object): target = [0, 1, 2] checker = DummyChecker() proxy = self._makeOne(target, checker) + def _try(): proxy[4] = 7 self.assertRaises(IndexError, _try) @@ -1300,13 +1336,14 @@ class AbstractProxyTestBase(object): target = [0, 1, 2] checker = DummyChecker(ForbiddenAttribute) proxy = self._makeOne(target, checker) + def _try(): proxy[4] = 7 self.assertRaises(ForbiddenAttribute, _try) self.assertEqual(checker._checked, '__setitem__') @_skip_if_not_Py2 - def test___getslice___w_checker_allows(self): + def test___getslice___w_checker_allows(self): # pragma: no cover target = [0, 1, 2] checker = DummyChecker() proxy = self._makeOne(target, checker) @@ -1316,11 +1353,13 @@ class AbstractProxyTestBase(object): def test___getslice___error_propagates(self): class Missing(Exception): pass + class Get(object): def __getitem__(self, x): - raise Missing('__getitem__') # pragma: no cover (only py3) - def __getslice__(self, start, stop): - raise Missing("__getslice__") + raise Missing('__getitem__') + + def __getslice__(self, start, stop): # PY2 + raise Missing("__getslice__") # pragma: no cover target = Get() checker = DummyChecker() proxy = self._makeOne(target, checker) @@ -1333,6 +1372,7 @@ class AbstractProxyTestBase(object): def test___getslice___dne_uses_getitem(self): class Missing(Exception): pass + class Get(object): def __getitem__(self, x): raise Missing('__getitem__') @@ -1347,7 +1387,7 @@ class AbstractProxyTestBase(object): self.assertEqual(checker._checked, self.getslice) @_skip_if_not_Py2 - def test___getslice___w_checker_forbids(self): + def test___getslice___w_checker_forbids(self): # pragma: no cover from zope.security.interfaces import ForbiddenAttribute target = [0, 1, 2] checker = DummyChecker(ForbiddenAttribute) @@ -1356,7 +1396,7 @@ class AbstractProxyTestBase(object): self.assertEqual(checker._checked, '__getslice__') @_skip_if_not_Py2 - def test___setslice___w_checker_allows(self): + def test___setslice___w_checker_allows(self): # pragma: no cover target = [0, 1, 2] checker = DummyChecker() proxy = self._makeOne(target, checker) @@ -1365,11 +1405,12 @@ class AbstractProxyTestBase(object): self.assertEqual(checker._checked, '__setslice__') @_skip_if_not_Py2 - def test___setslice___w_checker_forbids(self): + def test___setslice___w_checker_forbids(self): # pragma: no cover from zope.security.interfaces import ForbiddenAttribute target = [0, 1, 2] checker = DummyChecker(ForbiddenAttribute) proxy = self._makeOne(target, checker) + def _try(): proxy[1:3] = [3, 4] self.assertRaises(ForbiddenAttribute, _try) @@ -1378,11 +1419,13 @@ class AbstractProxyTestBase(object): def test___setslice___error_propagates(self): class Missing(Exception): pass + class Set(object): def __setitem__(self, k, v): - raise Missing('__setitem__') # pragma: no cover (only py3) - def __setslice__(self, start, stop, value): - raise Missing("__setslice__") + raise Missing('__setitem__') + + def __setslice__(self, start, stop, value): # PY2 + raise Missing("__setslice__") # pragma: no cover target = Set() checker = DummyChecker() proxy = self._makeOne(target, checker) @@ -1395,6 +1438,7 @@ class AbstractProxyTestBase(object): def test___setslice___dne_uses_setitem(self): class Missing(Exception): pass + class Set(object): def __setitem__(self, k, v): raise Missing('__setitem__') @@ -1443,6 +1487,7 @@ class AbstractProxyTestBase(object): target = {'a': 0, 'b': 1, 'c': 2} checker = DummyChecker(ForbiddenAttribute) proxy = self._makeOne(target, checker) + def _try(): proxy['a'] = 7 self.assertRaises(ForbiddenAttribute, _try) @@ -1451,7 +1496,7 @@ class AbstractProxyTestBase(object): binops = [ "x+y", "x-y", "x*y", "x/y", "divmod(x, y)", "x**y", "x//y", "x<<y", "x>>y", "x&y", "x|y", "x^y", - ] + ] def test_binops(self): from zope.security.proxy import removeSecurityProxy @@ -1467,28 +1512,27 @@ class AbstractProxyTestBase(object): self.assertEqual(removeSecurityProxy(eval(expr)), z, "x=%r; y=%r; expr=%r" % (x, y, expr)) - @_skip_if_not_Py2 - def test___unicode___allowed_by_default(self): + def test___unicode___allowed_by_default(self): # pragma: no cover # https://github.com/zopefoundation/zope.security/issues/10 class Foo(object): def __unicode__(self): return u'I am unicode' - checker = object() # checker not consulted + checker = object() # checker not consulted target = Foo() proxy = self._makeOne(target, checker) self.assertEqual(unicode(target), u'I am unicode') self.assertEqual(unicode(target), unicode(proxy)) @_skip_if_not_Py2 - def test___unicode___falls_through_to_str_by_default(self): + def test___unicode___falls_through_to_str_by_default(self): # pragma: no cover # noqa: E501 line too long # https://github.com/zopefoundation/zope.security/issues/10 class Foo(object): def __str__(self): return 'I am str' - checker = object() # checker not consulted + checker = object() # checker not consulted target = Foo() proxy = self._makeOne(target, checker) self.assertEqual(unicode(target), u'I am str') @@ -1497,11 +1541,12 @@ class AbstractProxyTestBase(object): self.assertIsInstance(unicode(proxy), unicode) @_skip_if_not_Py2 - def test___unicode___falls_through_to_str_even_if_str_not_allowed(self): + def test___unicode___falls_through_to_str_even_if_str_not_allowed(self): # pragma: no cover # noqa: E501 line too long # https://github.com/zopefoundation/zope.security/issues/10 # Note that this is inconsistent with str() and probably not a good # idea overall, so this test is strictly a regression test. from zope.security.interfaces import ForbiddenAttribute + class Foo(object): def __str__(self): return 'I am str' @@ -1525,7 +1570,7 @@ class AbstractProxyTestBase(object): class ProxyCTests(AbstractProxyTestBase, unittest.TestCase): - def _getTargetClass(self): + def _getTargetClass(self): # pragma: no cover from zope.security.proxy import _Proxy return _Proxy @@ -1548,6 +1593,7 @@ class ProxyPyTests(AbstractProxyTestBase, def test_access_checker_from_subclass(self): target = object() checker = DummyChecker() + class Sub(self._getTargetClass()): def get_checker(self): return self._checker @@ -1568,6 +1614,7 @@ class ProxyPyTests(AbstractProxyTestBase, target = object() checker = object() proxy = self._makeOne(target, checker) + def test(): del proxy._wrapped self.assertRaises(AttributeError, test) @@ -1576,6 +1623,7 @@ class ProxyPyTests(AbstractProxyTestBase, target = object() checker = object() proxy = self._makeOne(target, checker) + def test(): del proxy._checker self.assertRaises(AttributeError, test) @@ -1616,7 +1664,8 @@ class ProxyPyTests(AbstractProxyTestBase, orig_builtin_isinstance = zope.security.proxy._builtin_isinstance zope.security.proxy._builtin_isinstance = None try: - self.assertRaises(TypeError, zope.security.proxy.getObjectPy, proxy) + self.assertRaises( + TypeError, zope.security.proxy.getObjectPy, proxy) finally: zope.security.proxy._builtin_isinstance = orig_builtin_isinstance @@ -1646,17 +1695,21 @@ class ProxyPyTests(AbstractProxyTestBase, proxy = self._makeOne(module, DummyChecker()) self.assertEqual(WithModule.__module__, proxy.__module__) + class DummyChecker(object): _proxied = _checked = None + def __init__(self, raising=None, allowed=()): self._raising = raising self._allowed = allowed + def check(self, target, name): self._checked = name if name not in self._allowed: if self._raising is not None: raise self._raising(name) check_getattr = check_setattr = check + def proxy(self, value): self._proxied = value return value @@ -1703,6 +1756,7 @@ class Test_isinstance(unittest.TestCase): def test_w_proxied_object(self): from zope.security.checker import Checker from zope.security.proxy import Proxy + class Foo(object): pass target = Foo() @@ -1717,7 +1771,7 @@ class Checker(object): ok = 1 - unproxied_types = {str,} + unproxied_types = {str, } def check_getattr(self, _object, name): if name not in ("foo", "next", "__class__", "__name__", "__module__"): @@ -1741,32 +1795,45 @@ class Checker(object): class Something: def __init__(self): self.foo = [1, 2, 3] + def __getitem__(self, key): return self.foo[key] + def __setitem__(self, key, value): self.foo[key] = value + def __delitem__(self, key): del self.foo[key] + def __call__(self, arg): return 42 + def __eq__(self, other): return self is other + def __hash__(self): return 42 + def __iter__(self): return self + def __next__(self): - return 42 # Infinite sequence + return 42 # Infinite sequence next = __next__ + def __len__(self): return 42 - def __nonzero__(self): - return 1 - def __getslice__(self, i, j): - return [42] - def __setslice__(self, i, j, value): - if value != [42]: + + def __nonzero__(self): # PY2 + return 1 # pragma: no cover + + def __getslice__(self, i, j): # PY2 + return [42] # pragma: no cover + + def __setslice__(self, i, j, value): # PY2 + if value != [42]: # pragma: no cover raise AssertionError("Value should be [42]") + def __contains__(self, x): return x == 42 @@ -1800,7 +1867,7 @@ class ProxyFactoryTests(unittest.TestCase): self.assertTrue(s.startswith( "<security proxied %s.%s instance at" % (x.__class__.__module__, x.__class__.__name__)), - s) + s) def testRepr(self): from zope.security.proxy import ProxyFactory @@ -1814,7 +1881,7 @@ class ProxyFactoryTests(unittest.TestCase): self.assertTrue(s.startswith( "<security proxied %s.%s instance at" % (x.__class__.__module__, x.__class__.__name__)), - s) + s) def testGetAttrOK(self): from zope.security.proxy import removeSecurityProxy @@ -1867,8 +1934,8 @@ class ProxyFactoryTests(unittest.TestCase): def testRichCompareOK(self): self.assertTrue(self.p == self.x) -## def testRichCompareFail(self): -## self.shouldFail(lambda: self.p == self.x) +# def testRichCompareFail(self): +# self.shouldFail(lambda: self.p == self.x) def testIterOK(self): from zope.security.proxy import removeSecurityProxy @@ -1884,23 +1951,23 @@ class ProxyFactoryTests(unittest.TestCase): self.shouldFail(self.p.next) @_skip_if_not_Py2 - def testCompareOK(self): + def testCompareOK(self): # pragma: no cover self.assertEqual(cmp(self.p, self.x), 0) -## def testCompareFail(self): -## self.shouldFail(cmp, self.p, self.x) +# def testCompareFail(self): +# self.shouldFail(cmp, self.p, self.x) def testHashOK(self): self.assertEqual(hash(self.p), hash(self.x)) -## def testHashFail(self): -## self.shouldFail(hash, self.p) +# def testHashFail(self): +# self.shouldFail(hash, self.p) def testNonzeroOK(self): self.assertEqual(not self.p, 0) -## def testNonzeroFail(self): -## self.shouldFail(lambda: not self.p) +# def testNonzeroFail(self): +# self.shouldFail(lambda: not self.p) def testLenOK(self): self.assertEqual(len(self.p), 42) @@ -1909,7 +1976,7 @@ class ProxyFactoryTests(unittest.TestCase): self.shouldFail(len, self.p) @_skip_if_not_Py2 - def testSliceOK(self): + def testSliceOK(self): # pragma: no cover from zope.security.proxy import removeSecurityProxy self.assertEqual(removeSecurityProxy(self.p[:]), [42]) @@ -1938,9 +2005,9 @@ class ProxyFactoryTests(unittest.TestCase): from zope.security.proxy import getChecker self.assertEqual(self.c, getChecker(self.p)) - def testProxiedClassicClassAsDictKey(self): from zope.security.proxy import ProxyFactory + class C(object): pass d = {C: C()} @@ -1949,6 +2016,7 @@ class ProxyFactoryTests(unittest.TestCase): def testProxiedNewClassAsDictKey(self): from zope.security.proxy import ProxyFactory + class C(object): pass d = {C: C()} @@ -1957,7 +2025,7 @@ class ProxyFactoryTests(unittest.TestCase): unops = ["-x", "+x", "abs(x)", "~x", "int(x)", "float(x)"] if PYTHON2: - unops.append("long(x)") + unops.append("long(x)") # pragma: no cover def _make_eval(self, expr, locs): def _eval(*args): @@ -1973,7 +2041,7 @@ class ProxyFactoryTests(unittest.TestCase): from zope.security.proxy import removeSecurityProxy self.c.unproxied_types = {str, int, float} if PYTHON2: - self.c.unproxied_types.add(long) + self.c.unproxied_types.add(long) # pragma: no cover for expr in self.unops: x = 1 @@ -1986,7 +2054,7 @@ class ProxyFactoryTests(unittest.TestCase): self.shouldFail(self._make_eval(expr, locals()), x) @_skip_if_not_Py2 - def test_odd_unops(self): + def test_odd_unops(self): # pragma: no cover # unops that don't return a proxy P = self.c.proxy for func in ( @@ -1999,7 +2067,7 @@ class ProxyFactoryTests(unittest.TestCase): binops = [ "x+y", "x-y", "x*y", "x/y", "divmod(x, y)", "x**y", "x//y", "x<<y", "x>>y", "x&y", "x|y", "x^y", - ] + ] def test_binops(self): from zope.security.proxy import removeSecurityProxy @@ -2046,7 +2114,7 @@ class ProxyFactoryTests(unittest.TestCase): self.shouldFail(doit2) @_skip_if_not_Py2 - def test_coerce(self): + def test_coerce(self): # pragma: no cover from zope.security.proxy import removeSecurityProxy P = self.c.proxy @@ -2203,8 +2271,8 @@ class LocationProxySecurityCheckerTests(unittest.TestCase): import zope.security try: from importlib import reload as _reload - except ImportError: - _reload = reload # Python 2 + except ImportError: # pragma: PY2 + _reload = reload # noqa: F821 undefined name 'reload' # This attribute is set when zope.security.decorator is imported, to # show that it will be set too, if zope.security.proxy is imported |