(self)
| 1835 | self.assertGreater(alloc, len(b)) |
| 1836 | |
| 1837 | def test_extend(self): |
| 1838 | orig = b'hello' |
| 1839 | a = bytearray(orig) |
| 1840 | a.extend(a) |
| 1841 | self.assertEqual(a, orig + orig) |
| 1842 | self.assertEqual(a[5:], orig) |
| 1843 | a = bytearray(b'') |
| 1844 | # Test iterators that don't have a __length_hint__ |
| 1845 | a.extend(map(int, orig * 25)) |
| 1846 | a.extend(int(x) for x in orig * 25) |
| 1847 | self.assertEqual(a, orig * 50) |
| 1848 | self.assertEqual(a[-5:], orig) |
| 1849 | a = bytearray(b'') |
| 1850 | a.extend(iter(map(int, orig * 50))) |
| 1851 | self.assertEqual(a, orig * 50) |
| 1852 | self.assertEqual(a[-5:], orig) |
| 1853 | a = bytearray(b'') |
| 1854 | a.extend(list(map(int, orig * 50))) |
| 1855 | self.assertEqual(a, orig * 50) |
| 1856 | self.assertEqual(a[-5:], orig) |
| 1857 | a = bytearray(b'') |
| 1858 | self.assertRaises(ValueError, a.extend, [0, 1, 2, 256]) |
| 1859 | self.assertRaises(ValueError, a.extend, [0, 1, 2, -1]) |
| 1860 | self.assertEqual(len(a), 0) |
| 1861 | a = bytearray(b'') |
| 1862 | a.extend([Indexable(ord('a'))]) |
| 1863 | self.assertEqual(a, b'a') |
| 1864 | a = bytearray(b'abc') |
| 1865 | self.assertRaisesRegex(TypeError, # Override for string. |
| 1866 | "expected iterable of integers; got: 'str'", |
| 1867 | a.extend, 'def') |
| 1868 | self.assertRaisesRegex(TypeError, # But not for others. |
| 1869 | "can't extend bytearray with float", |
| 1870 | a.extend, 1.0) |
| 1871 | |
| 1872 | def test_remove(self): |
| 1873 | b = bytearray(b'hello') |
nothing calls this directly
no test coverage detected