Skip to content

Commit dde15f5

Browse files
authored
pythongh-94808: Improve coverage of _PyBytes_FormatEx (pythonGH-95895)
There were two specific areas not covered: - %(name) syntax - %*s syntax Automerge-Triggered-By: GH:iritkatriel
1 parent 2fd7246 commit dde15f5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/test_bytes.py

+18
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,24 @@ def test_mod(self):
715715
self.assertEqual(b, b'hello,\x00world!')
716716
self.assertIs(type(b), self.type2test)
717717

718+
def check(fmt, vals, result):
719+
b = self.type2test(fmt)
720+
b = b % vals
721+
self.assertEqual(b, result)
722+
self.assertIs(type(b), self.type2test)
723+
724+
# A set of tests adapted from test_unicode:UnicodeTest.test_formatting
725+
check(b'...%(foo)b...', {b'foo':b"abc"}, b'...abc...')
726+
check(b'...%(f(o)o)b...', {b'f(o)o':b"abc", b'foo':b'bar'}, b'...abc...')
727+
check(b'...%(foo)b...', {b'foo':b"abc",b'def':123}, b'...abc...')
728+
check(b'%*b', (5, b'abc',), b' abc')
729+
check(b'%*b', (-5, b'abc',), b'abc ')
730+
check(b'%*.*b', (5, 2, b'abc',), b' ab')
731+
check(b'%*.*b', (5, 3, b'abc',), b' abc')
732+
check(b'%i %*.*b', (10, 5, 3, b'abc',), b'10 abc')
733+
check(b'%i%b %*.*b', (10, b'3', 5, 3, b'abc',), b'103 abc')
734+
check(b'%c', b'a', b'a')
735+
718736
def test_imod(self):
719737
b = self.type2test(b'hello, %b!')
720738
orig = b

0 commit comments

Comments
 (0)