71
79
def test_get_frame_data_standard(self):
72
80
filename, lineno, name, line, modname, supplement, info = (
73
81
stacktrace._get_frame_data(get_frame(), MY_LINE_NUMBER))
74
self.assertEqual(__file__, filename)
82
self.assertEqual(MY_FILE_NAME, filename)
75
83
self.assertEqual(MY_LINE_NUMBER, lineno)
76
84
self.assertEqual('get_frame', name)
77
85
self.assertStartsWith(line, 'MY_LINE_NUMBER = ')
91
99
get_frame(supplement={}), MY_LINE_NUMBER))
93
101
dict(source_url=None, line=None, column=None, expression=None,
94
warnings=(), extra=None),
102
warnings=[], extra=None),
97
105
def test_get_frame_data_supplement_and_info(self):
102
110
self.assertEqual(
103
111
dict(source_url=None, line=None, column=None, expression=None,
104
warnings=(), extra=None),
112
warnings=[], extra=None),
106
114
self.assertEqual('foo bar', info)
121
129
self.assertEqual(
122
dict(source_url='/foo/bar.pt', line=42, column=84,
130
dict(source_url='/foo/bar.pt', line='42', column='84',
123
131
expression='tal:define="foo view/foo"',
124
warnings=('watch out', 'pass auf'),
132
warnings=['watch out', 'pass auf'],
125
133
extra='read all about it'),
135
143
self.assertEqual(
136
144
dict(source_url=None, line=None, column=None, expression=None,
137
warnings=(), extra=None),
145
warnings=[], extra=None),
140
148
def test_get_frame_data_supplement_bad_getInfo_with_traceback(self):
153
161
stacktrace.DEBUG_EXCEPTION_FORMATTER = False
154
162
self.assertEqual(
155
163
dict(source_url=None, line=None, column=None, expression=None,
156
warnings=(), extra=None),
164
warnings=[], extra=None),
158
166
self.assertIn('boo_hiss', stderr.getvalue())
168
def test_get_frame_data_broken_str(self):
170
filename, lineno, name, line, modname, supplement, info = (
171
stacktrace._get_frame_data(
178
warnings=('watch out', bad),
184
dict(source_url=None, line=None, column=None,
185
expression=None, warnings=['watch out'], extra=None),
187
self.assertIs(None, info)
189
def test_get_frame_data_broken_warnings(self):
190
filename, lineno, name, line, modname, supplement, info = (
191
stacktrace._get_frame_data(
197
self.assertEqual([], supplement['warnings'])
160
199
def test_extract_stack(self):
161
200
extracted = stacktrace.extract_stack(get_frame())
162
201
self.assertTrue(len(extracted) > 1)
163
202
filename, lineno, name, line, modname, supplement, info = (
165
self.assertEqual(__file__, filename)
204
self.assertEqual(MY_FILE_NAME, filename)
166
205
self.assertIsInstance(lineno, int)
167
206
self.assertEqual('get_frame', name)
168
207
self.assertEqual('return sys._getframe()', line)
179
218
self.assertEqual(1, len(extracted))
180
219
filename, lineno, name, line, modname, supplement, info = (
182
self.assertEqual(__file__, filename)
221
self.assertEqual(MY_FILE_NAME, filename)
183
222
self.assertIsInstance(lineno, int)
184
223
self.assertEqual('test_extract_tb', name)
185
224
self.assertEqual('raise ValueError()', line)
195
234
self.assertEndsWith(line, '\n')
196
235
line = formatted[-1].split('\n')
197
236
self.assertStartsWith(
198
line[0], ' File "' + __file__ + '", line ')
237
line[0], ' File "' + MY_FILE_NAME + '", line ')
199
238
self.assertEndsWith(line[0], ', in get_frame')
200
239
self.assertEqual(' return sys._getframe()', line[1])
218
257
self.assertEndsWith(line, '\n')
219
258
line = formatted[-1].split('\n')
220
259
self.assertStartsWith(
221
line[0], ' File "' + __file__ + '", line ')
260
line[0], ' File "' + MY_FILE_NAME + '", line ')
222
261
self.assertEndsWith(line[0], ', in get_frame')
223
262
self.assertEqual(' return sys._getframe()', line[1])
224
263
self.assertEqual(' - /foo/bar.pt', line[2])
234
273
self.assertEqual(' - I am the Walrus', line[8])
236
275
def test_format_list_extra_errors(self):
237
extracted = stacktrace.extract_stack(
240
# This will cause an error because it is not iterable.
276
extracted = stacktrace.extract_stack(get_frame(supplement=dict()))
277
extracted[-1][-2]['warnings'] = object() # This should never happen.
244
278
stderr = sys.stderr = StringIO.StringIO()
245
279
self.assertFalse(stacktrace.DEBUG_EXCEPTION_FORMATTER)
246
280
stacktrace.DEBUG_EXCEPTION_FORMATTER = True