summaryrefslogtreecommitdiff
path: root/tests/basics/bytes_construct.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-12-04 15:46:14 +0000
committerDamien George <damien.p.george@gmail.com>2014-12-04 15:46:14 +0000
commit32ef3a3517caa79f5d2237dbed8078e7fa79c742 (patch)
tree59a132d0ab29a5732a64bad9433967da6ea222c5 /tests/basics/bytes_construct.py
parent3a5352b483bc2ceb0886eca7d9c82f7fce01f679 (diff)
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).
Diffstat (limited to 'tests/basics/bytes_construct.py')
-rw-r--r--tests/basics/bytes_construct.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/basics/bytes_construct.py b/tests/basics/bytes_construct.py
new file mode 100644
index 000000000..1eb6d3e48
--- /dev/null
+++ b/tests/basics/bytes_construct.py
@@ -0,0 +1,14 @@
+# test construction of bytes from different objects
+
+from array import array
+
+# tuple, list, bytearray
+print(bytes((1, 2)))
+print(bytes([1, 2]))
+print(bytes(bytearray(4)))
+
+# arrays
+print(bytes(array('b', [1, 2])))
+print(bytes(array('h', [1, 2])))
+print(bytes(array('I', [1, 2])))
+print(bytes(array('f', [1, 2.3])))