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]))
639 self.assertEqual(b, bytearray([0, 1, 2, 102, 111, 111]))
642 self.assertEqual(b, bytearray([102, 111, 111, 102, 111, 111]))
645 self.assertEqual(b, bytearray([102, 111, 111, 111, 111]))
648 self.assertEqual(b, bytearray([102, 117, 117, 117, 117]))
665 b = bytearray(L)
672 self.assertEqual(b, bytearray(L))
676 self.assertEqual(b, bytearray(L))
681 b = bytearray(range(256))
683 self.assertEqual(b, bytearray(list(range(8)) + list(range(256))))
686 b = bytearray(b"abc")
702 b = bytearray(b"abc")
710 b = bytearray(b"x")
718 b = bytearray()
731 a = bytearray(orig)
735 a = bytearray(b'')
741 a = bytearray(b'')
745 a = bytearray(b'')
749 a = bytearray(b'')
753 a = bytearray(b'')
758 b = bytearray(b'hello')
775 b = bytearray(b'world')
780 self.assertRaises(IndexError, lambda: bytearray().pop())
782 self.assertEqual(bytearray(b'\xff').pop(), 0xff)
785 self.assertRaises(AttributeError, lambda: bytearray().sort())
788 b = bytearray(b'hell')
792 b = bytearray()
796 b = bytearray()
801 b = bytearray(b'msssspp')
809 b = bytearray()
816 b = bytearray(b'abc')
819 t = bytearray([i for i in range(256)])
820 x = bytearray(b'')
824 a, b, c = bytearray(b"x").partition(b"y")
830 a, b, c = bytearray(b"x").partition(b"y")
834 b, c, a = bytearray(b"x").rpartition(b"y")
840 c, b, a = bytearray(b"x").rpartition(b"y")
845 # #4509: can't resize a bytearray when there are buffer exports, even
849 b = bytearray(range(10))
880 self.assertRaises(ValueError, int, bytearray(b''))
885 # Test various combinations of bytes and bytearray
891 self.assertEqual(f(bytearray()), "bytearray(b'')")
892 self.assertEqual(f(bytearray([0])), "bytearray(b'\\x00')")
893 self.assertEqual(f(bytearray([0, 1, 254, 255])),
894 "bytearray(b'\\x00\\x01\\xfe\\xff')")
930 self.assertIsNotNone(bytearray.__doc__)
931 self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)
938 b = bytearray(buf)
939 self.assertEqual(b, bytearray(sample))
946 self.assertEqual(str(bytearray(b'')), "bytearray(b'')")
947 self.assertEqual(str(bytearray(b'x')), "bytearray(b'x')")
948 self.assertEqual(str(bytearray(b'\x80')), "bytearray(b'\\x80')")
958 self.assertEqual(b, bytearray(s, 'latin-1'))
965 ba = bytearray(b)
966 rosetta = bytearray(range(0, 256))
1005 return bytearray(x)
1010 # but on mutable types like bytearray they MUST return a new copy.
1049 type2test = bytearray
1052 class ByteArraySubclass(bytearray):
1058 self.assertTrue(issubclass(ByteArraySubclass, bytearray))
1059 self.assertIsInstance(ByteArraySubclass(), bytearray)
1086 s2 = bytearray().join([s1])
1088 self.assertTrue(type(s2) is bytearray, type(s2))
1092 self.assertTrue(type(s3) is bytearray)
1121 class subclass(bytearray):
1123 bytearray.__init__(self, *args, **kwargs)