| 1 |
import pytest |
| 2 |
import traceback |
| 3 |
import sys |
| 4 |
import os |
| 5 |
sys.path.insert(0, os.path.join(os.path.dirname( __file__ ), "..", "rebound")) |
| 6 |
import rebound |
| 7 |
|
| 8 |
|
| 9 |
EXCEPTION_DETAILS = "Exception details" |
| 10 |
|
| 11 |
def gen_python_exception(exception_type): |
| 12 |
stack_trace = None |
| 13 |
try: |
| 14 |
raise exception_type(EXCEPTION_DETAILS) |
| 15 |
except Exception: |
| 16 |
stack_trace = traceback.format_exc() |
| 17 |
return stack_trace |
| 18 |
|
| 19 |
def gen_expected_message(exception_type_str): |
| 20 |
return exception_type_str + ": " + EXCEPTION_DETAILS |
| 21 |
|
| 22 |
|
| 23 |
@pytest.mark.parametrize("exception_type, exception_type_str", [ |
| 24 |
(StopIteration, "StopIteration"), |
| 25 |
(StopAsyncIteration, "StopAsyncIteration"), |
| 26 |
(ArithmeticError, "ArithmeticError"), |
| 27 |
(AssertionError, "AssertionError"), |
| 28 |
(AttributeError, "AttributeError"), |
| 29 |
(BufferError, "BufferError"), |
| 30 |
(EOFError, "EOFError"), |
| 31 |
(ImportError, "ImportError"), |
| 32 |
(MemoryError, "MemoryError"), |
| 33 |
(NameError, "NameError"), |
| 34 |
(OSError, "OSError"), |
| 35 |
(ReferenceError, "ReferenceError"), |
| 36 |
(RuntimeError, "RuntimeError"), |
| 37 |
(SyntaxError, "SyntaxError"), |
| 38 |
(SystemError, "SystemError"), |
| 39 |
(TypeError, "TypeError"), |
| 40 |
(ValueError, "ValueError"), |
| 41 |
(Warning, "Warning") |
| 42 |
]) |
| 43 |
def test_get_error_message(exception_type, exception_type_str): |
| 44 |
error_message = rebound.get_error_message(gen_python_exception(exception_type), "python3") |
| 45 |
expected_error_message = gen_expected_message(exception_type_str) |
| 46 |
assert error_message == expected_error_message |