diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2022-10-07 16:53:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-07 16:53:42 (GMT) |
commit | 72c166add89a0cd992d66f75ce94eee5eb675a99 (patch) | |
tree | 40ea28f65fcffad7dbad55f0dd7d5c6fcd61932b | |
parent | be4099e55d30a2991b46add59ee96c531904c144 (diff) | |
download | cpython-72c166add89a0cd992d66f75ce94eee5eb675a99.zip cpython-72c166add89a0cd992d66f75ce94eee5eb675a99.tar.gz cpython-72c166add89a0cd992d66f75ce94eee5eb675a99.tar.bz2 |
gh-94808: Cover `%p` in `PyUnicode_FromFormat` (#96677)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
-rw-r--r-- | Lib/test/test_unicode.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 30faaaf..b9ee9d3 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -2807,6 +2807,25 @@ class CAPITest(unittest.TestCase): check_format('repr=abc', b'repr=%V', 'abc', b'xyz') + # test %p + # We cannot test the exact result, + # because it returns a hex representation of a C pointer, + # which is going to be different each time. But, we can test the format. + p_format_regex = r'^0x[a-zA-Z0-9]{8,}$' + p_format1 = PyUnicode_FromFormat(b'%p', 'abc') + self.assertIsInstance(p_format1, str) + self.assertRegex(p_format1, p_format_regex) + + p_format2 = PyUnicode_FromFormat(b'%p %p', '123456', b'xyz') + self.assertIsInstance(p_format2, str) + self.assertRegex(p_format2, + r'0x[a-zA-Z0-9]{8,} 0x[a-zA-Z0-9]{8,}') + + # Extra args are ignored: + p_format3 = PyUnicode_FromFormat(b'%p', '123456', None, b'xyz') + self.assertIsInstance(p_format3, str) + self.assertRegex(p_format3, p_format_regex) + # Test string decode from parameter of %s using utf-8. # b'\xe4\xba\xba\xe6\xb0\x91' is utf-8 encoded byte sequence of # '\u4eba\u6c11' |