tests: Add tests for things that are not already tested.
The aim here is to improve coverage of the code.
This commit is contained in:
parent
848dd0e762
commit
af43565322
11
tests/basics/assign1.py
Normal file
11
tests/basics/assign1.py
Normal file
@ -0,0 +1,11 @@
|
||||
# test assignments
|
||||
|
||||
a = 1
|
||||
print(a)
|
||||
|
||||
a = b = 2
|
||||
print(a, b)
|
||||
|
||||
a = b = c = 3
|
||||
print(a, b, c)
|
||||
|
24
tests/basics/decorator.py
Normal file
24
tests/basics/decorator.py
Normal file
@ -0,0 +1,24 @@
|
||||
# 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:
|
||||
except: # NameError:
|
||||
# FIXME uPy returns KeyError for this
|
||||
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]
|
||||
print(d)
|
||||
del d[5]
|
||||
print(d)
|
||||
|
||||
# delete nested subscr
|
||||
d = {0:{0:0}}
|
||||
del d[0][0]
|
||||
print(d)
|
||||
|
@ -33,6 +33,30 @@ elif 0:
|
||||
else:
|
||||
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
|
||||
|
||||
def f(t1, t2, f1):
|
||||
|
@ -24,6 +24,17 @@ print(-1073741823)
|
||||
|
||||
# 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
|
||||
print(a)
|
||||
a *= 0x10
|
||||
|
13
tests/basics/return1.py
Normal file
13
tests/basics/return1.py
Normal file
@ -0,0 +1,13 @@
|
||||
# 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)
|
||||
[a, b] = 100, 200
|
||||
print(a, b)
|
||||
|
||||
# optimised 3-way swap
|
||||
a = 1
|
||||
b = 2
|
||||
c = 3
|
||||
a, b, c = b, c, a
|
||||
print(a, b, c)
|
||||
|
||||
try:
|
||||
a, b, c = (1, 2)
|
||||
except ValueError:
|
||||
|
@ -22,3 +22,6 @@ try:
|
||||
print(','.join([b'abc', b'123']))
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
# joined by the compiler
|
||||
print("a" "b")
|
||||
|
@ -2,8 +2,23 @@
|
||||
|
||||
a, = 1, ; print(a)
|
||||
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, 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
|
||||
|
||||
@ -27,6 +42,9 @@ a = [28, 29]
|
||||
*b, = a
|
||||
print(a, b, a == b)
|
||||
|
||||
[*a] = [1, 2, 3]
|
||||
print(a)
|
||||
|
||||
try:
|
||||
a, *b, c = (30,)
|
||||
except ValueError:
|
||||
|
@ -16,3 +16,21 @@ while 2:
|
||||
while -1:
|
||||
print(4)
|
||||
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 @@
|
||||
x = 1 / 2
|
||||
print(x)
|
||||
|
||||
# /= operator
|
||||
a = 1
|
||||
a /= 2
|
||||
print(a)
|
||||
|
||||
print(1.0 // 2)
|
||||
print(2.0 // 2)
|
||||
|
||||
|
7
tests/micropython/decorator.py
Normal file
7
tests/micropython/decorator.py
Normal file
@ -0,0 +1,7 @@
|
||||
# test micropython-specific decorators
|
||||
|
||||
@micropython.bytecode
|
||||
def f():
|
||||
return 'bytecode'
|
||||
|
||||
print(f())
|
1
tests/micropython/decorator.py.exp
Normal file
1
tests/micropython/decorator.py.exp
Normal file
@ -0,0 +1 @@
|
||||
bytecode
|
Loading…
Reference in New Issue
Block a user