summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorScott Shawcroft <scott@chickadee.tech>2016-10-10 11:42:59 -0700
committerScott Shawcroft <scott@chickadee.tech>2016-10-10 11:42:59 -0700
commita52fd670e66e72dc60d460016a2f1f03a65dbeb6 (patch)
tree3b5af151ff68fcbf772e5348efd43d770445508c /tests
parenta6254f4344be4f54232149adb5d834ab9561846c (diff)
parent89bfbfdeee2c86a18ccab6dce41bbd3e4597c981 (diff)
Merge remote-tracking branch 'micropython/master'
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/async_with.py12
-rw-r--r--tests/basics/async_with.py.exp5
-rw-r--r--tests/basics/async_with2.py2
-rw-r--r--tests/basics/async_with2.py.exp2
-rw-r--r--tests/basics/errno1.py3
-rw-r--r--tests/basics/errno1.py.exp1
-rw-r--r--tests/basics/frozenset_add.py5
-rw-r--r--tests/basics/scope.py22
-rw-r--r--tests/basics/set1.py4
-rw-r--r--tests/basics/set_difference.py3
-rw-r--r--tests/basics/struct1.py12
-rw-r--r--tests/basics/try_finally2.py30
-rw-r--r--tests/cmdline/cmd_showbc.py.exp5
-rw-r--r--tests/extmod/btree1.py20
-rw-r--r--tests/extmod/btree1.py.exp6
-rw-r--r--tests/extmod/uzlib_decompress.py2
-rw-r--r--tests/extmod/vfs_fat_ramdisk.py1
-rw-r--r--tests/extmod/vfs_fat_ramdisk.py.exp1
-rw-r--r--tests/float/float1.py4
-rw-r--r--tests/import/import_pkg1.py5
-rw-r--r--tests/io/bytesio_ext.py5
-rw-r--r--tests/io/write_ext.py2
-rw-r--r--tests/micropython/const.py2
-rw-r--r--tests/micropython/const2.py34
-rw-r--r--tests/micropython/const2.py.exp4
-rw-r--r--tests/micropython/const_error.py2
-rw-r--r--tests/misc/non_compliant.py7
-rw-r--r--tests/misc/non_compliant.py.exp2
28 files changed, 183 insertions, 20 deletions
diff --git a/tests/basics/async_with.py b/tests/basics/async_with.py
index 742f9ba99..9eccfd816 100644
--- a/tests/basics/async_with.py
+++ b/tests/basics/async_with.py
@@ -4,7 +4,7 @@ class AContext:
async def __aenter__(self):
print('enter')
async def __aexit__(self, exc_type, exc, tb):
- print('exit')
+ print('exit', exc_type, exc)
async def f():
async with AContext():
@@ -15,3 +15,13 @@ try:
o.send(None)
except StopIteration:
print('finished')
+
+async def g():
+ async with AContext():
+ raise ValueError('error')
+
+o = g()
+try:
+ o.send(None)
+except ValueError:
+ print('ValueError')
diff --git a/tests/basics/async_with.py.exp b/tests/basics/async_with.py.exp
index 1e9176af7..6072a3e0b 100644
--- a/tests/basics/async_with.py.exp
+++ b/tests/basics/async_with.py.exp
@@ -1,4 +1,7 @@
enter
body
-exit
+exit None None
finished
+enter
+exit <class 'ValueError'> error
+ValueError
diff --git a/tests/basics/async_with2.py b/tests/basics/async_with2.py
index 0ebec489f..44421ae91 100644
--- a/tests/basics/async_with2.py
+++ b/tests/basics/async_with2.py
@@ -20,7 +20,7 @@ class AContext:
print('enter')
print('f returned:', await f(10))
async def __aexit__(self, exc_type, exc, tb):
- print('exit')
+ print('exit', exc_type, exc)
print('f returned:', await f(20))
async def coro():
diff --git a/tests/basics/async_with2.py.exp b/tests/basics/async_with2.py.exp
index dd5a1c549..76b173b4c 100644
--- a/tests/basics/async_with2.py.exp
+++ b/tests/basics/async_with2.py.exp
@@ -9,7 +9,7 @@ coro yielded: 31
coro yielded: 32
body f returned: 33
body end
-exit
+exit None None
f start: 20
coro yielded: 21
coro yielded: 22
diff --git a/tests/basics/errno1.py b/tests/basics/errno1.py
index 680104481..eae1bbe1b 100644
--- a/tests/basics/errno1.py
+++ b/tests/basics/errno1.py
@@ -13,3 +13,6 @@ print(type(uerrno.EIO))
# check that errors are rendered in a nice way
msg = str(OSError(uerrno.EIO))
print(msg[:7], msg[-5:])
+
+# check that unknown errno is still rendered
+print(str(OSError(9999)))
diff --git a/tests/basics/errno1.py.exp b/tests/basics/errno1.py.exp
index e60fdf049..c3703df4a 100644
--- a/tests/basics/errno1.py.exp
+++ b/tests/basics/errno1.py.exp
@@ -1,2 +1,3 @@
<class 'int'>
[Errno ] EIO
+9999
diff --git a/tests/basics/frozenset_add.py b/tests/basics/frozenset_add.py
index 50615775b..415a8c2e1 100644
--- a/tests/basics/frozenset_add.py
+++ b/tests/basics/frozenset_add.py
@@ -10,3 +10,8 @@ try:
print(s.add(5))
except AttributeError:
print("AttributeError")
+
+try:
+ print(s.update([5]))
+except AttributeError:
+ print("AttributeError")
diff --git a/tests/basics/scope.py b/tests/basics/scope.py
index 3aecc0b8d..11704c482 100644
--- a/tests/basics/scope.py
+++ b/tests/basics/scope.py
@@ -19,3 +19,25 @@ def f():
g()
return a
print(f())
+
+# nonlocal at inner-inner level (h)
+def f():
+ x = 1
+ def g():
+ def h():
+ nonlocal x
+ return x
+ return h
+ return g
+print(f()()())
+
+# nonlocal declared at outer level (g), and referenced by inner level (h)
+def f():
+ x = 1
+ def g():
+ nonlocal x
+ def h():
+ return x
+ return h
+ return g
+print(f()()())
diff --git a/tests/basics/set1.py b/tests/basics/set1.py
index 6afd9eb5e..6ea69e4f0 100644
--- a/tests/basics/set1.py
+++ b/tests/basics/set1.py
@@ -6,6 +6,10 @@ print(s)
s = {3, 4, 3, 1}
print(sorted(s))
+# expression in constructor
+s = {1 + len(s)}
+print(s)
+
# Sets are not hashable
try:
{s: 1}
diff --git a/tests/basics/set_difference.py b/tests/basics/set_difference.py
index abfcbe7d6..97b63a815 100644
--- a/tests/basics/set_difference.py
+++ b/tests/basics/set_difference.py
@@ -14,3 +14,6 @@ print(s.difference_update({1}))
print(sorted(s))
print(s.difference_update({1}, [2]))
print(sorted(s))
+
+s.difference_update(s)
+print(s)
diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py
index 1abe34b4c..b53a9c8bc 100644
--- a/tests/basics/struct1.py
+++ b/tests/basics/struct1.py
@@ -103,15 +103,3 @@ try:
print(struct.unpack_from('<b', buf, -11))
except:
print('struct.error')
-
-# pack with too many args, not checked by uPy
-#try:
-# print(struct.pack('ii', 1, 2, 3))
-#except:
-# print('struct.error')
-
-# pack with too few args, not checked by uPy
-#try:
-# print(struct.pack('ii', 1))
-#except:
-# print('struct.error')
diff --git a/tests/basics/try_finally2.py b/tests/basics/try_finally2.py
new file mode 100644
index 000000000..3c4171d91
--- /dev/null
+++ b/tests/basics/try_finally2.py
@@ -0,0 +1,30 @@
+# check that the Python stack does not overflow when the finally
+# block itself uses more stack than the rest of the function
+def f1(a, b):
+ pass
+def test1():
+ val = 1
+ try:
+ raise ValueError()
+ finally:
+ f1(2, 2) # use some stack
+ print(val) # check that the local variable is the same
+try:
+ test1()
+except ValueError:
+ pass
+
+# same as above but with 3 args instead of 2, to use an extra stack entry
+def f2(a, b, c):
+ pass
+def test2():
+ val = 1
+ try:
+ raise ValueError()
+ finally:
+ f2(2, 2, 2) # use some stack
+ print(val) # check that the local variable is the same
+try:
+ test2()
+except ValueError:
+ pass
diff --git a/tests/cmdline/cmd_showbc.py.exp b/tests/cmdline/cmd_showbc.py.exp
index 7d2eaeb85..0e5c55942 100644
--- a/tests/cmdline/cmd_showbc.py.exp
+++ b/tests/cmdline/cmd_showbc.py.exp
@@ -27,8 +27,7 @@ arg names:
File cmdline/cmd_showbc.py, code block 'f' (descriptor: \.\+, bytecode @\.\+ bytes)
Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
########
-\.\+5b
-arg names:
+\.\+rg names:
(N_STATE 22)
(N_EXC_STACK 2)
(INIT_CELL 14)
@@ -242,8 +241,6 @@ arg names:
\\d\+ POP_BLOCK
\\d\+ JUMP \\d\+
\\d\+ POP_TOP
-\\d\+ POP_TOP
-\\d\+ POP_TOP
\\d\+ LOAD_DEREF 14
\\d\+ POP_TOP
\\d\+ POP_EXCEPT
diff --git a/tests/extmod/btree1.py b/tests/extmod/btree1.py
index c96cce92d..662983766 100644
--- a/tests/extmod/btree1.py
+++ b/tests/extmod/btree1.py
@@ -1,6 +1,7 @@
try:
import btree
import uio
+ import uerrno
except ImportError:
print("SKIP")
import sys
@@ -15,6 +16,9 @@ db[b"foo1"] = b"bar1"
db[b"foo2"] = b"bar2"
db[b"bar1"] = b"foo1"
+dbstr = str(db)
+print(dbstr[:7], dbstr[-1:])
+
print(db[b"foo2"])
try:
print(db[b"foo"])
@@ -56,14 +60,30 @@ print("---")
for k, v in db.items(None, None, btree.DESC):
print((k, v))
+print(db.seq(1, b"foo1"))
+print(db.seq(1, b"qux"))
+
+try:
+ db.seq(b"foo1")
+except OSError as e:
+ print(e.args[0] == uerrno.EINVAL)
+
print(list(db.keys()))
print(list(db.values()))
for k in db:
print(k)
+db.put(b"baz1", b"qux1")
+
print("foo1", "foo1" in db)
print("foo2", "foo2" in db)
+print("baz1", "baz1" in db)
+
+try:
+ print(db + db[b"foo1"])
+except TypeError:
+ print("TypeError")
db.close()
f.close()
diff --git a/tests/extmod/btree1.py.exp b/tests/extmod/btree1.py.exp
index 2983a0987..a46725230 100644
--- a/tests/extmod/btree1.py.exp
+++ b/tests/extmod/btree1.py.exp
@@ -1,3 +1,4 @@
+<btree >
b'bar2'
KeyError
None
@@ -25,6 +26,9 @@ KeyError
(b'foo3', b'bar3')
(b'foo1', b'bar1')
(b'bar1', b'foo1')
+(b'foo1', b'bar1')
+None
+True
[b'bar1', b'foo1', b'foo3']
[b'foo1', b'bar1', b'bar3']
b'bar1'
@@ -32,3 +36,5 @@ b'foo1'
b'foo3'
foo1 True
foo2 False
+baz1 True
+TypeError
diff --git a/tests/extmod/uzlib_decompress.py b/tests/extmod/uzlib_decompress.py
index 468335a0d..6892808cb 100644
--- a/tests/extmod/uzlib_decompress.py
+++ b/tests/extmod/uzlib_decompress.py
@@ -10,6 +10,8 @@ PATTERNS = [
(b'0' * 100, b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc1'),
(bytes(range(64)), b'x\x9cc`dbfaec\xe7\xe0\xe4\xe2\xe6\xe1\xe5\xe3\x17\x10\x14\x12\x16\x11\x15\x13\x97\x90\x94\x92\x96\x91\x95\x93WPTRVQUS\xd7\xd0\xd4\xd2\xd6\xd1\xd5\xd370426153\xb7\xb0\xb4\xb2\xb6\xb1\xb5\xb3\x07\x00\xaa\xe0\x07\xe1'),
(b'hello', b'x\x01\x01\x05\x00\xfa\xffhello\x06,\x02\x15'), # compression level 0
+ # adaptive/dynamic huffman tree
+ (b'13371813150|13764518736|12345678901', b'x\x9c\x05\xc1\x81\x01\x000\x04\x04\xb1\x95\\\x1f\xcfn\x86o\x82d\x06Qq\xc8\x9d\xc5X}<e\xb5g\x83\x0f\x89X\x07\xab')
]
for unpacked, packed in PATTERNS:
diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py
index 57c8eeba8..f470dbcfe 100644
--- a/tests/extmod/vfs_fat_ramdisk.py
+++ b/tests/extmod/vfs_fat_ramdisk.py
@@ -45,6 +45,7 @@ assert b"FOO_FILETXT" not in bdev.data
assert b"hello!" not in bdev.data
vfs = uos.VfsFat(bdev, "/ramdisk")
+print("statvfs:", vfs.statvfs("/ramdisk"))
print("getcwd:", vfs.getcwd())
diff --git a/tests/extmod/vfs_fat_ramdisk.py.exp b/tests/extmod/vfs_fat_ramdisk.py.exp
index b6079ad3b..fd893b6e4 100644
--- a/tests/extmod/vfs_fat_ramdisk.py.exp
+++ b/tests/extmod/vfs_fat_ramdisk.py.exp
@@ -1,3 +1,4 @@
+statvfs: (512, 512, 14, 14, 14, 0, 0, 0, 0, 255)
getcwd: /ramdisk
hello!
getcwd: /ramdisk/foo_dir
diff --git a/tests/float/float1.py b/tests/float/float1.py
index 27fe26205..f21f5bcdd 100644
--- a/tests/float/float1.py
+++ b/tests/float/float1.py
@@ -23,6 +23,10 @@ print(float("INFINITY"))
print(float("nan"))
print(float("NaN"))
try:
+ float("")
+except ValueError:
+ print("ValueError")
+try:
float("1e+")
except ValueError:
print("ValueError")
diff --git a/tests/import/import_pkg1.py b/tests/import/import_pkg1.py
index 8cd77af79..fe6e4473e 100644
--- a/tests/import/import_pkg1.py
+++ b/tests/import/import_pkg1.py
@@ -9,3 +9,8 @@ pkg_ = __import__("pkg.mod")
print(pkg_ is not pkg.mod)
print(pkg_ is pkg)
print(pkg_.mod is pkg.mod)
+
+# import using "as"
+import pkg.mod as mm
+print(mm is pkg.mod)
+print(mm.foo())
diff --git a/tests/io/bytesio_ext.py b/tests/io/bytesio_ext.py
index 30d79fcfc..e827d1409 100644
--- a/tests/io/bytesio_ext.py
+++ b/tests/io/bytesio_ext.py
@@ -17,3 +17,8 @@ print(a.getvalue())
a.flush()
print(a.getvalue())
+
+a.seek(0)
+arr = bytearray(10)
+print(a.readinto(arr))
+print(arr)
diff --git a/tests/io/write_ext.py b/tests/io/write_ext.py
index f4ed0d368..19b616174 100644
--- a/tests/io/write_ext.py
+++ b/tests/io/write_ext.py
@@ -1,3 +1,5 @@
+# This tests extended (MicroPython-specific) form of write:
+# write(buf, len) and write(buf, offset, len)
import uio
try:
diff --git a/tests/micropython/const.py b/tests/micropython/const.py
index 09717fd14..660a095f2 100644
--- a/tests/micropython/const.py
+++ b/tests/micropython/const.py
@@ -1,5 +1,7 @@
# test constant optimisation
+from micropython import const
+
X = const(123)
Y = const(X + 456)
diff --git a/tests/micropython/const2.py b/tests/micropython/const2.py
new file mode 100644
index 000000000..60085a1e0
--- /dev/null
+++ b/tests/micropython/const2.py
@@ -0,0 +1,34 @@
+# check that consts are not replaced in anything except standalone identifiers
+
+from micropython import const
+
+X = const(1)
+Y = const(2)
+Z = const(3)
+
+# import that uses a constant
+import micropython as X
+print(globals()['X'])
+
+# function name that matches a constant
+def X():
+ print('function X', X)
+globals()['X']()
+
+# arguments that match a constant
+def f(X, *Y, **Z):
+ pass
+f(1)
+
+# class name that matches a constant
+class X:
+ def f(self):
+ print('class X', X)
+globals()['X']().f()
+
+# constant within a class
+class A:
+ C1 = const(4)
+ def X(self):
+ print('method X', Y, C1, self.C1)
+A().X()
diff --git a/tests/micropython/const2.py.exp b/tests/micropython/const2.py.exp
new file mode 100644
index 000000000..0568f91ce
--- /dev/null
+++ b/tests/micropython/const2.py.exp
@@ -0,0 +1,4 @@
+<module 'micropython'>
+function X 1
+class X 1
+method X 2 4 4
diff --git a/tests/micropython/const_error.py b/tests/micropython/const_error.py
index b46efcae2..6d3d135b5 100644
--- a/tests/micropython/const_error.py
+++ b/tests/micropython/const_error.py
@@ -1,5 +1,7 @@
# make sure syntax error works correctly for bad const definition
+from micropython import const
+
def test_syntax(code):
try:
exec(code)
diff --git a/tests/misc/non_compliant.py b/tests/misc/non_compliant.py
index ba2dd15c6..1157ff8b2 100644
--- a/tests/misc/non_compliant.py
+++ b/tests/misc/non_compliant.py
@@ -1,6 +1,7 @@
# tests for things that are not implemented, or have non-compliant behaviour
import array
+import ustruct
# array deletion not implemented
try:
@@ -87,3 +88,9 @@ try:
del [][2:3:4]
except NotImplementedError:
print('NotImplementedError')
+
+# struct pack with too many args, not checked by uPy
+print(ustruct.pack('bb', 1, 2, 3))
+
+# struct pack with too few args, not checked by uPy
+print(ustruct.pack('bb', 1))
diff --git a/tests/misc/non_compliant.py.exp b/tests/misc/non_compliant.py.exp
index 5937ccb2f..c03580442 100644
--- a/tests/misc/non_compliant.py.exp
+++ b/tests/misc/non_compliant.py.exp
@@ -12,3 +12,5 @@ NotImplementedError
NotImplementedError
NotImplementedError
NotImplementedError
+b'\x01\x02'
+b'\x01\x00'