Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-94808: Cover %p in PyUnicode_FromFormat #96677

Merged
merged 7 commits into from
Oct 7, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/test/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2807,6 +2807,18 @@ def check_format(expected, format, *args):
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_format1 = PyUnicode_FromFormat(b'%p', 'abc')
self.assertIsInstance(p_format1, str)
self.assertTrue(p_format1.startswith('0x'))

p_format2 = PyUnicode_FromFormat(b'repr=%p', '123456', b'xyz')
self.assertIsInstance(p_format2, str)
self.assertTrue(p_format2.startswith('repr=0x'))

# 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'
Expand Down