-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathpython_test.py
More file actions
46 lines (42 loc) · 1.48 KB
/
python_test.py
File metadata and controls
46 lines (42 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pytest
import traceback
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname( __file__ ), "..", "rebound"))
import rebound
# Constants and helper functions
EXCEPTION_DETAILS = "Exception details"
def gen_python_exception(exception_type):
stack_trace = None
try:
raise exception_type(EXCEPTION_DETAILS)
except Exception:
stack_trace = traceback.format_exc()
return stack_trace
def gen_expected_message(exception_type_str):
return exception_type_str + ": " + EXCEPTION_DETAILS
# Tests
@pytest.mark.parametrize("exception_type, exception_type_str", [
(StopIteration, "StopIteration"),
(StopAsyncIteration, "StopAsyncIteration"),
(ArithmeticError, "ArithmeticError"),
(AssertionError, "AssertionError"),
(AttributeError, "AttributeError"),
(BufferError, "BufferError"),
(EOFError, "EOFError"),
(ImportError, "ImportError"),
(MemoryError, "MemoryError"),
(NameError, "NameError"),
(OSError, "OSError"),
(ReferenceError, "ReferenceError"),
(RuntimeError, "RuntimeError"),
(SyntaxError, "SyntaxError"),
(SystemError, "SystemError"),
(TypeError, "TypeError"),
(ValueError, "ValueError"),
(Warning, "Warning")
])
def test_get_error_message(exception_type, exception_type_str):
error_message = rebound.get_error_message(gen_python_exception(exception_type), "python3")
expected_error_message = gen_expected_message(exception_type_str)
assert error_message == expected_error_message