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

[3.11] gh-94808: Improve coverage of _PyBytes_FormatEx (GH-95895) #96647

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Changes from all 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
18 changes: 18 additions & 0 deletions Lib/test/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,24 @@ def test_mod(self):
self.assertEqual(b, b'hello,\x00world!')
self.assertIs(type(b), self.type2test)

def check(fmt, vals, result):
b = self.type2test(fmt)
b = b % vals
self.assertEqual(b, result)
self.assertIs(type(b), self.type2test)

# A set of tests adapted from test_unicode:UnicodeTest.test_formatting
check(b'...%(foo)b...', {b'foo':b"abc"}, b'...abc...')
check(b'...%(f(o)o)b...', {b'f(o)o':b"abc", b'foo':b'bar'}, b'...abc...')
check(b'...%(foo)b...', {b'foo':b"abc",b'def':123}, b'...abc...')
check(b'%*b', (5, b'abc',), b' abc')
check(b'%*b', (-5, b'abc',), b'abc ')
check(b'%*.*b', (5, 2, b'abc',), b' ab')
check(b'%*.*b', (5, 3, b'abc',), b' abc')
check(b'%i %*.*b', (10, 5, 3, b'abc',), b'10 abc')
check(b'%i%b %*.*b', (10, b'3', 5, 3, b'abc',), b'103 abc')
check(b'%c', b'a', b'a')

def test_imod(self):
b = self.type2test(b'hello, %b!')
orig = b
Expand Down