Home | History | Annotate | Download | only in test

Lines Matching refs:bytearray

1 """Unit tests for the bytes and bytearray types.

225 # XXX Shouldn't bytes and bytearray agree on what to raise?
242 for f in bytes, bytearray:
259 b = bytearray([0x1a, 0x2b, 0x30])
297 self.assertFalse(bytearray().endswith(b"anything"))
523 type2test = bytearray
526 self.assertRaises(TypeError, hash, bytearray())
538 b = bytearray(20)
557 b = bytearray(b'hello')
560 b = bytearray(b'hello1') # test even number of items
563 b = bytearray()
569 return bytearray(map(ord, s))
574 b = bytearray([1, 2, 3])
576 self.assertEqual(b, bytearray([1, 100, 3]))
578 self.assertEqual(b, bytearray([1, 100, 200]))
580 self.assertEqual(b, bytearray([10, 100, 200]))
608 b = bytearray(range(10))
610 self.assertEqual(b, bytearray(range(1, 10)))
612 self.assertEqual(b, bytearray(range(1, 9)))
614 self.assertEqual(b, bytearray([1, 2, 3, 4, 6, 7, 8]))
617 b = bytearray(range(10))
620 b[0:5] = bytearray([1, 1, 1, 1, 1])
621 self.assertEqual(b, bytearray([1, 1, 1, 1, 1, 5, 6, 7, 8, 9]))
624 self.assertEqual(b, bytearray([5, 6, 7, 8, 9]))
626 b[0:0] = bytearray([0, 1, 2, 3, 4])
627 self.assertEqual(b, bytearray(range(10)))
629 b[-7:-3] = bytearray([100, 101])
630 self.assertEqual(b, bytearray([0, 1, 2, 100, 101, 7, 8, 9]))
633 self.assertEqual(b, bytearray(range(10)))
636 self.assertEqual(b, bytearray([0, 1, 2, 42, 42, 42, 3, 4, 5, 6, 7, 8, 9]))
645 b = bytearray(L)
652 self.assertEqual(b, bytearray(L))
656 self.assertEqual(b, bytearray(L))
661 b = bytearray(range(256))
663 self.assertEqual(b, bytearray(list(range(8)) + list(range(256))))
666 b = bytearray(b"abc")
682 b = bytearray(b"abc")
690 b = bytearray(b"x")
698 b = bytearray()
711 a = bytearray(orig)
715 a = bytearray(b'')
721 a = bytearray(b'')
725 a = bytearray(b'')
729 a = bytearray(b'')
733 a = bytearray(b'')
738 b = bytearray(b'hello')
755 b = bytearray(b'world')
760 self.assertRaises(IndexError, lambda: bytearray().pop())
762 self.assertEqual(bytearray(b'\xff').pop(), 0xff)
765 self.assertRaises(AttributeError, lambda: bytearray().sort())
768 b = bytearray(b'hell')
772 b = bytearray()
776 b = bytearray()
781 b = bytearray(b'msssspp')
789 b = bytearray()
796 b = bytearray(b'abc')
799 t = bytearray([i for i in range(256)])
800 x = bytearray(b'')
804 a, b, c = bytearray(b"x").partition(b"y")
810 a, b, c = bytearray(b"x").partition(b"y")
814 b, c, a = bytearray(b"x").rpartition(b"y")
820 c, b, a = bytearray(b"x").rpartition(b"y")
825 # #4509: can't resize a bytearray
829 b = bytearray(range(10))
860 self.assertRaises(ValueError, int, bytearray(b''))
865 # Test various combinations of bytes and bytearray
871 self.assertEqual(f(bytearray()), "bytearray(b'')")
872 self.assertEqual(f(bytearray([0])), "bytearray(b'\\x00')")
873 self.assertEqual(f(bytearray([0, 1, 254, 255])),
874 "bytearray(b'\\x00\\x01\\xfe\\xff')")
909 self.assertIsNotNone(bytearray.__doc__)
910 self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)
917 b = bytearray(buf)
918 self.assertEqual(b, bytearray(sample))
925 self.assertEqual(str(bytearray(b'')), "bytearray(b'')")
926 self.assertEqual(str(bytearray(b'x')), "bytearray(b'x')")
927 self.assertEqual(str(bytearray(b'\x80')), "bytearray(b'\\x80')")
937 self.assertEqual(b, bytearray(s, 'latin-1'))
944 ba = bytearray(b)
945 rosetta = bytearray(range(0, 256))
984 return bytearray(x)
989 # but on mutable types like bytearray they MUST return a new copy.
1028 type2test = bytearray
1031 class ByteArraySubclass(bytearray):
1037 self.assertTrue(issubclass(ByteArraySubclass, bytearray))
1038 self.assertIsInstance(ByteArraySubclass(), bytearray)
1065 s2 = bytearray().join([s1])
1067 self.assertTrue(type(s2) is bytearray, type(s2))
1071 self.assertTrue(type(s3) is bytearray)
1100 class subclass(bytearray):
1102 bytearray.__init__(self, *args, **kwargs)