From 6572029dc0665e58c2ea7355c9e541bdf83105a4 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 22 Jul 2018 16:19:22 +0200 Subject: [PATCH] tests: Make tests work on targets without float support. --- tests/basics/op_precedence.py | 2 +- tests/extmod/urandom_extra.py | 10 ---------- tests/extmod/urandom_extra_float.py | 24 ++++++++++++++++++++++++ tests/misc/print_exception.py | 4 ++-- tests/run-tests | 4 ++++ 5 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 tests/extmod/urandom_extra_float.py diff --git a/tests/basics/op_precedence.py b/tests/basics/op_precedence.py index 519a2a1137..7d8302ba4d 100644 --- a/tests/basics/op_precedence.py +++ b/tests/basics/op_precedence.py @@ -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) diff --git a/tests/extmod/urandom_extra.py b/tests/extmod/urandom_extra.py index f5a34e1687..0cfd9280b5 100644 --- a/tests/extmod/urandom_extra.py +++ b/tests/extmod/urandom_extra.py @@ -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 diff --git a/tests/extmod/urandom_extra_float.py b/tests/extmod/urandom_extra_float.py new file mode 100644 index 0000000000..f665fd18ad --- /dev/null +++ b/tests/extmod/urandom_extra_float.py @@ -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 diff --git a/tests/misc/print_exception.py b/tests/misc/print_exception.py index f120fe1e18..f331624045 100644 --- a/tests/misc/print_exception.py +++ b/tests/misc/print_exception.py @@ -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: diff --git a/tests/run-tests b/tests/run-tests index dd88ac0afb..0a70963d77 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -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