diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basics/array_construct.py | 18 | ||||
-rw-r--r-- | tests/basics/bytearray_construct.py | 14 | ||||
-rw-r--r-- | tests/basics/bytes_construct.py | 14 |
3 files changed, 46 insertions, 0 deletions
diff --git a/tests/basics/array_construct.py b/tests/basics/array_construct.py new file mode 100644 index 0000000000..e050f3003b --- /dev/null +++ b/tests/basics/array_construct.py @@ -0,0 +1,18 @@ +# test construction of array.array from different objects + +from array import array + +# tuple, list +print(array('b', (1, 2))) +print(array('h', [1, 2])) + +# raw copy from bytes, bytearray +print(array('h', b'12')) +print(array('h', bytearray(2))) +print(array('i', bytearray(4))) + +# convert from other arrays +print(array('H', array('b', [1, 2]))) +print(array('f', array('h', [1, 2]))) +print(array('b', array('I', [1, 2]))) +print(array('d', array('f', [1, 2]))) diff --git a/tests/basics/bytearray_construct.py b/tests/basics/bytearray_construct.py new file mode 100644 index 0000000000..0a7097d55a --- /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]))) diff --git a/tests/basics/bytes_construct.py b/tests/basics/bytes_construct.py new file mode 100644 index 0000000000..1eb6d3e485 --- /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]))) |