diff options
author | Damien George <damien.p.george@gmail.com> | 2018-02-14 16:50:20 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-02-14 16:50:20 +1100 |
commit | 04c55f582866b700c5c39158ee76a1b970b71375 (patch) | |
tree | 2ba6bef5a0dc00f671d9c1959eb214890d5a80a2 /tests/basics/fun_error.py | |
parent | 6031957473a15f62ecbe59b9d27e58e9d06a4d8a (diff) | |
download | micropython-04c55f582866b700c5c39158ee76a1b970b71375.tar.gz micropython-04c55f582866b700c5c39158ee76a1b970b71375.zip |
tests: Rewrite some tests so they can run without needing eval/exec.
For builds without the compiler enabled (and hence without eval/exec) it is
useful to still be able to run as many tests as possible.
Diffstat (limited to 'tests/basics/fun_error.py')
-rw-r--r-- | tests/basics/fun_error.py | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/tests/basics/fun_error.py b/tests/basics/fun_error.py index 367fe0b7fa..3e79c727b3 100644 --- a/tests/basics/fun_error.py +++ b/tests/basics/fun_error.py @@ -1,31 +1,44 @@ # test errors from bad function calls -def test_exc(code, exc): - try: - exec(code) - print("no exception") - except exc: - print("right exception") - except: - print("wrong exception") - # function doesn't take keyword args -test_exc("[].append(x=1)", TypeError) +try: + [].append(x=1) +except TypeError: + print('TypeError') # function with variable number of positional args given too few -test_exc("round()", TypeError) +try: + round() +except TypeError: + print('TypeError') # function with variable number of positional args given too many -test_exc("round(1, 2, 3)", TypeError) +try: + round(1, 2, 3) +except TypeError: + print('TypeError') # function with fixed number of positional args given wrong number -test_exc("[].append(1, 2)", TypeError) +try: + [].append(1, 2) +except TypeError: + print('TypeError') # function with keyword args given extra positional args -test_exc("[].sort(1)", TypeError) +try: + [].sort(1) +except TypeError: + print('TypeError') # function with keyword args given extra keyword args -test_exc("[].sort(noexist=1)", TypeError) +try: + [].sort(noexist=1) +except TypeError: + print('TypeError') # kw given for positional, but a different positional is missing -test_exc("def f(x, y): pass\nf(x=1)", TypeError) +try: + def f(x, y): pass + f(x=1) +except TypeError: + print('TypeError') |