summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2011-03-03 18:21:02 (GMT)
committerEli Bendersky <eliben@gmail.com>2011-03-03 18:21:02 (GMT)
commit4db28d3343da7e48946a62036058fc6f0ee7cd71 (patch)
treef70ae2f75439eaf594b3877f5fd77a365e040caf /Lib/test/test_bytes.py
parent91221f2857961cfed3411e5c49cfa256d9c6a3f8 (diff)
downloadcpython-4db28d3343da7e48946a62036058fc6f0ee7cd71.zip
cpython-4db28d3343da7e48946a62036058fc6f0ee7cd71.tar.gz
cpython-4db28d3343da7e48946a62036058fc6f0ee7cd71.tar.bz2
Issue #10516: added copy() and clear() methods to bytearrays as well
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 84867bb..a6f1826 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -564,6 +564,39 @@ class ByteArrayTest(BaseBytesTest):
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))