summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/builtin_hash.py1
-rw-r--r--tests/basics/list1.py6
-rw-r--r--tests/basics/list_mult.py6
-rw-r--r--tests/basics/list_pop.py6
-rw-r--r--tests/basics/slice_bignum.py5
-rw-r--r--tests/basics/special_methods.py146
-rw-r--r--tests/basics/try_finally_loops.py8
-rw-r--r--tests/basics/tuple1.py15
-rw-r--r--tests/basics/tuple_mult.py6
-rw-r--r--tests/cmdline/cmd_optimise.py4
-rw-r--r--tests/cmdline/cmd_optimise.py.exp1
-rw-r--r--tests/extmod/framebuf1.py41
-rw-r--r--tests/extmod/framebuf1.py.exp9
-rw-r--r--tests/extmod/ubinascii_crc32.py20
-rw-r--r--tests/extmod/uzlib_decompio.py32
-rw-r--r--tests/extmod/uzlib_decompio.py.exp12
-rw-r--r--tests/extmod/uzlib_decompress.py (renamed from tests/extmod/zlibd_decompress.py)8
-rw-r--r--tests/extmod/vfs_fat_ramdisk.py13
-rw-r--r--tests/misc/non_compliant.py17
-rw-r--r--tests/misc/non_compliant.py.exp3
-rwxr-xr-xtests/run-tests4
-rw-r--r--tests/unix/extra_coverage.py9
-rw-r--r--tests/unix/extra_coverage.py.exp6
23 files changed, 375 insertions, 3 deletions
diff --git a/tests/basics/builtin_hash.py b/tests/basics/builtin_hash.py
index c9731a3b59..ffea08e575 100644
--- a/tests/basics/builtin_hash.py
+++ b/tests/basics/builtin_hash.py
@@ -3,6 +3,7 @@
print(hash(False))
print(hash(True))
print({():1}) # hash tuple
+print({(1,):1}) # hash non-empty tuple
print({1 << 66:1}) # hash big int
print({-(1 << 66):2}) # hash negative big int
print(hash in {hash:1}) # hash function
diff --git a/tests/basics/list1.py b/tests/basics/list1.py
index c8317baa3d..fa426c0e58 100644
--- a/tests/basics/list1.py
+++ b/tests/basics/list1.py
@@ -22,3 +22,9 @@ print(x)
print(x[1:])
print(x[:-1])
print(x[2:3])
+
+# unsupported type on RHS of add
+try:
+ [] + None
+except TypeError:
+ print('TypeError')
diff --git a/tests/basics/list_mult.py b/tests/basics/list_mult.py
index 16948f74c2..548f88534e 100644
--- a/tests/basics/list_mult.py
+++ b/tests/basics/list_mult.py
@@ -10,3 +10,9 @@ for i in (-4, -2, 0, 2, 4):
a = [1, 2, 3]
c = a * 3
print(a, c)
+
+# unsupported type on RHS
+try:
+ [] * None
+except TypeError:
+ print('TypeError')
diff --git a/tests/basics/list_pop.py b/tests/basics/list_pop.py
index bb2ccc6d67..87ed456f85 100644
--- a/tests/basics/list_pop.py
+++ b/tests/basics/list_pop.py
@@ -9,3 +9,9 @@ except IndexError:
print("IndexError raised")
else:
raise AssertionError("No IndexError raised")
+
+# popping such that list storage shrinks (tests implementation detail of uPy)
+l = list(range(20))
+for i in range(len(l)):
+ l.pop()
+print(l)
diff --git a/tests/basics/slice_bignum.py b/tests/basics/slice_bignum.py
new file mode 100644
index 0000000000..cc820522b0
--- /dev/null
+++ b/tests/basics/slice_bignum.py
@@ -0,0 +1,5 @@
+# test slicing when arguments are bignums
+
+print(list(range(10))[(1<<66)>>65:])
+print(list(range(10))[:(1<<66)>>65])
+print(list(range(10))[::(1<<66)>>65])
diff --git a/tests/basics/special_methods.py b/tests/basics/special_methods.py
new file mode 100644
index 0000000000..1df7a7c4c7
--- /dev/null
+++ b/tests/basics/special_methods.py
@@ -0,0 +1,146 @@
+class Cud():
+
+ def __init__(self):
+ print("__init__ called")
+
+ def __repr__(self):
+ print("__repr__ called")
+ return ""
+
+ def __lt__(self, other):
+ print("__lt__ called")
+
+ def __le__(self, other):
+ print("__le__ called")
+
+ def __eq__(self, other):
+ print("__eq__ called")
+
+ def __ne__(self, other):
+ print("__ne__ called")
+
+ def __ge__(self, other):
+ print("__ge__ called")
+
+ def __gt__(self, other):
+ print("__gt__ called")
+
+ def __abs__(self):
+ print("__abs__ called")
+
+ def __add__(self, other):
+ print("__add__ called")
+
+ def __and__(self, other):
+ print("__and__ called")
+
+ def __floordiv__(self, other):
+ print("__floordiv__ called")
+
+ def __index__(self, other):
+ print("__index__ called")
+
+ def __inv__(self):
+ print("__inv__ called")
+
+ def __invert__(self):
+ print("__invert__ called")
+
+ def __lshift__(self, val):
+ print("__lshift__ called")
+
+ def __mod__(self, val):
+ print("__mod__ called")
+
+ def __mul__(self, other):
+ print("__mul__ called")
+
+ def __matmul__(self, other):
+ print("__matmul__ called")
+
+ def __neg__(self):
+ print("__neg__ called")
+
+ def __or__(self, other):
+ print("__or__ called")
+
+ def __pos__(self):
+ print("__pos__ called")
+
+ def __pow__(self, val):
+ print("__pow__ called")
+
+ def __rshift__(self, val):
+ print("__rshift__ called")
+
+ def __sub__(self, other):
+ print("__sub__ called")
+
+ def __truediv__(self, other):
+ print("__truediv__ called")
+
+ def __div__(self, other):
+ print("__div__ called")
+
+ def __xor__(self, other):
+ print("__xor__ called")
+
+ def __iadd__(self, other):
+ print("__iadd__ called")
+ return self
+
+ def __isub__(self, other):
+ print("__isub__ called")
+ return self
+
+cud1 = Cud()
+cud2 = Cud()
+
+str(cud1)
+cud1 < cud2
+cud1 <= cud2
+cud1 == cud2
+cud1 >= cud2
+cud1 > cud2
+cud1 + cud2
+cud1 - cud2
+
+# the following require MICROPY_PY_ALL_SPECIAL_METHODS
++cud1
+-cud1
+~cud1
+cud1 * cud2
+cud1 / cud2
+cud2 // cud1
+cud1 += cud2
+cud1 -= cud2
+
+# TODO: the following operations are not supported on every ports
+#
+# ne is not supported, !(eq) is called instead
+#cud1 != cud2
+#
+# binary and is not supported
+# cud1 & cud2
+#
+# binary lshift is not supported
+# cud1<<1
+#
+# modulus is not supported
+# cud1 % 2
+#
+# binary or is not supported
+# cud1 | cud2
+#
+# pow is not supported
+# cud1**2
+#
+# rshift is not suported
+# cud1>>1
+#
+# xor is not supported
+# cud1^cud2
+#
+# in the followin test, cpython still calls __eq__
+# cud3=cud1
+# cud3==cud1
diff --git a/tests/basics/try_finally_loops.py b/tests/basics/try_finally_loops.py
index 28a8373dc0..06a6b4a0ce 100644
--- a/tests/basics/try_finally_loops.py
+++ b/tests/basics/try_finally_loops.py
@@ -33,3 +33,11 @@ for i in range(4):
print('here')
finally:
print('finnaly 3')
+
+# break from within try-finally, within for-loop
+for i in [1]:
+ try:
+ print(i)
+ break
+ finally:
+ print('finally 4')
diff --git a/tests/basics/tuple1.py b/tests/basics/tuple1.py
index 53eac2a306..2993391d53 100644
--- a/tests/basics/tuple1.py
+++ b/tests/basics/tuple1.py
@@ -16,3 +16,18 @@ print(x[:-1])
print(x[2:3])
print(x + (10, 100, 10000))
+
+# construction of tuple from large iterator (tests implementation detail of uPy)
+print(tuple(range(20)))
+
+# unsupported unary operation
+try:
+ +()
+except TypeError:
+ print('TypeError')
+
+# unsupported type on RHS of add
+try:
+ () + None
+except TypeError:
+ print('TypeError')
diff --git a/tests/basics/tuple_mult.py b/tests/basics/tuple_mult.py
index 0f52bce44e..b128b29689 100644
--- a/tests/basics/tuple_mult.py
+++ b/tests/basics/tuple_mult.py
@@ -10,3 +10,9 @@ for i in (-4, -2, 0, 2, 4):
a = (1, 2, 3)
c = a * 3
print(a, c)
+
+# unsupported type on RHS
+try:
+ () * None
+except TypeError:
+ print('TypeError')
diff --git a/tests/cmdline/cmd_optimise.py b/tests/cmdline/cmd_optimise.py
new file mode 100644
index 0000000000..79d3bb44fd
--- /dev/null
+++ b/tests/cmdline/cmd_optimise.py
@@ -0,0 +1,4 @@
+# cmdline: -O
+# test optimisation output
+print(__debug__)
+assert 0
diff --git a/tests/cmdline/cmd_optimise.py.exp b/tests/cmdline/cmd_optimise.py.exp
new file mode 100644
index 0000000000..bc59c12aa1
--- /dev/null
+++ b/tests/cmdline/cmd_optimise.py.exp
@@ -0,0 +1 @@
+False
diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py
new file mode 100644
index 0000000000..f550b6b4f4
--- /dev/null
+++ b/tests/extmod/framebuf1.py
@@ -0,0 +1,41 @@
+try:
+ import framebuf
+except ImportError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+w = 5
+h = 16
+buf = bytearray(w * h // 8)
+fbuf = framebuf.FrameBuffer1(buf, w, h, w)
+
+# fill
+fbuf.fill(1)
+print(buf)
+fbuf.fill(0)
+print(buf)
+
+# put pixel
+fbuf.pixel(0, 0, 1)
+fbuf.pixel(4, 0, 1)
+fbuf.pixel(0, 15, 1)
+fbuf.pixel(4, 15, 1)
+print(buf)
+
+# get pixel
+print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
+
+# scroll
+fbuf.fill(0)
+fbuf.pixel(2, 7, 1)
+fbuf.scroll(0, 1)
+print(buf)
+fbuf.scroll(0, -2)
+print(buf)
+fbuf.scroll(1, 0)
+print(buf)
+fbuf.scroll(-1, 0)
+print(buf)
+fbuf.scroll(2, 2)
+print(buf)
diff --git a/tests/extmod/framebuf1.py.exp b/tests/extmod/framebuf1.py.exp
new file mode 100644
index 0000000000..8fd8c37098
--- /dev/null
+++ b/tests/extmod/framebuf1.py.exp
@@ -0,0 +1,9 @@
+bytearray(b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x01\x00\x00\x00\x01\x80\x00\x00\x00\x80')
+1 0
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00')
+bytearray(b'\x00\x00@\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x00\x00\x00@\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x00\x00@\x00\x00\x00\x00\x00\x00\x00')
+bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')
diff --git a/tests/extmod/ubinascii_crc32.py b/tests/extmod/ubinascii_crc32.py
new file mode 100644
index 0000000000..2c40177518
--- /dev/null
+++ b/tests/extmod/ubinascii_crc32.py
@@ -0,0 +1,20 @@
+try:
+ import ubinascii as binascii
+except ImportError:
+ import binascii
+try:
+ binascii.crc32
+except AttributeError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+print(hex(binascii.crc32(b'The quick brown fox jumps over the lazy dog')))
+print(hex(binascii.crc32(b'\x00' * 32)))
+print(hex(binascii.crc32(b'\xff' * 32)))
+print(hex(binascii.crc32(bytes(range(32)))))
+
+print(hex(binascii.crc32(b' over the lazy dog', binascii.crc32(b'The quick brown fox jumps'))))
+print(hex(binascii.crc32(b'\x00' * 16, binascii.crc32(b'\x00' * 16))))
+print(hex(binascii.crc32(b'\xff' * 16, binascii.crc32(b'\xff' * 16))))
+print(hex(binascii.crc32(bytes(range(16, 32)), binascii.crc32(bytes(range(16))))))
diff --git a/tests/extmod/uzlib_decompio.py b/tests/extmod/uzlib_decompio.py
new file mode 100644
index 0000000000..75a6df0ca4
--- /dev/null
+++ b/tests/extmod/uzlib_decompio.py
@@ -0,0 +1,32 @@
+try:
+ import zlib
+except ImportError:
+ import uzlib as zlib
+import uio as io
+
+
+# Raw DEFLATE bitstream
+buf = io.BytesIO(b'\xcbH\xcd\xc9\xc9\x07\x00')
+inp = zlib.DecompIO(buf, -8)
+print(buf.seek(0, 1))
+print(inp.read(1))
+print(buf.seek(0, 1))
+print(inp.read(2))
+print(inp.read())
+print(buf.seek(0, 1))
+print(inp.read(1))
+print(inp.read())
+print(buf.seek(0, 1))
+
+
+# zlib bitstream
+inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc1'))
+print(inp.read(10))
+print(inp.read())
+
+# zlib bitstream, wrong checksum
+inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc0'))
+try:
+ print(inp.read())
+except OSError as e:
+ print(repr(e))
diff --git a/tests/extmod/uzlib_decompio.py.exp b/tests/extmod/uzlib_decompio.py.exp
new file mode 100644
index 0000000000..3f5f360fa3
--- /dev/null
+++ b/tests/extmod/uzlib_decompio.py.exp
@@ -0,0 +1,12 @@
+0
+b'h'
+2
+b'el'
+b'lo'
+7
+b''
+b''
+7
+b'0000000000'
+b'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
+OSError(22,)
diff --git a/tests/extmod/zlibd_decompress.py b/tests/extmod/uzlib_decompress.py
index 4a898f27c7..468335a0d1 100644
--- a/tests/extmod/zlibd_decompress.py
+++ b/tests/extmod/uzlib_decompress.py
@@ -18,11 +18,17 @@ for unpacked, packed in PATTERNS:
# Raw DEFLATE bitstream
-v = b'\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00'
+v = b'\xcbH\xcd\xc9\xc9\x07\x00'
exp = b"hello"
out = zlib.decompress(v, -15)
assert(out == exp)
print(exp)
+# Even when you ask CPython zlib.compress to produce Raw DEFLATE stream,
+# it returns it with adler2 and oriignal size appended, as if it was a
+# zlib stream. Make sure there're no random issues decompressing such.
+v = b'\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00'
+out = zlib.decompress(v, -15)
+assert(out == exp)
# this should error
try:
diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py
index 7860d68124..57c8eeba89 100644
--- a/tests/extmod/vfs_fat_ramdisk.py
+++ b/tests/extmod/vfs_fat_ramdisk.py
@@ -1,5 +1,6 @@
import sys
import uos
+import uerrno
try:
uos.VfsFat
except AttributeError:
@@ -84,3 +85,15 @@ assert vfs.listdir() == ["sub_file.txt"]
vfs.chdir("..")
print("getcwd:", vfs.getcwd())
+
+
+vfs.umount()
+try:
+ vfs.listdir()
+except OSError as e:
+ assert e.args[0] == uerrno.ENODEV
+else:
+ raise AssertionError("expected OSError not thrown")
+
+vfs = uos.VfsFat(bdev, "/ramdisk")
+assert vfs.listdir() == ['foo_dir', 'moved-to-root.txt']
diff --git a/tests/misc/non_compliant.py b/tests/misc/non_compliant.py
index c760c2accd..ba2dd15c6a 100644
--- a/tests/misc/non_compliant.py
+++ b/tests/misc/non_compliant.py
@@ -70,3 +70,20 @@ try:
except NotImplementedError:
print('NotImplementedError')
+# tuple load with step!=1 not implemented
+try:
+ ()[2:3:4]
+except NotImplementedError:
+ print('NotImplementedError')
+
+# list store with step!=1 not implemented
+try:
+ [][2:3:4] = []
+except NotImplementedError:
+ print('NotImplementedError')
+
+# list delete with step!=1 not implemented
+try:
+ del [][2:3:4]
+except NotImplementedError:
+ print('NotImplementedError')
diff --git a/tests/misc/non_compliant.py.exp b/tests/misc/non_compliant.py.exp
index 28b1470d7c..5937ccb2fb 100644
--- a/tests/misc/non_compliant.py.exp
+++ b/tests/misc/non_compliant.py.exp
@@ -9,3 +9,6 @@ NotImplementedError
NotImplementedError
NotImplementedError
NotImplementedError
+NotImplementedError
+NotImplementedError
+NotImplementedError
diff --git a/tests/run-tests b/tests/run-tests
index 32d334a008..059e4e910f 100755
--- a/tests/run-tests
+++ b/tests/run-tests
@@ -200,6 +200,10 @@ def run_tests(pyb, tests, args):
# Some tests shouldn't be run under Travis CI
if os.getenv('TRAVIS') == 'true':
skip_tests.add('basics/memoryerror.py')
+ skip_tests.add('thread/thread_gc1.py') # has reliability issues
+ skip_tests.add('thread/thread_lock4.py') # has reliability issues
+ skip_tests.add('thread/stress_heap.py') # has reliability issues
+ skip_tests.add('thread/stress_recurse.py') # has reliability issues
if not has_complex:
skip_tests.add('float/complex1.py')
diff --git a/tests/unix/extra_coverage.py b/tests/unix/extra_coverage.py
index 8f330f1da2..72bcc9994a 100644
--- a/tests/unix/extra_coverage.py
+++ b/tests/unix/extra_coverage.py
@@ -5,4 +5,11 @@ except NameError:
import sys
sys.exit()
-extra_coverage()
+data = extra_coverage()
+
+# test hashing of str/bytes that have an invalid hash
+print(data)
+print(hash(data[0]))
+print(hash(data[1]))
+print(hash(bytes(data[0], 'utf8')))
+print(hash(str(data[1], 'utf8')))
diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp
index db282b152c..ea73a54e4c 100644
--- a/tests/unix/extra_coverage.py.exp
+++ b/tests/unix/extra_coverage.py.exp
@@ -7,7 +7,6 @@ ab abc
false true
(null)
-t
-2147483648
2147483648
80000000
@@ -36,3 +35,8 @@ ementation
12345678
0
0
+('0123456789', b'0123456789')
+7300
+7300
+7300
+7300