Skip to content

Commit 5cd0b22

Browse files
committed
tests: Split out those tests requiring float and import.
Tests in basics (which should probably be renamed to core) should not rely on float, or import any non-built-in files. This way these tests can be run when those features are not available. All test in basics now pass on the pyboard using stmhal port, except for string-repr which has some issues with character hex printing.
1 parent d7a4b69 commit 5cd0b22

40 files changed

Lines changed: 202 additions & 146 deletions

tests/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ This directory contains tests for various functionality areas of MicroPython.
22
To run all stable tests, run "run-tests" script in this directory. Note
33
that bytecode tests are not yet stable and should be run separately in
44
"bytecode" subdirectory.
5+
6+
When creating new tests, anything that relies on float support should go in the
7+
float/ subdirectory. Anything that relies on import x, where x is not a built-in
8+
module, should go in the import/ subdirectory.

tests/basics/int-divzero.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
try:
2-
1 / 0
3-
except ZeroDivisionError:
4-
print("ZeroDivisionError")
5-
61
try:
72
1 // 0
83
except ZeroDivisionError:

tests/basics/list1.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,3 @@
2222
print(x[1:])
2323
print(x[:-1])
2424
print(x[2:3])
25-
26-
try:
27-
print(x[1.0])
28-
except TypeError:
29-
print("TypeError")

tests/basics/modulo.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# check modulo matches python definition
2-
# This test compiler version
2+
3+
# this tests compiler constant folding
34
print(123 % 7)
45
print(-123 % 7)
56
print(123 % -7)
@@ -20,17 +21,3 @@
2021
print(a % -b)
2122
print(-a % b)
2223
print(-a % -b)
23-
24-
if False:
25-
print(1.23456 % 0.7)
26-
print(-1.23456 % 0.7)
27-
print(1.23456 % -0.7)
28-
print(-1.23456 % -0.7)
29-
30-
a = 1.23456
31-
b = 0.7
32-
print(a % b)
33-
print(a % -b)
34-
print(-a % b)
35-
print(-a % -b)
36-

tests/basics/string-format-modulo.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323

2424
print("%s" % True)
2525
print("%s" % 1)
26-
print("%s" % 1.0)
2726

2827
print("%r" % True)
2928
print("%r" % 1)
30-
print("%r" % 1.0)
3129

3230
print("%c" % 48)
3331
print("%c" % 'a')
@@ -37,28 +35,16 @@
3735
print("%+d" % 10)
3836
print("% d" % 10)
3937
print("%d" % -10)
40-
print("%d" % 1.0)
4138
print("%d" % True)
4239
print("%i" % -10)
43-
print("%i" % 1.0)
4440
print("%i" % True)
4541
print("%u" % -10)
46-
print("%u" % 1.0)
4742
print("%u" % True)
4843
print("%x" % 18)
49-
print("%x" % 18.0)
5044
print("%o" % 18)
51-
print("%o" % 18.0)
5245
print("%X" % 18)
53-
print("%X" % 18.0)
5446
print("%#x" % 18)
5547
print("%#X" % 18)
5648
print("%#6o" % 18)
5749
print("%#6x" % 18)
5850
print("%#06x" % 18)
59-
print("%e" % 1.23456)
60-
print("%E" % 1.23456)
61-
print("%f" % 1.23456)
62-
print("%F" % 1.23456)
63-
print("%g" % 1.23456)
64-
print("%G" % 1.23456)

tests/basics/string-format.py

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,6 @@ def test(fmt, *args):
6060
test("{:@=6d}", -123)
6161
test("{:06d}", -123)
6262

63-
test("{:10.4e}", 123.456)
64-
test("{:10.4e}", -123.456)
65-
test("{:10.4f}", 123.456)
66-
test("{:10.4f}", -123.456)
67-
test("{:10.4g}", 123.456)
68-
test("{:10.4g}", -123.456)
69-
test("{:e}", 100)
70-
test("{:f}", 200)
71-
test("{:g}", 300)
72-
73-
test("{:10.4E}", 123.456)
74-
test("{:10.4E}", -123.456)
75-
test("{:10.4F}", 123.456)
76-
test("{:10.4F}", -123.456)
77-
test("{:10.4G}", 123.456)
78-
test("{:10.4G}", -123.456)
79-
80-
# The following fails right now
81-
#test("{:10.1}", 0.0)
82-
8363
def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
8464
fmt = '{'
8565
if conv:
@@ -137,71 +117,4 @@ def test_fmt(conv, fill, alignment, sign, prefix, width, precision, type, arg):
137117
for str in ('', 'a', 'bcd', 'This is a test with a longer string'):
138118
test_fmt(conv, fill, alignment, '', '', width, '', 's', str)
139119

