@@ -715,6 +715,24 @@ def test_mod(self):
715
715
self .assertEqual (b , b'hello,\x00 world!' )
716
716
self .assertIs (type (b ), self .type2test )
717
717
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
+
718
736
def test_imod (self ):
719
737
b = self .type2test (b'hello, %b!' )
720
738
orig = b
0 commit comments