Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_bytes.py @ 68221:08804aea08f1
Issue #10516: added copy() and clear() methods to bytearrays as well
| author | Eli Bendersky <eliben@gmail.com> |
|---|---|
| date | Thu, 03 Mar 2011 18:21:02 +0000 |
| parents | be6c38d1817b |
| children | d2b5bde5c1fa |
line wrap: on
line diff
--- a/Lib/test/test_bytes.py Thu Mar 03 18:03:36 2011 +0000 +++ b/Lib/test/test_bytes.py Thu Mar 03 18:21:02 2011 +0000 @@ -564,6 +564,39 @@ b.reverse() self.assertFalse(b) + def test_clear(self): + b = bytearray(b'python') + b.clear() + self.assertEqual(b, b'') + + b = bytearray(b'') + b.clear() + self.assertEqual(b, b'') + + b = bytearray(b'') + b.append(ord('r')) + b.clear() + b.append(ord('p')) + self.assertEqual(b, b'p') + + def test_copy(self): + b = bytearray(b'abc') + bb = b.copy() + self.assertEqual(bb, b'abc') + + b = bytearray(b'') + bb = b.copy() + self.assertEqual(bb, b'') + + # test that it's indeed a copy and not a reference + b = bytearray(b'abc') + bb = b.copy() + self.assertEqual(b, bb) + self.assertIsNot(b, bb) + bb.append(ord('d')) + self.assertEqual(bb, b'abcd') + self.assertEqual(b, b'abc') + def test_regexps(self): def by(s): return bytearray(map(ord, s))
