Lines Matching refs:bytearray

1 """Unit tests for the bytes and bytearray types.
206 bytearray(size - 4)
211 # Issue #34974: bytes and bytearray constructors replace unexpected
402 # XXX Shouldn't bytes and bytearray agree on what to raise?
422 for f in bytes, bytearray:
439 b = bytearray([0x1a, 0x2b, 0x30])
476 self.assertEqual(bytearray([0x1a, 0x2b, 0x30]).hex(), '1a2b30')
549 self.assertEqual(dot_join([bytearray(b"ab"), b"cd"]), b"ab.:cd")
550 self.assertEqual(dot_join([b"ab", bytearray(b"cd")]), b"ab.:cd")
563 dot_join([bytearray(b"ab"), "cd", b"ef"])
606 self.assertFalse(bytearray().endswith(b"anything"))
846 # Fill character can be either bytes or bytearray (issue 12380)
848 for fill_type in (bytes, bytearray):
853 # Fill character can be either bytes or bytearray (issue 12380)
855 for fill_type in (bytes, bytearray):
860 # Fill character can be either bytes or bytearray (issue 12380)
862 for fill_type in (bytes, bytearray):
960 rosetta = bytearray(range(256))
1196 class BufferBlocked(bytearray):
1198 ba, bb = bytearray(b'ab'), BufferBlocked(b'ab')
1226 type2test = bytearray
1229 b = bytearray(b'python')
1230 msg = "bytearray indices must be integers or slices"
1235 b = bytearray(b'python')
1236 msg = "bytearray indices must be integers or slices"
1241 self.assertRaises(TypeError, hash, bytearray())
1253 b = bytearray(20)
1270 b = bytearray(b'hello')
1273 b = bytearray(b'hello1') # test even number of items
1276 b = bytearray()
1281 b = bytearray(b'python')
1285 b = bytearray(b'')
1289 b = bytearray(b'')
1296 b = bytearray(b'abc')
1300 b = bytearray(b'')
1305 b = bytearray(b'abc')
1315 return bytearray(map(ord, s))
1320 b = bytearray([1, 2, 3])
1322 self.assertEqual(b, bytearray([1, 100, 3]))
1324 self.assertEqual(b, bytearray([1, 100, 200]))
1326 self.assertEqual(b, bytearray([10, 100, 200]))
1354 b = bytearray(range(10))
1356 self.assertEqual(b, bytearray(range(1, 10)))
1358 self.assertEqual(b, bytearray(range(1, 9)))
1360 self.assertEqual(b, bytearray([1, 2, 3, 4, 6, 7, 8]))
1363 b = bytearray(range(10))
1366 b[0:5] = bytearray([1, 1, 1, 1, 1])
1367 self.assertEqual(b, bytearray([1, 1, 1, 1, 1, 5, 6, 7, 8, 9]))
1370 self.assertEqual(b, bytearray([5, 6, 7, 8, 9]))
1372 b[0:0] = bytearray([0, 1, 2, 3, 4])
1373 self.assertEqual(b, bytearray(range(10)))
1375 b[-7:-3] = bytearray([100, 101])
1376 self.assertEqual(b, bytearray([0, 1, 2, 100, 101, 7, 8, 9]))
1379 self.assertEqual(b, bytearray(range(10)))
1382 self.assertEqual(b, bytearray([0, 1, 2, 42, 42, 42, 3, 4, 5, 6, 7, 8, 9]))
1385 self.assertEqual(b, bytearray([0, 1, 2, 102, 111, 111]))
1388 self.assertEqual(b, bytearray([102, 111, 111, 102, 111, 111]))
1391 self.assertEqual(b, bytearray([102, 111, 111, 111, 111]))
1404 b = bytearray(range(100))
1414 b = bytearray(10)
1422 b = bytearray(10)
1435 b = bytearray(L)
1442 self.assertEqual(b, bytearray(L))
1446 self.assertEqual(b, bytearray(L))
1451 b = bytearray(range(256))
1453 self.assertEqual(b, bytearray(list(range(8)) + list(range(256))))
1456 b = bytearray(b"abc")
1472 b = bytearray(b"abc")
1480 b = bytearray(b"x")
1488 b = bytearray()
1500 b = bytearray()
1518 a = bytearray(orig)
1522 a = bytearray(b'')
1528 a = bytearray(b'')
1532 a = bytearray(b'')
1536 a = bytearray(b'')
1540 a = bytearray(b'')
1545 b = bytearray(b'hello')
1562 c = bytearray([126, 127, 128, 129])
1569 b = bytearray(b'world')
1574 self.assertRaises(IndexError, lambda: bytearray().pop())
1576 self.assertEqual(bytearray(b'\xff').pop(), 0xff)
1579 self.assertRaises(AttributeError, lambda: bytearray().sort())
1582 b = bytearray(b'hell')
1586 b = bytearray()
1590 b = bytearray()
1595 b = bytearray(b'msssspp')
1602 b = bytearray()
1609 b = bytearray(b'abc')
1612 t = bytearray([i for i in range(256)])
1613 x = bytearray(b'')
1617 a, b, c = bytearray(b"x").partition(b"y")
1623 a, b, c = bytearray(b"x").partition(b"y")
1627 b, c, a = bytearray(b"x").rpartition(b"y")
1633 c, b, a = bytearray(b"x").rpartition(b"y")
1638 # #4509: can't resize a bytearray when there are buffer exports, even
1642 b = bytearray(range(10))
1672 self.assertRaises(BufferError, _testcapi.getbuffer_with_null_view, bytearray())
1675 orig = bytearray(b'abc')
1714 ba = bytearray(b'ab')
1723 b = bytearray(b'abc')
1738 b = bytearray(b'Now you see me...')
1744 b = bytearray(b'Now you see me...')
1751 # Test various combinations of bytes and bytearray
1757 self.assertEqual(f(bytearray()), "bytearray(b'')")
1758 self.assertEqual(f(bytearray([0])), "bytearray(b'\\x00')")
1759 self.assertEqual(f(bytearray([0, 1, 254, 255])),
1760 "bytearray(b'\\x00\\x01\\xfe\\xff')")
1767 for b in b'abc', bytearray(b'abc'):
1805 self.assertIsNotNone(bytearray.__doc__)
1806 self.assertTrue(bytearray.__doc__.startswith("bytearray("), bytearray.__doc__)
1813 b = bytearray(buf)
1814 self.assertEqual(b, bytearray(sample))
1821 self.assertEqual(str(bytearray(b'')), "bytearray(b'')")
1822 self.assertEqual(str(bytearray(b'x')), "bytearray(b'x')")
1823 self.assertEqual(str(bytearray(b'\x80')), "bytearray(b'\\x80')")
1833 self.assertEqual(b, bytearray(s, 'latin-1'))
1845 # bytearray.replace must always return a new bytearray
1846 b = bytearray()
1863 bytearray(b'') == ''
1865 '' == bytearray(b'')
1867 bytearray(b'') != ''
1869 '' != bytearray(b'')
1896 return bytearray(x)
1901 # but on mutable types like bytearray they MUST return a new copy.
1930 type2test = bytearray
2031 class ByteArraySubclass(bytearray):
2034 class ByteArraySubclassWithSlots(bytearray):
2044 basetype = bytearray
2048 class subclass(bytearray):
2050 bytearray.__init__(me, *args, **kwargs)
2058 basetype = bytearray