Show More
@@ -2,10 +2,14 b'' | |||
|
2 | 2 | """Tests for IPython.core.ultratb |
|
3 | 3 | """ |
|
4 | 4 | import io |
|
5 | import sys | |
|
5 | 6 | import os.path |
|
6 | 7 | from textwrap import dedent |
|
8 | import traceback | |
|
7 | 9 | import unittest |
|
8 | 10 | |
|
11 | from ..ultratb import ColorTB, VerboseTB | |
|
12 | ||
|
9 | 13 | |
|
10 | 14 | from IPython.testing import tools as tt |
|
11 | 15 | from IPython.testing.decorators import onlyif_unicode_paths |
@@ -220,3 +224,48 b' except Exception:' | |||
|
220 | 224 | with tt.AssertNotPrints("ZeroDivisionError"), \ |
|
221 | 225 | tt.AssertPrints("ValueError", suppress=False): |
|
222 | 226 | ip.run_cell(self.SUPPRESS_CHAINING_CODE) |
|
227 | ||
|
228 | ||
|
229 | #---------------------------------------------------------------------------- | |
|
230 | ||
|
231 | # module testing (minimal) | |
|
232 | def test_handlers(): | |
|
233 | def spam(c, d_e): | |
|
234 | (d, e) = d_e | |
|
235 | x = c + d | |
|
236 | y = c * d | |
|
237 | foo(x, y) | |
|
238 | ||
|
239 | def foo(a, b, bar=1): | |
|
240 | eggs(a, b + bar) | |
|
241 | ||
|
242 | def eggs(f, g, z=globals()): | |
|
243 | h = f + g | |
|
244 | i = f - g | |
|
245 | return h / i | |
|
246 | ||
|
247 | buff = io.StringIO() | |
|
248 | ||
|
249 | buff.write(u'') | |
|
250 | buff.write(u'*** Before ***') | |
|
251 | try: | |
|
252 | buff.write(spam(1, (2, 3))) | |
|
253 | except: | |
|
254 | traceback.print_exc(file=buff) | |
|
255 | ||
|
256 | handler = ColorTB(ostream=buff) | |
|
257 | buff.write(u'*** ColorTB ***') | |
|
258 | try: | |
|
259 | buff.write(spam(1, (2, 3))) | |
|
260 | except: | |
|
261 | handler(*sys.exc_info()) | |
|
262 | buff.write(u'') | |
|
263 | ||
|
264 | handler = VerboseTB(ostream=buff) | |
|
265 | buff.write(u'*** VerboseTB ***') | |
|
266 | try: | |
|
267 | buff.write(spam(1, (2, 3))) | |
|
268 | except: | |
|
269 | handler(*sys.exc_info()) | |
|
270 | buff.write(u'') | |
|
271 |
@@ -1326,9 +1326,9 b' class AutoFormattedTB(FormattedTB):' | |||
|
1326 | 1326 | class ColorTB(FormattedTB): |
|
1327 | 1327 | """Shorthand to initialize a FormattedTB in Linux colors mode.""" |
|
1328 | 1328 | |
|
1329 | def __init__(self, color_scheme='Linux', call_pdb=0): | |
|
1329 | def __init__(self, color_scheme='Linux', call_pdb=0, **kwargs): | |
|
1330 | 1330 | FormattedTB.__init__(self, color_scheme=color_scheme, |
|
1331 | call_pdb=call_pdb) | |
|
1331 | call_pdb=call_pdb, **kwargs) | |
|
1332 | 1332 | |
|
1333 | 1333 | |
|
1334 | 1334 | class SyntaxTB(ListTB): |
@@ -1405,47 +1405,3 b' def eqrepr(value, repr=text_repr):' | |||
|
1405 | 1405 | |
|
1406 | 1406 | def nullrepr(value, repr=text_repr): |
|
1407 | 1407 | return '' |
|
1408 | ||
|
1409 | ||
|
1410 | #---------------------------------------------------------------------------- | |
|
1411 | ||
|
1412 | # module testing (minimal) | |
|
1413 | if __name__ == "__main__": | |
|
1414 | def spam(c, d_e): | |
|
1415 | (d, e) = d_e | |
|
1416 | x = c + d | |
|
1417 | y = c * d | |
|
1418 | foo(x, y) | |
|
1419 | ||
|
1420 | def foo(a, b, bar=1): | |
|
1421 | eggs(a, b + bar) | |
|
1422 | ||
|
1423 | def eggs(f, g, z=globals()): | |
|
1424 | h = f + g | |
|
1425 | i = f - g | |
|
1426 | return h / i | |
|
1427 | ||
|
1428 | print('') | |
|
1429 | print('*** Before ***') | |
|
1430 | try: | |
|
1431 | print(spam(1, (2, 3))) | |
|
1432 | except: | |
|
1433 | traceback.print_exc() | |
|
1434 | print('') | |
|
1435 | ||
|
1436 | handler = ColorTB() | |
|
1437 | print('*** ColorTB ***') | |
|
1438 | try: | |
|
1439 | print(spam(1, (2, 3))) | |
|
1440 | except: | |
|
1441 | handler(*sys.exc_info()) | |
|
1442 | print('') | |
|
1443 | ||
|
1444 | handler = VerboseTB() | |
|
1445 | print('*** VerboseTB ***') | |
|
1446 | try: | |
|
1447 | print(spam(1, (2, 3))) | |
|
1448 | except: | |
|
1449 | handler(*sys.exc_info()) | |
|
1450 | print('') | |
|
1451 |
General Comments 0
You need to be logged in to leave comments.
Login now