Skip to content

Commit

Permalink
Try to make the tests pass on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Feb 19, 2013
1 parent 18a6987 commit e1d5f7c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/zope/security/tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Security proxy tests
"""
import unittest
import sys

from zope.security._compat import PYTHON2

Expand All @@ -35,6 +36,15 @@ def dummy(self):
return dummy
return testfunc

def _fmt_address(obj):
# Try to replicate PyString_FromString("%p", obj), which actually uses
# the platform sprintf(buf, "%p", obj), which we cannot access from Python
# directly (and ctypes seems like overkill).
if sys.platform == 'win32':
return '0x%08x' % id(obj)
else:
return '0x%0x' % id(obj)


class ProxyCTests(unittest.TestCase):

Expand Down Expand Up @@ -157,9 +167,10 @@ def test___str___checker_forbids_str(self):
target = object()
checker = DummyChecker(ForbiddenAttribute)
proxy = self._makeOne(target, checker)
address = _fmt_address(target)
self.assertEqual(str(proxy),
'<security proxied %s.object '
'instance at 0x%0x>' % (_BUILTINS, id(target)))
'instance at %s>' % (_BUILTINS, address))

def test___repr___checker_allows_str(self):
target = object()
Expand All @@ -173,9 +184,10 @@ def test___repr___checker_forbids_str(self):
target = object()
checker = DummyChecker(ForbiddenAttribute)
proxy = self._makeOne(target, checker)
address = _fmt_address(target)
self.assertEqual(repr(proxy),
'<security proxied %s.object '
'instance at 0x%0x>' % (_BUILTINS, id(target)))
'instance at %s>' % (_BUILTINS, address))

@_skip_if_not_Py2
def test___cmp___w_self(self):
Expand Down

0 comments on commit e1d5f7c

Please sign in to comment.