From 32ef3a3517caa79f5d2237dbed8078e7fa79c742 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 4 Dec 2014 15:46:14 +0000 Subject: py: Allow bytes/bytearray/array to be init'd by buffer protocol objects. Behaviour of array initialisation is subtly different for bytes, bytearray and array.array when argument has buffer protocol. This patch gets us CPython conformant (except we allow initialisation of array.array by buffer with length not a multiple of typecode). --- tests/basics/bytearray_construct.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/basics/bytearray_construct.py (limited to 'tests/basics/bytearray_construct.py') diff --git a/tests/basics/bytearray_construct.py b/tests/basics/bytearray_construct.py new file mode 100644 index 000000000..0a7097d55 --- /dev/null +++ b/tests/basics/bytearray_construct.py @@ -0,0 +1,14 @@ +# test construction of bytearray from different objects + +from array import array + +# bytes, tuple, list +print(bytearray(b'123')) +print(bytearray((1, 2))) +print(bytearray([1, 2])) + +# arrays +print(bytearray(array('b', [1, 2]))) +print(bytearray(array('h', [1, 2]))) +print(bytearray(array('I', [1, 2]))) +print(bytearray(array('f', [1, 2.3]))) -- cgit v1.2.3