Skip to content

Commit 12c66be

Browse files
committed
tests: Add some tests to improve coverage.
Used gcov to find some parts of vm.c, runtime.c, obj.c that were not covered by any tests. Still need to use gcov more thoroughly.
1 parent 81e70a8 commit 12c66be

8 files changed

Lines changed: 59 additions & 1 deletion

File tree

tests/basics/builtin_hash.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# test builtin hash function
22

3+
print(hash(False))
4+
print(hash(True))
5+
print({():1}) # hash tuple
6+
print({1 << 66:1}) # hash big int
7+
print(hash in {hash:1}) # hash function
8+
9+
try:
10+
hash([])
11+
except TypeError:
12+
print("TypeError")
13+
314
class A:
415
def __hash__(self):
516
return 123

tests/basics/del_global.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# del global
2+
3+
def do_del():
4+
global x
5+
del x
6+
7+
x = 1
8+
print(x)
9+
do_del()
10+
try:
11+
print(x)
12+
except NameError:
13+
print("NameError")
14+
try:
15+
do_del()
16+
except: # NameError:
17+
# FIXME uPy returns KeyError for this
18+
print("NameError")

tests/basics/del_name.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# del global
1+
# del name
22

33
x = 1
44
print(x)

tests/basics/fun_largestate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,9 @@ def f():
129129
x125 = 1
130130
x126 = 1
131131

132+
f()
133+
132134
def g():
133135
x = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,]
136+
137+
g()

tests/basics/int1.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
print(int(False))
2+
print(int(True))
3+
14
print(int(0))
25
print(int(1))
36
print(int(+1))

tests/basics/int_small.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@
4949
# This would overflow
5050
#a -= 1
5151

52+
# negative shifts are not allowed
53+
try:
54+
a << -1
55+
except ValueError:
56+
print("ValueError")
57+
try:
58+
a >> -1
59+
except ValueError:
60+
print("ValueError")
5261

5362
# Shifts to big amounts are undefined behavior in C and is CPU-specific
5463

tests/basics/unary_op.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
x = 1
2+
print(+x)
3+
print(-x)
4+
print(~x)
5+
16
print(not None)
27
print(not False)
38
print(not True)

tests/float/int_power.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# negative power should produce float
2+
3+
x = 2
4+
print(x ** -2)
5+
6+
x = 3
7+
x **= -2
8+
print(x)

0 commit comments

Comments
 (0)