diff options
author | David Lechner <david@lechnology.com> | 2020-03-22 21:26:08 -0500 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-03-30 13:21:58 +1100 |
commit | 3dc324d3f1312e40d3a8ed87e7244966bb756f26 (patch) | |
tree | 94ff44f8eabba0039582c245b901173597edd11e /tests/misc/print_exception.py | |
parent | 488613bca6c460340ed2995ae5cafafe22d0bfff (diff) | |
download | micropython-3dc324d3f1312e40d3a8ed87e7244966bb756f26.tar.gz micropython-3dc324d3f1312e40d3a8ed87e7244966bb756f26.zip |
tests: Format all Python code with black, except tests in basics subdir.
This adds the Python files in the tests/ directory to be formatted with
./tools/codeformat.py. The basics/ subdirectory is excluded for now so we
aren't changing too much at once.
In a few places `# fmt: off`/`# fmt: on` was used where the code had
special formatting for readability or where the test was actually testing
the specific formatting.
Diffstat (limited to 'tests/misc/print_exception.py')
-rw-r--r-- | tests/misc/print_exception.py | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/tests/misc/print_exception.py b/tests/misc/print_exception.py index 2067030bf9..f26c1fd5ac 100644 --- a/tests/misc/print_exception.py +++ b/tests/misc/print_exception.py @@ -1,4 +1,5 @@ import sys + try: try: import uio as io @@ -8,12 +9,14 @@ except ImportError: print("SKIP") raise SystemExit -if hasattr(sys, 'print_exception'): +if hasattr(sys, "print_exception"): print_exception = sys.print_exception else: import traceback + print_exception = lambda e, f: traceback.print_exception(None, e, sys.exc_info()[2], file=f) + def print_exc(e): buf = io.StringIO() print_exception(e, buf) @@ -29,22 +32,27 @@ def print_exc(e): elif not l.startswith(" "): print(l) + # basic exception message try: - raise Exception('msg') + raise Exception("msg") except Exception as e: - print('caught') + print("caught") print_exc(e) # exception message with more than 1 source-code line def f(): g() + + def g(): - raise Exception('fail') + raise Exception("fail") + + try: f() except Exception as e: - print('caught') + print("caught") print_exc(e) # Test that an exception propagated through a finally doesn't have a traceback added there @@ -52,9 +60,9 @@ try: try: f() finally: - print('finally') + print("finally") except Exception as e: - print('caught') + print("caught") print_exc(e) # Test that re-raising an exception doesn't add traceback info @@ -62,25 +70,27 @@ try: try: f() except Exception as e: - print('reraise') + print("reraise") print_exc(e) raise except Exception as e: - print('caught') + print("caught") print_exc(e) # Here we have a function with lots of bytecode generated for a single source-line, and # there is an error right at the end of the bytecode. It should report the correct line. def f(): - f([1, 2], [1, 2], [1, 2], {1:1, 1:1, 1:1, 1:1, 1:1, 1:1, 1:f.X}) + f([1, 2], [1, 2], [1, 2], {1: 1, 1: 1, 1: 1, 1: 1, 1: 1, 1: 1, 1: f.X}) return 1 + + try: f() except Exception as e: print_exc(e) # Test non-stream object passed as output object, only valid for uPy -if hasattr(sys, 'print_exception'): +if hasattr(sys, "print_exception"): try: sys.print_exception(Exception, 1) had_exception = False |