Home | History | Annotate | Download | only in test

Lines Matching refs:bytearray

1 """Unit tests for the bytes and bytearray types.
223 # XXX Shouldn't bytes and bytearray agree on what to raise?
240 for f in bytes, bytearray:
257 b = bytearray([0x1a, 0x2b, 0x30])
295 self.assertFalse(bytearray().endswith(b"anything"))
458 type2test = bytearray
461 self.assertRaises(TypeError, hash, bytearray())
473 b = bytearray(20)
492 b = bytearray(b'hello')
495 b = bytearray(b'hello1') # test even number of items
498 b = bytearray()
504 return bytearray(map(ord, s))
509 b = bytearray([1, 2, 3])
511 self.assertEqual(b, bytearray([1, 100, 3]))
513 self.assertEqual(b, bytearray([1, 100, 200]))
515 self.assertEqual(b, bytearray([10, 100, 200]))
543 b = bytearray(range(10))
545 self.assertEqual(b, bytearray(range(1, 10)))
547 self.assertEqual(b, bytearray(range(1, 9)))
549 self.assertEqual(b, bytearray([1, 2, 3, 4, 6, 7, 8]))
552 b = bytearray(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]))
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]))
568 self.assertEqual(b, bytearray(range(10)))
571 self.assertEqual(b, bytearray([0, 1, 2, 42, 42, 42, 3, 4, 5, 6, 7, 8, 9]))
574 self.assertEqual(b, bytearray([0, 1, 2, 102, 111, 111]))
577 self.assertEqual(b, bytearray([102, 111, 111, 102, 111, 111]))
580 self.assertEqual(b, bytearray([102, 111, 111, 111, 111]))
583 self.assertEqual(b, bytearray([102, 117, 117, 117, 117]))
600 b = bytearray(L)
607 self.assertEqual(b, bytearray(L))
611 self.assertEqual(b, bytearray(L))
616 b = bytearray(range(256))
618 self.assertEqual(b, bytearray(list(range(8)) + list(range(256))))
621 b = bytearray(b"abc")
637 b = bytearray(b"abc")
645 b = bytearray(b"x")
653 b = bytearray()
665 b = bytearray()
683 a = bytearray(orig)
687 a = bytearray(b'')
693 a = bytearray(b'')
697 a = bytearray(b'')
701 a = bytearray(b'')
705 a = bytearray(b'')
710 b = bytearray(b'hello')
727 c = bytearray([126, 127, 128, 129])
729 self.assertEqual(c, bytearray([126, 128, 129]))
731 self.assertEqual(c, bytearray([126, 128]))
734 b = bytearray(b'world')
739 self.assertRaises(IndexError, lambda: bytearray().pop())
741 self.assertEqual(bytearray(b'\xff').pop(), 0xff)
744 self.assertRaises(AttributeError, lambda: bytearray().sort())
747 b = bytearray(b'hell')
751 b = bytearray()
755 b = bytearray()
760 b = bytearray(b'msssspp')
768 b = bytearray()
775 b = bytearray(b'abc')
778 t = bytearray([i for i in range(256)])
779 x = bytearray(b'')
783 a, b, c = bytearray(b"x").partition(b"y")
789 a, b, c = bytearray(b"x").partition(b"y")
793 b, c, a = bytearray(b"x").rpartition(b"y")
799 c, b, a = bytearray(b"x").rpartition(b"y")
804 # #4509: can't resize a bytearray when there are buffer exports, even
808 b = bytearray(range(10))
839 self.assertRaises(ValueError, int, bytearray(b''))
854 # Test various combinations of bytes and bytearray
860 self.assertEqual(f(bytearray()), "bytearray(b'')")
861 self.assertEqual(f(bytearray([0])), "bytearray(b'\\x00')")
862 self.assertEqual(f(bytearray([0, 1, 254, 255])),
863 "bytearray(b'\\x00\\x01\\xfe\\xff')")
899 self.assertIsNotNone(bytearray.__doc__)
900 self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)
907 b = bytearray(buf)
908 self.assertEqual(b, bytearray(sample))
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')")
927 self.assertEqual(b, bytearray(s, 'latin-1'))
934 ba = bytearray(b)
935 rosetta = bytearray(range(0, 256))
973 return bytearray(x)
978 # but on mutable types like bytearray they MUST return a new copy.
996 type2test = bytearray
1014 class ByteArraySubclass(bytearray):
1020 self.assertTrue(issubclass(ByteArraySubclass, bytearray))
1021 self.assertIsInstance(ByteArraySubclass(), bytearray)
1048 s2 = bytearray().join([s1])
1050 self.assertTrue(type(s2) is bytearray, type(s2))
1054 self.assertTrue(type(s3) is bytearray)
1083 class subclass(bytearray):
1085 bytearray.__init__(self, *args, **kwargs)