[Python-checkins] cpython: test_bytes: new try to fix test on '%p' formatter on Windows
victor.stinner
python-checkins at python.org
Wed Oct 14 09:31:45 EDT 2015
https://hg.python.org/cpython/rev/8e97d54e6d7d
changeset: 98754:8e97d54e6d7d
user: Victor Stinner <victor.stinner at gmail.com>
date: Wed Oct 14 15:28:59 2015 +0200
summary:
test_bytes: new try to fix test on '%p' formatter on Windows
files:
Lib/test/test_bytes.py | 22 ++++++++++++++++------
1 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -839,12 +839,22 @@
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 @@
(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')),
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list