Lines Matching refs:b
42 b = self.type2test()
43 self.assertEqual(type(b), self.type2test)
44 self.assertEqual(b.__class__, self.type2test)
47 b = self.type2test()
48 self.assertEqual(len(b), 0)
49 self.assertRaises(IndexError, lambda: b[0])
50 self.assertRaises(IndexError, lambda: b[1])
51 self.assertRaises(IndexError, lambda: b[sys.maxint])
52 self.assertRaises(IndexError, lambda: b[sys.maxint+1])
53 self.assertRaises(IndexError, lambda: b[10**100])
54 self.assertRaises(IndexError, lambda: b[-1])
55 self.assertRaises(IndexError, lambda: b[-2])
56 self.assertRaises(IndexError, lambda: b[-sys.maxint])
57 self.assertRaises(IndexError, lambda: b[-sys.maxint-1])
58 self.assertRaises(IndexError, lambda: b[-sys.maxint-2])
59 self.assertRaises(IndexError, lambda: b[-10**100])
63 b = self.type2test(i for i in ints)
64 self.assertEqual(len(b), 256)
65 self.assertEqual(list(b), ints)
68 b = self.type2test([Indexable(), Indexable(1), Indexable(254),
70 self.assertEqual(list(b), [0, 1, 254, 255])
75 self.assertEqual(self.type2test(0), b'')
76 self.assertEqual(self.type2test(1), b'\x00')
77 self.assertEqual(self.type2test(5), b'\x00\x00\x00\x00\x00')
80 self.assertEqual(self.type2test('0', 'ascii'), b'0')
81 self.assertEqual(self.type2test(b'0'), b'0')
133 self.assertEqual(self.type2test(b"\0a\0b\0c") == u"abc", False)
134 self.assertEqual(self.type2test(b"\0\0\0a\0\0\0b\0\0\0c") == u"abc", False)
135 self.assertEqual(self.type2test(b"a\0b\0c\0") == u"abc", False)
136 self.assertEqual(self.type2test(b"a\0\0\0b\0\0\0c\0\0\0") == u"abc", False)
142 b = self.type2test(input)
143 output = list(reversed(b))
150 b = by("Hello, world")
152 self.assertEqual(b[:5], by("Hello"))
153 self.assertEqual(b[1:5], by("ello"))
154 self.assertEqual(b[5:7], by(", "))
155 self.assertEqual(b[7:], by("world"))
156 self.assertEqual(b[7:12], by("world"))
157 self.assertEqual(b[7:100], by("world"))
159 self.assertEqual(b[:-7], by("Hello"))
160 self.assertEqual(b[-11:-7], by("ello"))
161 self.assertEqual(b[-7:-5], by(", "))
162 self.assertEqual(b[-5:], by("world"))
163 self.assertEqual(b[-5:12], by("world"))
164 self.assertEqual(b[-5:100], by("world"))
165 self.assertEqual(b[-100:5], by("Hello"))
170 b = self.type2test(L)
176 self.assertEqual(b[start:stop:step], self.type2test(L[start:stop:step]))
181 b = self.type2test(sample, enc)
182 self.assertEqual(b, self.type2test(sample.encode(enc)))
184 b = self.type2test(sample, "latin1", "ignore")
185 self.assertEqual(b, self.type2test(sample[:-4], "utf-8"))
190 b = self.type2test(sample, enc)
191 self.assertEqual(b.decode(enc), sample)
193 b = self.type2test(sample, "latin1")
194 self.assertRaises(UnicodeDecodeError, b.decode, "utf8")
195 self.assertEqual(b.decode("utf8", "ignore"), "Hello world\n")
196 self.assertEqual(b.decode(errors="ignore", encoding="utf8"),
200 b = self.type2test(0)
201 self.assertEqual(b, self.type2test())
202 b = self.type2test(10)
203 self.assertEqual(b, self.type2test([0]*10))
204 b = self.type2test(10000)
205 self.assertEqual(b, self.type2test([0]*10000))
208 b1 = self.type2test(b"abc")
209 b2 = self.type2test(b"def")
210 self.assertEqual(b1 + b2, b"abcdef")
211 self.assertEqual(b1 + bytes(b"def"), b"abcdef")
212 self.assertEqual(bytes(b"def") + b1, b"defabc")
217 for b in b"abc", self.type2test(b"abc"):
218 self.assertEqual(b * 3, b"abcabcabc")
219 self.assertEqual(b * 0, b"")
220 self.assertEqual(b * -1, b"")
221 self.assertRaises(TypeError, lambda: b * 3.14)
222 self.assertRaises(TypeError, lambda: 3.14 * b)
225 lambda: b * sys.maxsize)
228 self.assertEqual(self.type2test(b'x')*100, self.type2test([ord('x')]*100))
231 b = self.type2test(b"abc")
232 self.assertIn(ord('a'), b)
233 self.assertIn(int(ord('a')), b)
234 self.assertNotIn(200, b)
235 self.assertRaises(ValueError, lambda: 300 in b)
236 self.assertRaises(ValueError, lambda: -1 in b)
237 self.assertRaises(TypeError, lambda: None in b)
238 self.assertRaises(TypeError, lambda: float(ord('a')) in b)
239 self.assertRaises(TypeError, lambda: u"a" in b)
241 self.assertIn(f(b""), b)
242 self.assertIn(f(b"a"), b)
243 self.assertIn(f(b"b"), b)
244 self.assertIn(f(b"c"), b)
245 self.assertIn(f(b"ab"), b)
246 self.assertIn(f(b"bc"), b)
247 self.assertIn(f(b"abc"), b)
248 self.assertNotIn(f(b"ac"), b)
249 self.assertNotIn(f(b"d"), b)
250 self.assertNotIn(f(b"dab"), b)
251 self.assertNotIn(f(b"abd"), b)
257 b = bytearray([0x1a, 0x2b, 0x30])
258 self.assertEqual(self.type2test.fromhex(u'1a2B30'), b)
259 self.assertEqual(self.type2test.fromhex(u' 1A 2B 30 '), b)
260 self.assertEqual(self.type2test.fromhex(u'0000'), b'\0\0')
268 self.assertEqual(self.type2test(b"").join([]), b"")
269 self.assertEqual(self.type2test(b"").join([b""]), b"")
270 for lst in [[b"abc"], [b"a", b"bc"], [b"ab", b"c"], [b"a", b"b", b"c"]]:
272 self.assertEqual(self.type2test(b"").join(lst), b"abc")
273 self.assertEqual(self.type2test(b"").join(tuple(lst)), b"abc")
274 self.assertEqual(self.type2test(b"").join(iter(lst)), b"abc")
275 self.assertEqual(self.type2test(b".").join([b"ab", b"cd"]), b"ab.cd")
279 b = self.type2test(b'mississippi')
280 self.assertEqual(b.count(b'i'), 4)
281 self.assertEqual(b.count(b'ss'), 2)
282 self.assertEqual(b.count(b'w'), 0)
285 b = self.type2test(b'hello')
286 self.assertFalse(self.type2test().startswith(b"anything"))
287 self.assertTrue(b.startswith(b"hello"))
288 self.assertTrue(b.startswith(b"hel"))
289 self.assertTrue(b.startswith(b"h"))
290 self.assertFalse(b.startswith(b"hellow"))
291 self.assertFalse(b.startswith(b"ha"))
294 b = self.type2test(b'hello')
295 self.assertFalse(bytearray().endswith(b"anything"))
296 self.assertTrue(b.endswith(b"hello"))
297 self.assertTrue(b.endswith(b"llo"))
298 self.assertTrue(b.endswith(b"o"))
299 self.assertFalse(b.endswith(b"whello"))
300 self.assertFalse(b.endswith(b"no"))
303 b = self.type2test(b'mississippi')
304 self.assertEqual(b.find(b'ss'), 2)
305 self.assertEqual(b.find(b'ss', 3), 5)
306 self.assertEqual(b.find(b'ss', 1, 7), 2)
307 self.assertEqual(b.find(b'ss', 1, 3), -1)
308 self.assertEqual(b.find(b'w'), -1)
309 self.assertEqual(b.find(b'mississippian'), -1)
312 b = self.type2test(b'mississippi')
313 self.assertEqual(b.rfind(b'ss'), 5)
314 self.assertEqual(b.rfind(b'ss', 3), 5)
315 self.assertEqual(b.rfind(b'ss', 0, 6), 2)
316 self.assertEqual(b.rfind(b'w'), -1)
317 self.assertEqual(b.rfind(b'mississippian'), -1)
320 b = self.type2test(b'world')
321 self.assertEqual(b.index(b'w'), 0)
322 self.assertEqual(b.index(b'orl'), 1)
323 self.assertRaises(ValueError, b.index, b'worm')
324 self.assertRaises(ValueError, b.index, b'ldo')
328 b = self.type2test(b'world')
329 self.assertEqual(b.rindex(b'w'), 0)
330 self.assertEqual(b.rindex(b'orl'), 1)
331 self.assertRaises(ValueError, b.rindex, b'worm')
332 self.assertRaises(ValueError, b.rindex, b'ldo')
335 b = self.type2test(b'mississippi')
336 self.assertEqual(b.replace(b'i', b'a'), b'massassappa')
337 self.assertEqual(b.replace(b'ss', b'x'), b'mixixippi')
340 self.assertRaises(TypeError, self.type2test(b'a b').split, u' ')
343 for b in (b'a\x1Cb', b'a\x1Db', b'a\x1Eb', b'a\x1Fb'):
344 b = self.type2test(b)
345 self.assertEqual(b.split(), [b])
346 b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F")
347 self.assertEqual(b.split(), [b'\x1c\x1d\x1e\x1f'])
350 self.assertRaises(TypeError, self.type2test(b'a b').rsplit, u' ')
353 b = self.type2test(b"\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F")
354 self.assertEqual(b.rsplit(), [b'\x1c\x1d\x1e\x1f'])
357 b = self.type2test(b'mississippi')
358 self.assertEqual(b.partition(b'ss'), (b'mi', b'ss', b'issippi'))
359 self.assertEqual(b.partition(b'w'), (b'mississippi', b'', b''))
362 b = self.type2test(b'mississippi')
363 self.assertEqual(b.rpartition(b'ss'), (b'missi', b'ss', b'ippi'))
364 self.assertEqual(b.rpartition(b'i'), (b'mississipp', b'i', b''))
365 self.assertEqual(b.rpartition(b'w'), (b'', b'', b'mississippi'))
369 for b in b"", b"a", b"abc", b"\xffab\x80", b"\0\0\377\0\0":
370 b = self.type2test(b)
371 ps = pickle.dumps(b, proto)
373 self.assertEqual(b, q)
376 self.assertEqual(self.type2test(b'abc').strip(memoryview(b'ac')), b'b')
377 self.assertEqual(self.type2test(b'abc').lstrip(memoryview(b'ac')), b'bc')
378 self.assertEqual(self.type2test(b'abc').rstrip(memoryview(b'ac')), b'ab')
381 self.assertRaises(TypeError, self.type2test(b'abc').strip, u'b')
382 self.assertRaises(TypeError, self.type2test(b'abc').lstrip, u'b')
383 self.assertRaises(TypeError, self.type2test(b'abc').rstrip, u'b')
386 b = self.type2test(b'\0A\x7f\x80\xff')
387 self.assertEqual([ord(b[i:i+1]) for i in range(len(b))],
392 b = self.type2test(b'hello')
393 l = self.type2test(b'l')
394 h = self.type2test(b'h')
395 x = self.type2test(b'x')
396 o = self.type2test(b'o')
398 self.assertEqual(2, b.find(l, None))
399 self.assertEqual(3, b.find(l, -2, None))
400 self.assertEqual(2, b.find(l, None, -2))
401 self.assertEqual(0, b.find(h, None, None))
403 self.assertEqual(3, b.rfind(l, None))
404 self.assertEqual(3, b.rfind(l, -2, None))
405 self.assertEqual(2, b.rfind(l, None, -2))
406 self.assertEqual(0, b.rfind(h, None, None))
408 self.assertEqual(2, b.index(l, None))
409 self.assertEqual(3, b.index(l, -2, None))
410 self.assertEqual(2, b.index(l, None, -2))
411 self.assertEqual(0, b.index(h, None, None))
413 self.assertEqual(3, b.rindex(l, None))
414 self.assertEqual(3, b.rindex(l, -2, None))
415 self.assertEqual(2, b.rindex(l, None, -2))
416 self.assertEqual(0, b.rindex(h, None, None))
418 self.assertEqual(2, b.count(l, None))
419 self.assertEqual(1, b.count(l, -2, None))
420 self.assertEqual(1, b.count(l, None, -2))
421 self.assertEqual(0, b.count(x, None, None))
423 self.assertEqual(True, b.endswith(o, None))
424 self.assertEqual(True, b.endswith(o, -2, None))
425 self.assertEqual(True, b.endswith(l, None, -2))
426 self.assertEqual(False, b.endswith(x, None, None))
428 self.assertEqual(True, b.startswith(h, None))
429 self.assertEqual(True, b.startswith(l, -2, None))
430 self.assertEqual(True, b.startswith(h, None, -2))
431 self.assertEqual(False, b.startswith(x, None, None))
435 b = self.type2test(b'hello')
436 x = self.type2test(b'x')
437 self.assertRaisesRegexp(TypeError, r'\bfind\b', b.find,
439 self.assertRaisesRegexp(TypeError, r'\brfind\b', b.rfind,
441 self.assertRaisesRegexp(TypeError, r'\bindex\b', b.index,
443 self.assertRaisesRegexp(TypeError, r'\brindex\b', b.rindex,
445 self.assertRaisesRegexp(TypeError, r'\bcount\b', b.count,
447 self.assertRaisesRegexp(TypeError, r'\bstartswith\b', b.startswith,
449 self.assertRaisesRegexp(TypeError, r'\bendswith\b', b.endswith,
464 short_sample = b"Hello world\n"
465 sample = short_sample + b"\0"*(20 - len(short_sample))
473 b = bytearray(20)
474 n = f.readinto(b)
478 self.assertEqual(list(b), list(b_sample))
481 f.write(b)
492 b = bytearray(b'hello')
493 self.assertEqual(b.reverse(), None)
494 self.assertEqual(b, b'olleh')
495 b = bytearray(b'hello1') # test even number of items
496 b.reverse()
497 self.assertEqual(b, b'1olleh')
498 b = bytearray()
499 b.reverse()
500 self.assertFalse(b)
505 b = by("Hello, world")
506 self.assertEqual(re.findall(r"\w+", b), [by("Hello"), by("world")])
509 b = bytearray([1, 2, 3])
510 b[1] = 100
511 self.assertEqual(b, bytearray([1, 100, 3]))
512 b[-1] = 200
513 self.assertEqual(b, bytearray([1, 100, 200]))
514 b[0] = Indexable(10)
515 self.assertEqual(b, bytearray([10, 100, 200]))
517 b[3] = 0
522 b[-10] = 0
527 b[0] = 256
532 b[0] = Indexable(-1)
537 b[0] = None
543 b = bytearray(range(10))
544 del b[0]
545 self.assertEqual(b, bytearray(range(1, 10)))
546 del b[-1]
547 self.assertEqual(b, bytearray(range(1, 9)))
548 del b[4]
549 self.assertEqual(b, bytearray([1, 2, 3, 4, 6, 7, 8]))
552 b = bytearray(range(10))
553 self.assertEqual(list(b), list(range(10)))
555 b[0:5] = bytearray([1, 1, 1, 1, 1])
556 self.assertEqual(b, bytearray([1, 1, 1, 1, 1, 5, 6, 7, 8, 9]))
558 del b[0:-5]
559 self.assertEqual(b, bytearray([5, 6, 7, 8, 9]))
561 b[0:0] = bytearray([0, 1, 2, 3, 4])
562 self.assertEqual(b, bytearray(range(10)))
564 b[-7:-3] = bytearray([100, 101])
565 self.assertEqual(b, bytearray([0, 1, 2, 100, 101, 7, 8, 9]))
567 b[3:5] = [3, 4, 5, 6]
568 self.assertEqual(b, bytearray(range(10)))
570 b[3:0] = [42, 42, 42]
571 self.assertEqual(b, bytearray([0, 1, 2, 42, 42, 42, 3, 4, 5, 6, 7, 8, 9]))
573 b[3:] = b'foo'
574 self.assertEqual(b, bytearray([0, 1, 2, 102, 111, 111]))
576 b[:3] = memoryview(b'foo')
577 self.assertEqual(b, bytearray([102, 111, 111, 102, 111, 111]))
579 b[3:4] = []
580 self.assertEqual(b, bytearray([102, 111, 111, 111, 111]))
582 b[1:] = list(b'uuuu') # this works only on Python2
583 self.assertEqual(b, bytearray([102, 117, 117, 117, 117]))
587 b[3:4] = elem
591 b[3:4] = elem
600 b = bytearray(L)
606 b[start:stop:step] = data
607 self.assertEqual(b, bytearray(L))
610 del b[start:stop:step]
611 self.assertEqual(b, bytearray(L))
616 b = bytearray(range(256))
617 b[8:] = b
618 self.assertEqual(b, bytearray(list(range(8)) + list(range(256))))
621 b = bytearray(b"abc")
622 b1 = b
623 b += b"def"
624 self.assertEqual(b, b"abcdef")
625 self.assertEqual(b, b1)
626 self.assertTrue(b is b1)
627 b += b"xyz"
628 self.assertEqual(b, b"abcdefxyz")
630 b += u""
637 b = bytearray(b"abc")
638 b1 = b
639 b *= 3
640 self.assertEqual(b, b"abcabcabc")
641 self.assertEqual(b, b1)
642 self.assertTrue(b is b1)
645 b = bytearray(b"x")
646 b1 = b
647 b *= 100
648 self.assertEqual(b, b"x"*100)
649 self.assertEqual(b, b1)
650 self.assertTrue(b is b1)
653 b = bytearray()
654 alloc = b.__alloc__()
658 b += b"x"
659 alloc = b.__alloc__()
660 self.assertGreater(alloc, len(b)) # including trailing null byte
665 b = bytearray()
669 a = list(b)
671 self.assertEqual(len(b), len(a))
672 self.assertLessEqual(len(b), i)
673 alloc = b.__alloc__()
674 self.assertGreater(alloc, len(b)) # including trailing null byte
675 b.__init__(g())
676 self.assertEqual(list(b), list(range(1, 100)))
677 self.assertEqual(len(b), 99)
678 alloc = b.__alloc__()
679 self.assertGreater(alloc, len(b))
682 orig = b'hello'
687 a = bytearray(b'')
693 a = bytearray(b'')
697 a = bytearray(b'')
701 a = bytearray(b'')
705 a = bytearray(b'')
707 self.assertEqual(a, b'a')
710 b = bytearray(b'hello')
711 b.remove(ord('l'))
712 self.assertEqual(b, b'helo')
713 b.remove(ord('l'))
714 self.assertEqual(b, b'heo')
715 self.assertRaises(ValueError, lambda: b.remove(ord('l')))
716 self.assertRaises(ValueError, lambda: b.remove(400))
717 self.assertRaises(TypeError, lambda: b.remove(u'e'))
719 b.remove(ord('o'))
720 b.remove(ord('h'))
721 self.assertEqual(b, b'e')
722 self.assertRaises(TypeError, lambda: b.remove(u'e'))
723 b.remove(Indexable(ord('e')))
724 self.assertEqual(b, b'')
734 b = bytearray(b'world')
735 self.assertEqual(b.pop(), ord('d'))
736 self.assertEqual(b.pop(0), ord('w'))
737 self.assertEqual(b.pop(-2), ord('r'))
738 self.assertRaises(IndexError, lambda: b.pop(10))
741 self.assertEqual(bytearray(b'\xff').pop(), 0xff)
747 b = bytearray(b'hell')
748 b.append(ord('o'))
749 self.assertEqual(b, b'hello')
750 self.assertEqual(b.append(100), None)
751 b = bytearray()
752 b.append(ord('A'))
753 self.assertEqual(len(b), 1)
754 self.assertRaises(TypeError, lambda: b.append(u'o'))
755 b = bytearray()
756 b.append(Indexable(ord('A')))
757 self.assertEqual(b, b'A')
760 b = bytearray(b'msssspp')
761 b.insert(1, ord('i'))
762 b.insert(4, ord('i'))
763 b.insert(-2, ord('i'))
764 b.insert(1000, ord('i'))
765 self.assertEqual(b, b'mississippi')
768 b = bytearray()
769 b.insert(0, Indexable(ord('A')))
770 self.assertEqual(b, b'A')
775 b = bytearray(b'abc')
776 self.assertFalse(b is b.replace(b'abc', b'cde', 0))
779 x = bytearray(b'')
783 a, b, c = bytearray(b"x").partition(b"y")
784 self.assertEqual(b, b"")
785 self.assertEqual(c, b"")
786 self.assertTrue(b is not c)
787 b += b"!"
788 self.assertEqual(c, b"")
789 a, b, c = bytearray(b"x").partition(b"y")
790 self.assertEqual(b, b"")
791 self.assertEqual(c, b"")
793 b, c, a = bytearray(b"x").rpartition(b"y")
794 self.assertEqual(b, b"")
795 self.assertEqual(c, b"")
796 self.assertTrue(b is not c)
797 b += b"!"
798 self.assertEqual(c, b"")
799 c, b, a = bytearray(b"x").rpartition(b"y")
800 self.assertEqual(b, b"")
801 self.assertEqual(c, b"")
808 b = bytearray(range(10))
809 v = memoryview(b)
811 b[1:-1] = range(n + 1, 2*n - 1)
813 orig = b[:]
815 self.assertEqual(b, orig)
817 self.assertEqual(b, orig)
819 self.assertEqual(b, orig)
821 self.assertRaises(BufferError, b.pop, 0)
822 self.assertEqual(b, orig)
823 self.assertRaises(BufferError, b.remove, b[1])
824 self.assertEqual(b, orig)
826 del b[1]
828 self.assertEqual(b, orig)
831 b[1:-1:2] = b""
833 self.assertEqual(b, orig)
839 self.assertRaises(ValueError, int, bytearray(b''))
864 self.assertEqual(f(b"abc"), "b'abc'")
865 self.assertEqual(f(b"'"), '''b"'"''') # '''
866 self.assertEqual(f(b"'\""), r"""b'\'"'""") # '
869 self.assertEqual(b"abc" == bytes(b"abc"), True)
870 self.assertEqual(b"ab" != bytes(b"abc"), True)
871 self.assertEqual(b"ab" <= bytes(b"abc"), True)
872 self.assertEqual(b"ab" < bytes(b"abc"), True)
873 self.assertEqual(b"abc" >= bytes(b"ab"), True)
874 self.assertEqual(b"abc" > bytes(b"ab"), True)
876 self.assertEqual(b"abc" != bytes(b"abc"), False)
877 self.assertEqual(b"ab" == bytes(b"abc"), False)
878 self.assertEqual(b"ab" > bytes(b"abc"), False)
879 self.assertEqual(b"ab" >= bytes(b"abc"), False)
880 self.assertEqual(b"abc" < bytes(b"ab"), False)
881 self.assertEqual(b"abc" <= bytes(b"ab"), False)
883 self.assertEqual(bytes(b"abc") == b"abc", True)
884 self.assertEqual(bytes(b"ab") != b"abc", True)
885 self.assertEqual(bytes(b"ab") <= b"abc", True)
886 self.assertEqual(bytes(b"ab") < b"abc", True)
887 self.assertEqual(bytes(b"abc") >= b"ab", True)
888 self.assertEqual(bytes(b"abc") > b"ab", True)
890 self.assertEqual(bytes(b"abc") != b"abc", False)
891 self.assertEqual(bytes(b"ab") == b"abc", False)
892 self.assertEqual(bytes(b"ab") > b"abc", False)
893 self.assertEqual(bytes(b"ab") >= b"abc", False)
894 self.assertEqual(bytes(b"abc") < b"ab", False)
895 self.assertEqual(bytes(b"abc") <= b"ab", False)
905 sample = bytes(b"Hello world\n\x80\x81\xfe\xff")
907 b = bytearray(buf)
908 self.assertEqual(b, bytearray(sample))
912 self.assertEqual(str(b''), "b''")
913 self.assertEqual(str(b'x'), "b'x'")
914 self.assertEqual(str(b'\x80'), "b'\\x80'")
915 self.assertEqual(str(bytearray(b'')), "bytearray(b'')")
916 self.assertEqual(str(bytearray(b'x')), "bytearray(b'x')")
917 self.assertEqual(str(bytearray(b'\x80')), "bytearray(b'\\x80')")
921 (b"Wonderful spam", "Wonderful spam"),
923 (b"\xaa\x00\000\200", "\xaa\x00\000\200"),
926 for b, s in tests:
927 self.assertEqual(b, bytearray(s, 'latin-1'))
933 b = b'hello'
934 ba = bytearray(b)
937 c = b.translate(rosetta, b'l')
938 self.assertEqual(b, b'hello')
939 self.assertEqual(c, b'hee')
940 c = ba.translate(rosetta, b'l')
941 self.assertEqual(ba, b'hello')
942 self.assertEqual(c, b'hee')
943 c = b.translate(None, b'e')
944 self.assertEqual(c, b'hllo')
945 c = ba.translate(None, b'e')
946 self.assertEqual(c, b'hllo')
947 self.assertRaises(TypeError, b.translate, None, None)
951 self.assertEqual(b'a b'.split(memoryview(b' ')), [b'a', b'b'])
954 self.assertEqual(b'a b'.rsplit(memoryview(b' ')), [b'a', b'b'])
976 val = self.marshal(b'1234')
1023 a, b = b"abcd", b"efgh"
1024 _a, _b = ByteArraySubclass(a), ByteArraySubclass(b)
1036 self.assertEqual(a + b, _a + _b)
1037 self.assertEqual(a + b, a + _b)
1038 self.assertEqual(a + b, _a + b)
1047 s1 = ByteArraySubclass(b"abcd")
1053 s3 = s1.join([b"abcd"])
1057 a = ByteArraySubclass(b"abcd")
1059 a.y = ByteArraySubclass(b"efgh")
1061 b = pickle.loads(pickle.dumps(a, proto))
1062 self.assertNotEqual(id(a), id(b))
1063 self.assertEqual(a, b)
1064 self.assertEqual(a.x, b.x)
1065 self.assertEqual(a.y, b.y)
1066 self.assertEqual(type(a), type(b))
1067 self.assertEqual(type(a.y), type(b.y))
1070 a = ByteArraySubclass(b"abcd")
1072 a.y = ByteArraySubclass(b"efgh")
1074 b = copy_method(a)
1075 self.assertNotEqual(id(a), id(b))
1076 self.assertEqual(a, b)
1077 self.assertEqual(a.x, b.x)
1078 self.assertEqual(a.y, b.y)
1079 self.assertEqual(type(a), type(b))
1080 self.assertEqual(type(a.y), type(b.y))
1086 x = subclass(4, source=b"abcd")
1087 self.assertEqual(x, b"abcd")
1088 x = subclass(newarg=4, source=b"abcd")
1089 self.assertEqual(x, b"abcd")