summaryrefslogtreecommitdiff
path: root/tests/basics/struct2.py
diff options
context:
space:
mode:
authorGlenn Ruben Bakke <glennbakke@gmail.com>2017-10-04 21:45:04 +0200
committerGlenn Ruben Bakke <glennbakke@gmail.com>2017-10-04 21:45:04 +0200
commitbcab2ba0a80297100919366add6bada140c6ed75 (patch)
tree5133218f4fc010d5688f006dbdd1e2f346a843f7 /tests/basics/struct2.py
parent4468731e3d039a3f72ac25aa43e936cf5ebb3f78 (diff)
parentf869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c (diff)
ports/nrf: Upmerging port with upstream master
Diffstat (limited to 'tests/basics/struct2.py')
-rw-r--r--tests/basics/struct2.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/basics/struct2.py b/tests/basics/struct2.py
index d8234d0d3..ceb067776 100644
--- a/tests/basics/struct2.py
+++ b/tests/basics/struct2.py
@@ -25,6 +25,16 @@ print(struct.calcsize('0s1s0H2H'))
print(struct.unpack('<0s1s0H2H', b'01234'))
print(struct.pack('<0s1s0H2H', b'abc', b'abc', 258, 515))
+# check that we get an error if the buffer is too small
+try:
+ struct.unpack('2H', b'\x00\x00')
+except:
+ print('Exception')
+try:
+ struct.pack_into('2I', bytearray(4), 0, 0)
+except:
+ print('Exception')
+
# check that unknown types raise an exception
try:
struct.unpack('z', b'1')
@@ -40,3 +50,30 @@ try:
struct.calcsize('0z')
except:
print('Exception')
+
+# check that a count without a type specifier raises an exception
+
+try:
+ struct.calcsize('1')
+except:
+ print('Exception')
+
+try:
+ struct.pack('1')
+except:
+ print('Exception')
+
+try:
+ struct.pack_into('1', bytearray(4), 0, 'xx')
+except:
+ print('Exception')
+
+try:
+ struct.unpack('1', 'xx')
+except:
+ print('Exception')
+
+try:
+ struct.unpack_from('1', 'xx')
+except:
+ print('Exception')