From 978a79692a76e454a5d68820df5793629b281656 2015-11-12 17:19:25 From: Matthias Bussonnier Date: 2015-11-12 17:19:25 Subject: [PATCH] Move ultratb test to be run on CI. --- diff --git a/IPython/core/tests/test_ultratb.py b/IPython/core/tests/test_ultratb.py index 2d0a493..5f5dec0 100644 --- a/IPython/core/tests/test_ultratb.py +++ b/IPython/core/tests/test_ultratb.py @@ -2,10 +2,14 @@ """Tests for IPython.core.ultratb """ import io +import sys import os.path from textwrap import dedent +import traceback import unittest +from ..ultratb import ColorTB, VerboseTB + from IPython.testing import tools as tt from IPython.testing.decorators import onlyif_unicode_paths @@ -220,3 +224,48 @@ except Exception: with tt.AssertNotPrints("ZeroDivisionError"), \ tt.AssertPrints("ValueError", suppress=False): ip.run_cell(self.SUPPRESS_CHAINING_CODE) + + +#---------------------------------------------------------------------------- + +# module testing (minimal) +def test_handlers(): + def spam(c, d_e): + (d, e) = d_e + x = c + d + y = c * d + foo(x, y) + + def foo(a, b, bar=1): + eggs(a, b + bar) + + def eggs(f, g, z=globals()): + h = f + g + i = f - g + return h / i + + buff = io.StringIO() + + buff.write(u'') + buff.write(u'*** Before ***') + try: + buff.write(spam(1, (2, 3))) + except: + traceback.print_exc(file=buff) + + handler = ColorTB(ostream=buff) + buff.write(u'*** ColorTB ***') + try: + buff.write(spam(1, (2, 3))) + except: + handler(*sys.exc_info()) + buff.write(u'') + + handler = VerboseTB(ostream=buff) + buff.write(u'*** VerboseTB ***') + try: + buff.write(spam(1, (2, 3))) + except: + handler(*sys.exc_info()) + buff.write(u'') + diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index 639635e..52656a1 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -1326,9 +1326,9 @@ class AutoFormattedTB(FormattedTB): class ColorTB(FormattedTB): """Shorthand to initialize a FormattedTB in Linux colors mode.""" - def __init__(self, color_scheme='Linux', call_pdb=0): + def __init__(self, color_scheme='Linux', call_pdb=0, **kwargs): FormattedTB.__init__(self, color_scheme=color_scheme, - call_pdb=call_pdb) + call_pdb=call_pdb, **kwargs) class SyntaxTB(ListTB): @@ -1405,47 +1405,3 @@ def eqrepr(value, repr=text_repr): def nullrepr(value, repr=text_repr): return '' - - -#---------------------------------------------------------------------------- - -# module testing (minimal) -if __name__ == "__main__": - def spam(c, d_e): - (d, e) = d_e - x = c + d - y = c * d - foo(x, y) - - def foo(a, b, bar=1): - eggs(a, b + bar) - - def eggs(f, g, z=globals()): - h = f + g - i = f - g - return h / i - - print('') - print('*** Before ***') - try: - print(spam(1, (2, 3))) - except: - traceback.print_exc() - print('') - - handler = ColorTB() - print('*** ColorTB ***') - try: - print(spam(1, (2, 3))) - except: - handler(*sys.exc_info()) - print('') - - handler = VerboseTB() - print('*** VerboseTB ***') - try: - print(spam(1, (2, 3))) - except: - handler(*sys.exc_info()) - print('') -