-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_exception.py
186 lines (158 loc) · 5.78 KB
/
test_exception.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# -*- coding: utf-8 -*-
import re
import traceback
from fork import *
@cpu_bound
def runtime_error_cpu():
raise RuntimeError('runtime error')
@cpu_bound
def operator_error_cpu():
return ''
@io_bound
def runtime_error_io():
raise RuntimeError('runtime error')
@io_bound
def operator_error_io():
return ''
def test_cpu_bound_fork_runtime_error():
print('##### test_cpu_bound_fork_runtime_error #####')
try:
x = fork(runtime_error_cpu)
print(x)
except:
given_traceback = traceback.format_exc()
if re.match(wanted_runtime_traceback.strip(), given_traceback.strip()):
print('Traceback looks as desired.')
else:
print('Traceback do not look as desired:')
print(given_traceback.strip())
def test_cpu_bound_process_runtime_error():
print('##### test_cpu_bound_fork_runtime_error #####')
try:
x = process(runtime_error_cpu)
print(x)
except:
given_traceback = traceback.format_exc()
if re.match(wanted_runtime_traceback.strip(), given_traceback.strip()):
print('Traceback looks as desired.')
else:
print('Traceback do not look as desired:')
print(given_traceback.strip())
def test_io_bound_fork_runtime_error():
print('##### test_io_bound_fork_runtime_error #####')
try:
x = fork(runtime_error_io)
print(x)
except:
given_traceback = traceback.format_exc()
if re.match(wanted_runtime_traceback.strip(), given_traceback.strip()):
print('Traceback looks as desired.')
else:
print('Traceback do not look as desired:')
print(given_traceback.strip())
def test_io_bound_thread_runtime_error():
print('##### test_io_bound_thread_runtime_error #####')
try:
x = thread(runtime_error_io)
print(x)
except:
given_traceback = traceback.format_exc()
if re.match(wanted_runtime_traceback.strip(), given_traceback.strip()):
print('Traceback looks as desired.')
else:
print('Traceback do not look as desired:')
print(given_traceback.strip())
def test_cpu_bound_fork_operator_error():
print('##### test_cpu_bound_fork_operator_error #####')
try:
x = 1 + fork(operator_error_cpu)
print(x)
except:
given_traceback = traceback.format_exc()
if re.match(wanted_operator_traceback.strip(), given_traceback.strip()):
print('Traceback looks as desired.')
else:
print('Traceback do not look as desired:')
print(given_traceback.strip())
def test_cpu_bound_process_operator_error():
print('##### test_cpu_bound_process_operator_error #####')
try:
x = 1 + process(operator_error_cpu)
print(x)
except:
given_traceback = traceback.format_exc()
if re.match(wanted_operator_traceback.strip(), given_traceback.strip()):
print('Traceback looks as desired.')
else:
print('Traceback do not look as desired:')
print(given_traceback.strip())
def test_io_bound_fork_operator_error():
print('##### test_io_bound_fork_operator_error #####')
try:
x = 1 + fork(operator_error_io)
print(x)
except:
given_traceback = traceback.format_exc()
if re.match(wanted_operator_traceback.strip(), given_traceback.strip()):
print('Traceback looks as desired.')
else:
print('Traceback do not look as desired:')
print(given_traceback.strip())
def test_io_bound_thread_operator_error():
print('##### test_io_bound_thread_operator_error #####')
try:
x = 1 + thread(operator_error_io)
print(x)
except:
given_traceback = traceback.format_exc()
if re.match(wanted_operator_traceback.strip(), given_traceback.strip()):
print('Traceback looks as desired.')
else:
print('Traceback do not look as desired:')
print(given_traceback.strip())
wanted_runtime_traceback = \
r'''
Traceback \(most recent call last\):
File ".*/test_exception\.py", line \d+, in test_.*_runtime_error
print\(x\)
File ".*/fork\.py", line \d+, in __str__
return str\(self\.__future__\.result\(\)\)
File ".*/fork\.py", line \d+, in _result_with_proper_traceback
raise ResultEvaluationError\(original_traceback\)
(fork\.)?ResultEvaluationError:\s*
\s*
Original Traceback \(most recent call last\):
File ".*/test_exception\.py", line \d+, in <module>
test_.*_runtime_error\(\)
File ".*/test_exception\.py", line \d+, in test_.*_runtime_error
x = .*runtime_error.*
File ".*/test_exception\.py", line \d+, in runtime_error_.*
raise RuntimeError\('runtime error'\)
RuntimeError: runtime error
'''
wanted_operator_traceback = \
r'''
Traceback \(most recent call last\):
File ".*/test_exception\.py", line \d+, in test_.*_operator_error
print\(x\)
File ".*/fork\.py", line \d+, in __str__
return str\(self.__future__.result\(\)\)
File ".*/fork\.py", line \d+, in _result_with_proper_traceback
raise ResultEvaluationError\(original_traceback\)
(fork.)?ResultEvaluationError:\s*
\s*
Original Traceback \(most recent call last\):
File ".*/test_exception\.py", line \d+, in <module>
test_.*_operator_error\(\)
File ".*/test_exception\.py", line \d+, in .*_operator_error
x = \d+ \+ .*operator_error.*
TypeError: unsupported operand type\(s\) for \+: 'int' and 'str'
'''
test_cpu_bound_fork_runtime_error()
test_cpu_bound_process_runtime_error()
test_io_bound_fork_runtime_error()
test_io_bound_thread_runtime_error()
test_cpu_bound_fork_operator_error()
test_cpu_bound_process_operator_error()
test_io_bound_fork_operator_error()
test_io_bound_thread_operator_error()