tests: Make tests work on targets without float support.

This commit is contained in:
Ayke van Laethem 2018-07-22 16:19:22 +02:00 committed by Damien George
parent 7be5bb3672
commit 6572029dc0
5 changed files with 31 additions and 13 deletions

View File

@ -37,7 +37,7 @@ print(2 + 2 * 2)
# BAD: (-2)**2 = 4
print(-2**2)
# OK: 2**(-1) = 0.5
print(2**-1)
print(2**-0)
# (expr...)
print((2 + 2) * 2)

View File

@ -67,13 +67,3 @@ try:
random.choice([])
except IndexError:
print('IndexError')
print('random')
for i in range(50):
assert 0 <= random.random() < 1
print('uniform')
for i in range(50):
assert 0 <= random.uniform(0, 4) <= 4
assert 2 <= random.uniform(2, 6) <= 6
assert -2 <= random.uniform(-2, 2) <= 2

View File

@ -0,0 +1,24 @@
try:
import urandom as random
except ImportError:
try:
import random
except ImportError:
print("SKIP")
raise SystemExit
try:
random.randint
except AttributeError:
print('SKIP')
raise SystemExit
print('random')
for i in range(50):
assert 0 <= random.random() < 1
print('uniform')
for i in range(50):
assert 0 <= random.uniform(0, 4) <= 4
assert 2 <= random.uniform(2, 6) <= 6
assert -2 <= random.uniform(-2, 2) <= 2

View File

@ -31,7 +31,7 @@ def print_exc(e):
# basic exception message
try:
1/0
raise Exception('msg')
except Exception as e:
print('caught')
print_exc(e)
@ -40,7 +40,7 @@ except Exception as e:
def f():
g()
def g():
2/0
raise Exception('fail')
try:
f()
except Exception as e:

View File

@ -277,8 +277,12 @@ def run_tests(pyb, tests, args, base_path="."):
skip_tests.add('thread/stress_recurse.py') # has reliability issues
if upy_float_precision == 0:
skip_tests.add('extmod/uctypes_le_float.py')
skip_tests.add('extmod/uctypes_native_float.py')
skip_tests.add('extmod/uctypes_sizeof_float.py')
skip_tests.add('extmod/ujson_dumps_float.py')
skip_tests.add('extmod/ujson_loads_float.py')
skip_tests.add('extmod/urandom_extra_float.py')
skip_tests.add('misc/rge_sm.py')
if upy_float_precision < 32:
skip_tests.add('float/float2int_intbig.py') # requires fp32, there's float2int_fp30_intbig.py instead