summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics
diff options
context:
space:
mode:
Diffstat (limited to 'tests/basics')
-rw-r--r--tests/basics/array1.py10
-rw-r--r--tests/basics/async_def.py16
-rw-r--r--tests/basics/async_def.py.exp3
-rw-r--r--tests/basics/async_with.py14
-rw-r--r--tests/basics/async_with.py.exp6
-rw-r--r--tests/basics/async_with2.py2
-rw-r--r--tests/basics/async_with2.py.exp2
-rw-r--r--tests/basics/builtin_range.py6
-rw-r--r--tests/basics/del_global.py5
-rw-r--r--tests/basics/dict1.py24
-rw-r--r--tests/basics/dict_views.py15
-rw-r--r--tests/basics/errno1.py18
-rw-r--r--tests/basics/errno1.py.exp3
-rw-r--r--tests/basics/for_range.py5
-rw-r--r--tests/basics/frozenset_add.py5
-rw-r--r--tests/basics/int_constfolding.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/slice_attrs.py9
-rw-r--r--tests/basics/struct1.py14
-rw-r--r--tests/basics/syntaxerror.py4
-rw-r--r--tests/basics/try_finally2.py30
-rw-r--r--tests/basics/unpack1.py1
24 files changed, 210 insertions, 16 deletions
diff --git a/tests/basics/array1.py b/tests/basics/array1.py
index bce22cc57d..c45b883c94 100644
--- a/tests/basics/array1.py
+++ b/tests/basics/array1.py
@@ -6,6 +6,12 @@ i = array.array('I', [1, 2, 3])
print(i, len(i))
print(a[0])
print(i[-1])
+a = array.array('l', [-1])
+print(len(a), a[0])
+a1 = array.array('l', [1, 2, 3])
+a2 = array.array('L', [1, 2, 3])
+print(a2[1])
+print(a1 == a2)
# Empty arrays
print(len(array.array('h')))
@@ -15,6 +21,10 @@ print(array.array('i'))
print(bool(array.array('i')))
print(bool(array.array('i', [1])))
+# containment, with incorrect type
+print('12' in array.array('B', b'12'))
+print([] in array.array('B', b'12'))
+
# bad typecode
try:
array.array('X')
diff --git a/tests/basics/async_def.py b/tests/basics/async_def.py
new file mode 100644
index 0000000000..e345703d74
--- /dev/null
+++ b/tests/basics/async_def.py
@@ -0,0 +1,16 @@
+# test async def
+
+def dec(f):
+ print('decorator')
+ return f
+
+# test definition with a decorator
+@dec
+async def foo():
+ print('foo')
+
+coro = foo()
+try:
+ coro.send(None)
+except StopIteration:
+ print('StopIteration')
diff --git a/tests/basics/async_def.py.exp b/tests/basics/async_def.py.exp
new file mode 100644
index 0000000000..f555ace99a
--- /dev/null
+++ b/tests/basics/async_def.py.exp
@@ -0,0 +1,3 @@
+decorator
+foo
+StopIteration
diff --git a/tests/basics/async_with.py b/tests/basics/async_with.py
index 742f9ba993..5af0c5d955 100644
--- a/tests/basics/async_with.py
+++ b/tests/basics/async_with.py
@@ -3,8 +3,9 @@
class AContext:
async def __aenter__(self):
print('enter')
+ return 1
async def __aexit__(self, exc_type, exc, tb):
- print('exit')
+ print('exit', exc_type, exc)
async def f():
async with AContext():
@@ -15,3 +16,14 @@ try:
o.send(None)
except StopIteration:
print('finished')
+
+async def g():
+ async with AContext() as ac:
+ print(ac)
+ 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 1e9176af7b..d00b18c969 100644
--- a/tests/basics/async_with.py.exp
+++ b/tests/basics/async_with.py.exp
@@ -1,4 +1,8 @@
enter
body
-exit
+exit None None
finished
+enter
+1
+exit <class 'ValueError'> error
+ValueError
diff --git a/tests/basics/async_with2.py b/tests/basics/async_with2.py
index 0ebec489fe..44421ae917 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 dd5a1c549a..76b173b4c2 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/builtin_range.py b/tests/basics/builtin_range.py
index 9110cf12cd..59fc0344a4 100644
--- a/tests/basics/builtin_range.py
+++ b/tests/basics/builtin_range.py
@@ -50,3 +50,9 @@ try:
range(1)[0] = 1
except TypeError:
print("TypeError")
+
+# bad attr (can't store)
+try:
+ range(4).start = 0
+except AttributeError:
+ print('AttributeError')
diff --git a/tests/basics/del_global.py b/tests/basics/del_global.py
index 77d11cb3c4..d740357b03 100644
--- a/tests/basics/del_global.py
+++ b/tests/basics/del_global.py
@@ -54,3 +54,8 @@ try:
print(c)
except NameError:
print("NameError")
+
+a = 1
+b = 2
+c = 3
+del (a, (b, c))
diff --git a/tests/basics/dict1.py b/tests/basics/dict1.py
index c70ca588a7..20fa9def31 100644
--- a/tests/basics/dict1.py
+++ b/tests/basics/dict1.py
@@ -16,3 +16,27 @@ while x < 100:
d[x] = x
x += 1
print(d[50])
+
+# equality operator on dicts of different size
+print({} == {1:1})
+
+# equality operator on dicts of same size but with different keys
+print({1:1} == {2:1})
+
+# value not found
+try:
+ {}[0]
+except KeyError as er:
+ print('KeyError', er, repr(er), er.args)
+
+# unsupported unary op
+try:
+ +{}
+except TypeError:
+ print('TypeError')
+
+# unsupported binary op
+try:
+ {} + {}
+except TypeError:
+ print('TypeError')
diff --git a/tests/basics/dict_views.py b/tests/basics/dict_views.py
index fbf63fa0ac..7ebcc1f56d 100644
--- a/tests/basics/dict_views.py
+++ b/tests/basics/dict_views.py
@@ -3,4 +3,19 @@ for m in d.items, d.values, d.keys:
print(m())
print(list(m()))
+# print a view with more than one item
+print({1:1, 2:1}.values())
+
+# unsupported binary op on a dict values view
+try:
+ {1:1}.values() + 1
+except TypeError:
+ print('TypeError')
+
+# unsupported binary op on a dict keys view
+try:
+ {1:1}.keys() + 1
+except TypeError:
+ print('TypeError')
+
# set operations still to come
diff --git a/tests/basics/errno1.py b/tests/basics/errno1.py
new file mode 100644
index 0000000000..eae1bbe1b4
--- /dev/null
+++ b/tests/basics/errno1.py
@@ -0,0 +1,18 @@
+# test errno's and uerrno module
+
+try:
+ import uerrno
+except ImportError:
+ print("SKIP")
+ import sys
+ sys.exit()
+
+# check that constants exist and are integers
+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
new file mode 100644
index 0000000000..c3703df4a2
--- /dev/null
+++ b/tests/basics/errno1.py.exp
@@ -0,0 +1,3 @@
+<class 'int'>
+[Errno ] EIO
+9999
diff --git a/tests/basics/for_range.py b/tests/basics/for_range.py
index ddff5ebd44..58a8f7caa7 100644
--- a/tests/basics/for_range.py
+++ b/tests/basics/for_range.py
@@ -35,6 +35,11 @@ try:
except TypeError:
print('TypeError')
try:
+ for x in range(start=0, end=1):
+ print(x)
+except TypeError:
+ print('TypeError')
+try:
for x in range(0, 1, step=1):
print(x)
except TypeError:
diff --git a/tests/basics/frozenset_add.py b/tests/basics/frozenset_add.py
index 50615775bd..415a8c2e13 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/int_constfolding.py b/tests/basics/int_constfolding.py
index c01f964daa..aa38fa6b80 100644
--- a/tests/basics/int_constfolding.py
+++ b/tests/basics/int_constfolding.py
@@ -38,3 +38,8 @@ print(-123 // 7, -123 % 7)
print(123 // -7, 123 % -7)
print(-123 // -7, -123 % -7)
+# zero big-num on rhs
+print(1 + ((1 << 65) - (1 << 65)))
+
+# negative big-num on rhs
+print(1 + (-(1 << 65)))
diff --git a/tests/basics/scope.py b/tests/basics/scope.py
index 3aecc0b8d4..11704c482a 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 6afd9eb5ef..6ea69e4f05 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 abfcbe7d63..97b63a8150 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/slice_attrs.py b/tests/basics/slice_attrs.py
index 76368a78c6..67456ff8e6 100644
--- a/tests/basics/slice_attrs.py
+++ b/tests/basics/slice_attrs.py
@@ -14,3 +14,12 @@ except:
A()[1:2:3]
+
+# test storing to attr (shouldn't be allowed)
+class B:
+ def __getitem__(self, idx):
+ try:
+ idx.start = 0
+ except AttributeError:
+ print('AttributeError')
+B()[:]
diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py
index 857e171c10..b53a9c8bc0 100644
--- a/tests/basics/struct1.py
+++ b/tests/basics/struct1.py
@@ -10,6 +10,8 @@ print(struct.unpack(">bI", b"\x80\0\0\x01\0"))
# 32-bit little-endian specific
#print(struct.unpack("bI", b"\x80\xaa\x55\xaa\0\0\x01\0"))
+print(struct.pack("<l", 1))
+print(struct.pack(">l", 1))
print(struct.pack("<i", 1))
print(struct.pack(">i", 1))
print(struct.pack("<h", 1))
@@ -101,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/syntaxerror.py b/tests/basics/syntaxerror.py
index 2ae0183f8b..e5cbbac060 100644
--- a/tests/basics/syntaxerror.py
+++ b/tests/basics/syntaxerror.py
@@ -49,6 +49,9 @@ test_syntax("f[0]**2 = 1")
# can't assign to empty tuple
test_syntax("() = 1")
+# can't have *x on RHS
+test_syntax("x = *x")
+
# can't have multiple *x on LHS
test_syntax("*a, *b = c")
@@ -76,6 +79,7 @@ test_syntax("continue")
test_syntax("return")
test_syntax("yield")
test_syntax("nonlocal a")
+test_syntax("await 1")
# error on uPy, warning on CPy
#test_syntax("def f():\n a = 1\n global a")
diff --git a/tests/basics/try_finally2.py b/tests/basics/try_finally2.py
new file mode 100644
index 0000000000..3c4171d91f
--- /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/basics/unpack1.py b/tests/basics/unpack1.py
index 10e01dea06..0e8ec592c9 100644
--- a/tests/basics/unpack1.py
+++ b/tests/basics/unpack1.py
@@ -12,6 +12,7 @@ a, b, c = range(3); print(a, b, c)
(a,) = range(1); print(a)
(a, b) = range(2); print(a, b)
(a, b, c) = range(3); print(a, b, c)
+(a, (b, c)) = [-1, range(2)]; print(a, b, c)
# lists