summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavePutz <dwputz@gmail.com>2020-09-14 16:50:40 -0500
committerGitHub <noreply@github.com>2020-09-14 16:50:40 -0500
commit2a2a8d64571bf93e2a166626841555fe1753a565 (patch)
treea4b7ba795a6e17d4d0b32abd942af380b1c36e57 /tests
parent4a3be4df91837a1c71fcbd62e041f7c45cd4dd4b (diff)
parent3d8bac50e41acc286cefbde9e052c5ccb335101e (diff)
Merge pull request #28 from adafruit/main
Merge from adafruit/main
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/bit_length.py4
-rw-r--r--tests/basics/builtin_help.py.exp4
-rw-r--r--tests/basics/struct1.py25
-rw-r--r--tests/basics/struct_micropython.py41
-rw-r--r--tests/basics/struct_micropython.py.exp2
-rw-r--r--tests/cmdline/repl_autocomplete.py.exp2
-rw-r--r--tests/misc/non_compliant.py6
-rw-r--r--tests/misc/non_compliant.py.exp2
8 files changed, 32 insertions, 54 deletions
diff --git a/tests/basics/bit_length.py b/tests/basics/bit_length.py
new file mode 100644
index 000000000..5eb33f604
--- /dev/null
+++ b/tests/basics/bit_length.py
@@ -0,0 +1,4 @@
+for i in range(129):
+ j = (1 << i)
+ print(i, (j-1).bit_length(), (j).bit_length(), (j+1).bit_length())
+ print(i, (-j-1).bit_length(), (-j).bit_length(), (-j+1).bit_length())
diff --git a/tests/basics/builtin_help.py.exp b/tests/basics/builtin_help.py.exp
index ed8a7d74b..89350a6c7 100644
--- a/tests/basics/builtin_help.py.exp
+++ b/tests/basics/builtin_help.py.exp
@@ -1,14 +1,14 @@
########
object <function> is of type function
object <class 'int'> is of type type
+ bit_length -- <function>
from_bytes -- <classmethod>
to_bytes -- <function>
object 1 is of type int
+ bit_length -- <function>
from_bytes -- <classmethod>
to_bytes -- <function>
object <module 'micropython'> is of type module
__name__ -- micropython
- const -- <function>
- opt_level -- <function>
########
done
diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py
index db34342a1..107006cc3 100644
--- a/tests/basics/struct1.py
+++ b/tests/basics/struct1.py
@@ -39,6 +39,28 @@ print(v == (10, 100, 200, 300))
# network byte order
print(struct.pack('!i', 123))
+# too short / too long arguments
+buf = bytearray(b'>>>123<<<')
+try:
+ struct.pack_into('bb', buf, 0, 3)
+except:
+ print('struct.error')
+
+try:
+ struct.pack_into('bb', buf, 0, 3, 1, 4)
+except:
+ print('struct.error')
+
+try:
+ struct.pack('bb', 3)
+except:
+ print('struct.error')
+
+try:
+ struct.pack('bb', 3, 1, 4)
+except:
+ print('struct.error')
+
# check that we get an error if the buffer is too small
try:
struct.unpack('I', b'\x00\x00\x00')
@@ -96,3 +118,6 @@ try:
print(struct.unpack_from('<b', buf, -11))
except:
print('struct.error')
+
+# check padding bytes
+print(struct.pack("xb", 3))
diff --git a/tests/basics/struct_micropython.py b/tests/basics/struct_micropython.py
deleted file mode 100644
index e72153071..000000000
--- a/tests/basics/struct_micropython.py
+++ /dev/null
@@ -1,41 +0,0 @@
-# test MicroPython-specific features of struct
-
-try:
- import ustruct as struct
-except:
- try:
- import struct
- except ImportError:
- print("SKIP")
- raise SystemExit
-
-try:
- struct.pack('O', None)
-except ValueError:
- print("SKIP")
- raise SystemExit
-
-class A():
- pass
-
-# pack and unpack objects
-o = A()
-s = struct.pack("<O", o)
-o2 = struct.unpack("<O", s)
-print(o is o2[0])
-
-# pack can accept less arguments than required for the format spec
-print(struct.pack('<2I', 1))
-
-# pack and unpack pointer to a string
-# This requires uctypes to get the address of the string and instead of
-# putting this in a dedicated test that can be skipped we simply pass
-# if the import fails.
-try:
- import uctypes
- o = uctypes.addressof('abc')
- s = struct.pack("<S", o)
- o2 = struct.unpack("<S", s)
- assert o2[0] == 'abc'
-except ImportError:
- pass
diff --git a/tests/basics/struct_micropython.py.exp b/tests/basics/struct_micropython.py.exp
deleted file mode 100644
index 55b7b6623..000000000
--- a/tests/basics/struct_micropython.py.exp
+++ /dev/null
@@ -1,2 +0,0 @@
-True
-b'\x01\x00\x00\x00\x00\x00\x00\x00'
diff --git a/tests/cmdline/repl_autocomplete.py.exp b/tests/cmdline/repl_autocomplete.py.exp
index 7d160e7bf..0dabc9014 100644
--- a/tests/cmdline/repl_autocomplete.py.exp
+++ b/tests/cmdline/repl_autocomplete.py.exp
@@ -12,7 +12,7 @@ Use \.\+
'abc'
>>> x = 5
>>> x.
-from_bytes to_bytes
+bit_length from_bytes to_bytes
>>> x.
>>> x.__class__
<class 'int'>
diff --git a/tests/misc/non_compliant.py b/tests/misc/non_compliant.py
index 99633416a..9a746a8b0 100644
--- a/tests/misc/non_compliant.py
+++ b/tests/misc/non_compliant.py
@@ -105,12 +105,6 @@ try:
except NotImplementedError:
print('NotImplementedError')
-# struct pack with too many args, not checked by uPy
-print(struct.pack('bb', 1, 2, 3))
-
-# struct pack with too few args, not checked by uPy
-print(struct.pack('bb', 1))
-
# array slice assignment with unsupported RHS
try:
bytearray(4)[0:1] = [1, 2]
diff --git a/tests/misc/non_compliant.py.exp b/tests/misc/non_compliant.py.exp
index 3f15a1440..8518828ec 100644
--- a/tests/misc/non_compliant.py.exp
+++ b/tests/misc/non_compliant.py.exp
@@ -14,8 +14,6 @@ NotImplementedError
NotImplementedError
NotImplementedError
NotImplementedError
-b'\x01\x02'
-b'\x01\x00'
NotImplementedError
AttributeError
TypeError