summaryrefslogtreecommitdiff
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-10-14 15:28:59 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-10-14 15:28:59 +0200
commit83ff8a68324dfe54af8baf7e67f81b2db567ae7a (patch)
tree1d0dd1502de27bc16c5b2377a179c992b82811bd /Lib/test/test_bytes.py
parentf9c9a3fedfcf9da646cd0183b93bc00459cff164 (diff)
downloadcpython-git-83ff8a68324dfe54af8baf7e67f81b2db567ae7a.tar.gz
test_bytes: new try to fix test on '%p' formatter on Windows
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 0fe33b5cb3..87799dfd19 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -839,12 +839,22 @@ class BytesTest(BaseBytesTest, unittest.TestCase):
b'i=-123')
self.assertEqual(PyBytes_FromFormat(b'x=%x', c_int(0xabc)),
b'x=abc')
+
+ sizeof_ptr = ctypes.sizeof(c_char_p)
+
+ if os.name == 'nt':
+ # Windows (MSCRT)
+ ptr_format = '0x%0{}X'.format(2 * sizeof_ptr)
+ def ptr_formatter(ptr):
+ return (ptr_format % ptr)
+ else:
+ # UNIX (glibc)
+ def ptr_formatter(ptr):
+ return '%#x' % ptr
+
ptr = 0xabcdef
- expected = [b'ptr=%#x' % ptr]
- win_format = 'ptr=0x%0{}X'.format(2 * ctypes.sizeof(c_char_p))
- expected.append((win_format % ptr).encode('ascii'))
- self.assertIn(PyBytes_FromFormat(b'ptr=%p', c_char_p(ptr)),
- expected)
+ self.assertEqual(PyBytes_FromFormat(b'ptr=%p', c_char_p(ptr)),
+ ('ptr=' + ptr_formatter(ptr)).encode('ascii'))
self.assertEqual(PyBytes_FromFormat(b's=%s', c_char_p(b'cstr')),
b's=cstr')
@@ -859,7 +869,7 @@ class BytesTest(BaseBytesTest, unittest.TestCase):
(b'%zd', c_ssize_t, _testcapi.PY_SSIZE_T_MIN, str),
(b'%zd', c_ssize_t, _testcapi.PY_SSIZE_T_MAX, str),
(b'%zu', c_size_t, size_max, str),
- (b'%p', c_char_p, size_max, lambda value: '%#x' % value),
+ (b'%p', c_char_p, size_max, ptr_formatter),
):
self.assertEqual(PyBytes_FromFormat(formatstr, ctypes_type(value)),
py_formatter(value).encode('ascii')),