140-
eg_nums = (0.0, -0.0, 0.1, 1.234, 12.3459, 1.23456789, 123456789.0, -0.0,
141-
-0.1, -1.234, -12.3459, 1e4, 1e-4, 1e5, 1e-5, 1e6, 1e-6, 1e10,
142-
1e37, -1e37, 1e-37, -1e-37,
143-
1.23456e8, 1.23456e7, 1.23456e6, 1.23456e5, 1.23456e4, 1.23456e3, 1.23456e2, 1.23456e1, 1.23456e0,
144-
1.23456e-1, 1.23456e-2, 1.23456e-3, 1.23456e-4, 1.23456e-5, 1.23456e-6, 1.23456e-7, 1.23456e-8,
145-
-1.23456e8, -1.23456e7, -1.23456e6, -1.23456e5, -1.23456e4, -1.23456e3, -1.23456e2, -1.23456e1, -1.23456e0,
146-
-1.23456e-1, -1.23456e-2, -1.23456e-3, -1.23456e-4, -1.23456e-5, -1.23456e-6, -1.23456e-7, -1.23456e-8)
147-
148-
if full_tests:
149-
for type in ('e', 'E', 'g', 'G', 'n'):
150-
for width in ('', '4', '6', '8', '10'):
151-
for alignment in ('', '<', '>', '=', '^'):
152-
for fill in ('', '@', '0', ' '):
153-
for sign in ('', '+', '-', ' '):
154-
for prec in ('', '1', '3', '6'):
155-
for num in eg_nums:
156-
test_fmt('', fill, alignment, sign, '', width, prec, type, num)
157-
158-
# Note: We use 1.23459 rather than 1.2345 because '{:3f}'.format(1.2345)
159-
# rounds differently than print("%.3f", 1.2345);
160-
161-
f_nums = (0.0, -0.0, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0,
162-
0.0012, 0.0123, 0.1234, 1.23459, 12.3456,
163-
-0.0001, -0.001, -0.01, -0.1, -1.0, -10.0,
164-
-0.0012, -0.0123, -0.1234, -1.23459, -12.3456)
165-
166-
if full_tests:
167-
for type in ('f', 'F'):
168-
for width in ('', '4', '6', '8', '10'):
169-
for alignment in ('', '<', '>', '=', '^'):
170-
for fill in ('', ' ', '0', '@'):
171-
for sign in ('', '+', '-', ' '):
172-
# An empty precision defaults to 6, but when uPy is
173-
# configured to use a float, we can only use a
174-
# precision of 6 with numbers less than 10 and still
175-
# get results that compare to CPython (which uses
176-
# long doubles).
177-
for prec in ('1', '2', '3'):
178-
for num in f_nums:
179-
test_fmt('', fill, alignment, sign, '', width, prec, type, num)
180-
for num in int_nums2:
181-
test_fmt('', fill, alignment, sign, '', width, '', type, num)
182-
183-
pct_nums1 = (0.1, 0.58, 0.99, -0.1, -0.58, -0.99)
184-
pct_nums2 = (True, False, 1, 0, -1)
185-
186-
if full_tests:
187-
type = '%'
188-
for width in ('', '4', '6', '8', '10'):
189-
for alignment in ('', '<', '>', '=', '^'):
190-
for fill in ('', ' ', '0', '@'):
191-
for sign in ('', '+', '-', ' '):
192-
# An empty precision defaults to 6, but when uPy is
193-
# configured to use a float, we can only use a
194-
# precision of 6 with numbers less than 10 and still
195-
# get results that compare to CPython (which uses
196-
# long doubles).
197-
for prec in ('1', '2', '3'):
198-
for num in pct_nums1:
199-
test_fmt('', fill, alignment, sign, '', width, prec, type, num)
200-
for num in pct_nums2:
201-
test_fmt('', fill, alignment, sign, '', width, '', type, num)
202-
203-
# We don't currently test a type of '' with floats (see the detailed comment
204-
# in objstr.c)
205-
206120
# TODO Add tests for erroneous format strings.
207-

tests/basics/true-value.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
if not 0:
1010
print("0")
1111

12-
if not 0.0:
13-
print("float 0")
14-
15-
if not 0+0j:
16-
print("complex 0")
17-
1812
if not "":
1913
print("Empty string")
2014
if "foo":

tests/basics/types1.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,20 @@
22

33
print(bool)
44
print(int)
5-
print(float)
6-
print(complex)
75
print(tuple)
86
print(list)
97
print(set)
108
print(dict)
119

1210
print(type(bool()) == bool)
1311
print(type(int()) == int)
14-
print(type(float()) == float)
15-
print(type(complex()) == complex)
1612
print(type(tuple()) == tuple)
1713
print(type(list()) == list)
1814
print(type(set()) == set)
1915
print(type(dict()) == dict)
2016

2117
print(type(False) == bool)
2218
print(type(0) == int)
23-
print(type(0.0) == float)
24-
print(type(1j) == complex)
2519
print(type(()) == tuple)
2620
print(type([]) == list)
2721
print(type({None}) == set)

tests/basics/types2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ class Foo: pass
99
print(int != list)
1010

1111
d = {}
12-
d[int] = float
12+
d[int] = list
13+
d[list] = int
14+
print(len(d))

0 commit comments

Comments
 (0)