@@ -225,7 +225,7 @@ def test_extended_getslice(self):
225225 # Skip step 0 (invalid)
226226 for step in indices [1 :]:
227227 self .assertEqual (b [start :stop :step ], bytes (L [start :stop :step ]))
228-
228+
229229 def test_regexps (self ):
230230 def by (s ):
231231 return bytes (map (ord , s ))
@@ -298,7 +298,7 @@ def test_setslice(self):
298298
299299 b [3 :5 ] = [3 , 4 , 5 , 6 ]
300300 self .assertEqual (b , bytes (range (10 )))
301-
301+
302302 b [3 :0 ] = [42 , 42 , 42 ]
303303 self .assertEqual (b , bytes ([0 , 1 , 2 , 42 , 42 , 42 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]))
304304
@@ -317,7 +317,7 @@ def test_extended_set_del_slice(self):
317317 L [start :stop :step ] = data
318318 b [start :stop :step ] = data
319319 self .assertEquals (b , bytes (L ))
320-
320+
321321 del L [start :stop :step ]
322322 del b [start :stop :step ]
323323 self .assertEquals (b , bytes (L ))
@@ -371,8 +371,10 @@ def test_concat(self):
371371 b1 = bytes ("abc" )
372372 b2 = bytes ("def" )
373373 self .assertEqual (b1 + b2 , bytes ("abcdef" ))
374- self .assertRaises (TypeError , lambda : b1 + "def" )
375- self .assertRaises (TypeError , lambda : "abc" + b2 )
374+ self .assertEqual (b1 + "def" , bytes ("abcdef" ))
375+ self .assertEqual ("def" + b1 , bytes ("defabc" ))
376+ self .assertRaises (TypeError , lambda : b1 + u"def" )
377+ ##self.assertRaises(TypeError, lambda: u"abc" + b2) # XXX FIXME
376378
377379 def test_repeat (self ):
378380 b = bytes ("abc" )
@@ -393,6 +395,14 @@ def test_iconcat(self):
393395 self .assertEqual (b , bytes ("abcdef" ))
394396 self .assertEqual (b , b1 )
395397 self .failUnless (b is b1 )
398+ b += "xyz"
399+ self .assertEqual (b , b"abcdefxyz" )
400+ try :
401+ b += u""
402+ except TypeError :
403+ pass
404+ else :
405+ self .fail ("bytes += unicode didn't raise TypeError" )
396406
397407 def test_irepeat (self ):
398408 b = bytes ("abc" )
@@ -490,7 +500,7 @@ def test_extend(self):
490500 a .extend (a )
491501 self .assertEqual (a , orig + orig )
492502 self .assertEqual (a [5 :], orig )
493-
503+
494504 def test_remove (self ):
495505 b = b'hello'
496506 b .remove (ord ('l' ))
@@ -643,14 +653,36 @@ def test_pickling(self):
643653 q = pm .loads (ps )
644654 self .assertEqual (b , q )
645655
656+ def test_strip (self ):
657+ b = b'mississippi'
658+ self .assertEqual (b .strip (b'i' ), b'mississipp' )
659+ self .assertEqual (b .strip (b'm' ), b'ississippi' )
660+ self .assertEqual (b .strip (b'pi' ), b'mississ' )
661+ self .assertEqual (b .strip (b'im' ), b'ssissipp' )
662+ self .assertEqual (b .strip (b'pim' ), b'ssiss' )
663+
664+ def test_lstrip (self ):
665+ b = b'mississippi'
666+ self .assertEqual (b .lstrip (b'i' ), b'mississippi' )
667+ self .assertEqual (b .lstrip (b'm' ), b'ississippi' )
668+ self .assertEqual (b .lstrip (b'pi' ), b'mississippi' )
669+ self .assertEqual (b .lstrip (b'im' ), b'ssissippi' )
670+ self .assertEqual (b .lstrip (b'pim' ), b'ssissippi' )
671+
672+ def test_rstrip (self ):
673+ b = b'mississippi'
674+ self .assertEqual (b .rstrip (b'i' ), b'mississipp' )
675+ self .assertEqual (b .rstrip (b'm' ), b'mississippi' )
676+ self .assertEqual (b .rstrip (b'pi' ), b'mississ' )
677+ self .assertEqual (b .rstrip (b'im' ), b'mississipp' )
678+ self .assertEqual (b .rstrip (b'pim' ), b'mississ' )
679+
646680 # Optimizations:
647681 # __iter__? (optimization)
648682 # __reversed__? (optimization)
649683
650- # XXX Some string methods? (Those that don't use character properties)
651- # lstrip, rstrip, strip?? (currently un-pepped)
652- # join
653-
684+ # XXX More string methods? (Those that don't use character properties)
685+
654686 # There are tests in string_tests.py that are more
655687 # comprehensive for things like split, partition, etc.
656688 # Unfortunately they are all bundled with tests that
@@ -675,7 +707,7 @@ def checkraises(self, exc, object, methodname, *args):
675707 getattr (bytes , methodname ),
676708 object ,
677709 * args
678- )
710+ )
679711
680712 # Currently the bytes containment testing uses a single integer
681713 # value. This may not be the final design, but until then the
0 commit comments