Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use regex
  • Loading branch information
sobolevn committed Sep 8, 2022
commit ad127bd31cc5a566a3f1b1f0ea6c156630d81e43
7 changes: 4 additions & 3 deletions Lib/test/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2811,13 +2811,14 @@ def check_format(expected, format, *args):
# 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,}'
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated
p_format1 = PyUnicode_FromFormat(b'%p', 'abc')
self.assertIsInstance(p_format1, str)
self.assertTrue(p_format1.startswith('0x'))
self.assertRegex(p_format1, p_format_regex)

p_format2 = PyUnicode_FromFormat(b'repr=%p', '123456', b'xyz')
p_format2 = PyUnicode_FromFormat(b'repr=%p', '123456', None, b'xyz')
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.assertTrue(p_format2.startswith('repr=0x'))
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
Expand Down