Skip to content
Merged
Changes from 3 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
13 changes: 13 additions & 0 deletions Lib/test/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2807,6 +2807,19 @@ 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_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'repr=%p', '123456', None, b'xyz')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this case test? I don't see what it adds over the previous case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has:

  • Multiple arguments (while p_format1 only has one arg)
  • All arguments have different types
  • New types are tested: bytes and None

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't the additional arguments ignored though, because there is only one %p in the format string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, tests can be better :)
Can you please take a look at the updated version?

It now has both:

  • Extra types
  • Ignored arguments

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

self.assertIsInstance(p_format2, str)
self.assertRegex(p_format2, 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'
Expand Down