Home | History | Annotate | Download | only in test

Lines Matching refs:bytearray

1 """Unit tests for the bytes and bytearray types.
143 bytearray(size - 4)
269 # XXX Shouldn't bytes and bytearray agree on what to raise?
289 for f in bytes, bytearray:
306 b = bytearray([0x1a, 0x2b, 0x30])
335 self.assertEqual(bytearray([0x1a, 0x2b, 0x30]).hex(), '1a2b30')
351 self.assertEqual(dot_join([bytearray(b"ab"), b"cd"]), b"ab.:cd")
352 self.assertEqual(dot_join([b"ab", bytearray(b"cd")]), b"ab.:cd")
361 dot_join([bytearray(b"ab"), "cd", b"ef"])
404 self.assertFalse(bytearray
598 # Fill character can be either bytes or bytearray (issue 12380)
600 for fill_type in (bytes, bytearray):
605 # Fill character can be either bytes or bytearray (issue 12380)
607 for fill_type in (bytes, bytearray):
612 # Fill character can be either bytes or bytearray (issue 12380)
614 for fill_type in (bytes, bytearray):
707 rosetta = bytearray(range(256))
914 class BufferBlocked(bytearray):
916 ba, bb = bytearray(b'ab'), BufferBlocked(b'ab')
922 type2test = bytearray
925 msg = "bytearray indices must be integers or slices"
927 bytearray(b'python')['a']
930 msg = "bytearray indices must be integers or slices"
932 b = bytearray(b'python')
936 self.assertRaises(TypeError, hash, bytearray())
948 b = bytearray(20)
965 b = bytearray(b'hello')
968 b = bytearray(b'hello1') # test even number of items
971 b = bytearray()
976 b = bytearray(b'python')
980 b = bytearray(b'')
984 b = bytearray(b'')
991 b = bytearray(b'abc')
995 b = bytearray(b'')
1000 b = bytearray(b'abc')
1010 return bytearray(map(ord, s))
1015 b = bytearray([1, 2, 3])
1017 self.assertEqual(b, bytearray([1, 100, 3]))
1019 self.assertEqual(b, bytearray([1, 100, 200]))
1021 self.assertEqual(b, bytearray([10, 100, 200]))
1049 b = bytearray(range(10))
1051 self.assertEqual(b, bytearray(range(1, 10)))
1053 self.assertEqual(b, bytearray(range(1, 9)))
1055 self.assertEqual(b, bytearray([1, 2, 3, 4, 6, 7, 8]))
1058 b = bytearray(range(10))
1061 b[0:5] = bytearray([1, 1, 1, 1, 1])
1062 self.assertEqual(b, bytearray([1, 1, 1, 1, 1, 5, 6, 7, 8, 9]))
1065 self.assertEqual(b, bytearray([5, 6, 7, 8, 9]))
1067 b[0:0] = bytearray([0, 1, 2, 3, 4])
1068 self.assertEqual(b, bytearray(range(10)))
1070 b[-7:-3] = bytearray([100, 101])
1071 self.assertEqual(b, bytearray([0, 1, 2, 100, 101, 7, 8, 9]))
1074 self.assertEqual(b, bytearray(range(10)))
1077 self.assertEqual(b, bytearray([0, 1, 2, 42, 42, 42, 3, 4, 5, 6, 7, 8, 9]))
1080 self.assertEqual(b, bytearray([0, 1, 2, 102, 111, 111]))
1083 self.assertEqual(b, bytearray([102, 111, 111, 102, 111, 111]))
1086 self.assertEqual(b, bytearray([102, 111, 111, 111, 111]))
1099 b = bytearray(range(100))
1109 b = bytearray(10)
1117 b = bytearray(10)
1129 b = bytearray(L)
1136 self.assertEqual(b, bytearray(L))
1140 self.assertEqual(b, bytearray(L))
1145 b = bytearray(range(256))
1147 self.assertEqual(b, bytearray(list(range(8)) + list(range(256))))
1150 b = bytearray(b"abc")
1166 b = bytearray(b"abc")
1174 b = bytearray(b"x")
1182 b = bytearray()
1194 b = bytearray()
1212 a = bytearray(orig)
1216 a = bytearray(b'')
1222 a = bytearray(b'')
1226 a = bytearray(b'')
1230 a = bytearray(b'')
1234 a = bytearray(b'')
1239 b = bytearray(b'hello')
1256 c = bytearray
1263 b = bytearray(b'world')
1268 self.assertRaises(IndexError, lambda: bytearray().pop())
1270 self.assertEqual(bytearray(b'\xff').pop(), 0xff)
1273 self.assertRaises(AttributeError, lambda: bytearray().sort())
1276 b = bytearray(b'hell')
1280 b = bytearray()
1284 b = bytearray()
1289 b = bytearray(b'msssspp')
1296 b = bytearray()
1303 b = bytearray(b'abc')
1306 t = bytearray([i for i in range(256)])
1307 x = bytearray(b'')
1311 a, b, c = bytearray(b"x").partition(b"y")
1317 a, b, c = bytearray(b"x").partition(b"y")
1321 b, c, a = bytearray(b"x").rpartition(b"y")
1327 c, b, a = bytearray(b"x").rpartition(b"y")
1332 # #4509: can't resize a bytearray when there are buffer exports, even
1336 b = bytearray(range(10))
1366 self.assertRaises(BufferError, getbuffer_with_null_view, bytearray())
1369 orig = bytearray(b'abc')
1408 ba = bytearray(b'ab')
1418 # Test various combinations of bytes and bytearray
1424 self.assertEqual(f(bytearray()), "bytearray(b'')")
1425 self.assertEqual(f(bytearray([0])), "bytearray(b'\\x00')")
1426 self.assertEqual(f(bytearray([0, 1, 254, 255])),
1427 "bytearray(b'\\x00\\x01\\xfe\\xff')")
1434 for b in b'abc', bytearray(b'abc'):
1472 self.assertIsNotNone(bytearray.__doc__)
1473 self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)
1480 b = bytearray(buf)
1481 self.assertEqual(b, bytearray(sample))
1488 self.assertEqual(str(bytearray(b'')), "bytearray(b'')")
1489 self.assertEqual(str(bytearray(b'x')), "bytearray(b'x')")
1490 self.assertEqual(str(bytearray(b'\x80')), "bytearray(b'\\x80')")
1500 self.assertEqual(b, bytearray(s, 'latin-1'))
1512 # bytearray.replace must always return a new bytearray
1513 b = bytearray()
1530 bytearray(b'') == ''
1532 '' == bytearray(b'')
1534 bytearray(b'') != ''
1536 '' != bytearray(b'')
1563 return bytearray(x)
1568 # but on mutable types like bytearray they MUST return a new copy.
1597 type2test = bytearray
1696 class ByteArraySubclass(bytearray):
1706 basetype = bytearray
1710 class subclass(bytearray):
1712 bytearray.__init__(me, *args, **kwargs)