Skip to content
Snippets Groups Projects
Commit af435653 authored by Damien George's avatar Damien George
Browse files

tests: Add tests for things that are not already tested.

The aim here is to improve coverage of the code.
parent 848dd0e7
Branches
No related tags found
No related merge requests found
# test assignments
a = 1
print(a)
a = b = 2
print(a, b)
a = b = c = 3
print(a, b, c)
# test decorators
def dec(f):
print('dec')
return f
def dec_arg(x):
print(x)
return lambda f:f
# plain decorator
@dec
def f():
pass
# decorator with arg
@dec_arg('dec_arg')
def g():
pass
# decorator of class
@dec
class A:
pass
...@@ -16,3 +16,41 @@ try: ...@@ -16,3 +16,41 @@ try:
except: # NameError: except: # NameError:
# FIXME uPy returns KeyError for this # FIXME uPy returns KeyError for this
print("NameError") print("NameError")
# delete globals using a list
a = 1
del (a,)
try:
print(a)
except NameError:
print("NameError")
a = 2
b = 3
del (a, b)
try:
print(a)
except NameError:
print("NameError")
try:
print(b)
except NameError:
print("NameError")
a = 1
b = 2
c = 3
del (a, b, c)
try:
print(a)
except NameError:
print("NameError")
try:
print(b)
except NameError:
print("NameError")
try:
print(c)
except NameError:
print("NameError")
...@@ -11,3 +11,8 @@ del d[3] ...@@ -11,3 +11,8 @@ del d[3]
print(d) print(d)
del d[5] del d[5]
print(d) print(d)
# delete nested subscr
d = {0:{0:0}}
del d[0][0]
print(d)
...@@ -33,6 +33,30 @@ elif 0: ...@@ -33,6 +33,30 @@ elif 0:
else: else:
print(17) print(17)
if not False:
print('a')
if not True:
print('a')
else:
print('b')
if False:
print('a')
else:
print('b')
if True:
print('a')
if (1,):
print('a')
if not (1,):
print('a')
else:
print('b')
f2 = 0 f2 = 0
def f(t1, t2, f1): def f(t1, t2, f1):
......
...@@ -24,6 +24,17 @@ print(-1073741823) ...@@ -24,6 +24,17 @@ print(-1073741823)
# Operations tests # Operations tests
# compile-time constexprs
print(1 + 3)
print(3 - 2)
print(2 * 3)
print(1 & 3)
print(1 | 2)
print(1 ^ 3)
print(+3)
print(-3)
print(~3)
a = 0x3fffff a = 0x3fffff
print(a) print(a)
a *= 0x10 a *= 0x10
......
# test return statement
def f():
return
print(f())
def g():
return 1
print(g())
def f(x):
return 1 if x else 2
print(f(0), f(1))
...@@ -14,6 +14,13 @@ print(a, b) ...@@ -14,6 +14,13 @@ print(a, b)
[a, b] = 100, 200 [a, b] = 100, 200
print(a, b) print(a, b)
# optimised 3-way swap
a = 1
b = 2
c = 3
a, b, c = b, c, a
print(a, b, c)
try: try:
a, b, c = (1, 2) a, b, c = (1, 2)
except ValueError: except ValueError:
......
...@@ -22,3 +22,6 @@ try: ...@@ -22,3 +22,6 @@ try:
print(','.join([b'abc', b'123'])) print(','.join([b'abc', b'123']))
except TypeError: except TypeError:
print("TypeError") print("TypeError")
# joined by the compiler
print("a" "b")
...@@ -2,8 +2,23 @@ ...@@ -2,8 +2,23 @@
a, = 1, ; print(a) a, = 1, ; print(a)
a, b = 2, 3 ; print(a, b) a, b = 2, 3 ; print(a, b)
a, b, c = 1, 2, 3; print(a, b, c)
a, = range(1); print(a)
a, b = range(2); print(a, b) a, b = range(2); print(a, b)
a, b, c = range(3); print(a, b, c)
(a) = range(1); print(a)
(a,) = range(1); print(a)
(a, b) = range(2); print(a, b)
(a, b, c) = range(3); print(a, b, c)
# lists
[] = []
[a] = range(1); print(a)
[a, b] = range(2); print(a, b)
[a, b, c] = range(3); print(a, b, c)
# with star # with star
...@@ -27,6 +42,9 @@ a = [28, 29] ...@@ -27,6 +42,9 @@ a = [28, 29]
*b, = a *b, = a
print(a, b, a == b) print(a, b, a == b)
[*a] = [1, 2, 3]
print(a)
try: try:
a, *b, c = (30,) a, *b, c = (30,)
except ValueError: except ValueError:
......
...@@ -16,3 +16,21 @@ while 2: ...@@ -16,3 +16,21 @@ while 2:
while -1: while -1:
print(4) print(4)
break break
while False:
print('a')
else:
print('b')
while True:
print('a')
break
while not False:
print('a')
break
while not True:
print('a')
else:
print('b')
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
x = 1 / 2 x = 1 / 2
print(x) print(x)
# /= operator
a = 1
a /= 2
print(a)
print(1.0 // 2) print(1.0 // 2)
print(2.0 // 2) print(2.0 // 2)
......
# test micropython-specific decorators
@micropython.bytecode
def f():
return 'bytecode'
print(f())
bytecode
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment