Skip to content

Commit

Permalink
tests: Make tests work on targets without float support.
Browse files Browse the repository at this point in the history
  • Loading branch information
aykevl committed Jul 30, 2018
1 parent f6f6452 commit c1410b2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/basics/op_precedence.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# BAD: (-2)**2 = 4
print(-2**2)
# OK: 2**(-1) = 0.5
print(2**-1)
print(2**-0)

# (expr...)
print((2 + 2) * 2)
10 changes: 0 additions & 10 deletions tests/extmod/urandom_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,3 @@
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
24 changes: 24 additions & 0 deletions tests/extmod/urandom_extra_float.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tests/misc/print_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -40,7 +40,7 @@ def print_exc(e):
def f():
g()
def g():
2/0
raise Exception('fail')
try:
f()
except Exception as e:
Expand Down
4 changes: 4 additions & 0 deletions tests/run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c1410b2

Please sign in to comment.