Skip to content

Commit

Permalink
Work around missing sys.getrefcount in PyPy.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Jan 20, 2017
1 parent de69eda commit 9ab3862
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/AccessControl/tests/testZopeGuards.py
Expand Up @@ -91,14 +91,22 @@ def tearDown(self):
def test_unauthorized(self):
from AccessControl import Unauthorized
from AccessControl.ZopeGuards import guarded_getattr

try:
# PyPy
from sys import getrefcount
except ImportError:
def getrefcount(obj):
return 1

obj, name = Method(), 'args'
value = getattr(obj, name)
rc = sys.getrefcount(value)
rc = getrefcount(value)
self.__sm.reject = True
self.assertRaises(Unauthorized, guarded_getattr, obj, name)
self.assert_(self.__sm.calls)
del self.__sm.calls[:]
self.assertEqual(rc, sys.getrefcount(value))
self.assertEqual(rc, getrefcount(value))

def test_calls_validate_for_unknown_type(self):
from AccessControl.ZopeGuards import guarded_getattr
Expand Down
13 changes: 10 additions & 3 deletions src/AccessControl/tests/testZopeSecurityPolicy.py
Expand Up @@ -233,15 +233,22 @@ def testProxyAccess(self):
self.assertPolicyAllows(item, 'dangerous_m')

def testIdentityProxy(self):
try:
# PyPy
from sys import getrefcount
except ImportError:
def getrefcount(obj):
return 1

eo = ImplictAcqObject()
eo.getOwner = lambda: None
self.context.stack.append(eo)
rc = sys.getrefcount(eo)
rc = getrefcount(eo)
self.testUserAccess()
self.assertEqual(rc, sys.getrefcount(eo))
self.assertEqual(rc, getrefcount(eo))
eo._proxy_roles = ()
self.testUserAccess()
self.assertEqual(rc, sys.getrefcount(eo))
self.assertEqual(rc, getrefcount(eo))

def testAccessToUnprotectedSubobjects(self):
item = self.item
Expand Down

0 comments on commit 9ab3862

Please sign in to comment.