""" Module with tests for ansi filters """ #----------------------------------------------------------------------------- # Copyright (c) 2013, the IPython Development Team. # # Distributed under the terms of the Modified BSD License. # # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- from IPython.utils.coloransi import TermColors from ...tests.base import TestsBase from ..ansi import * #----------------------------------------------------------------------------- # Class #----------------------------------------------------------------------------- class TestAnsi(TestsBase): """Contains test functions for ansi.py""" def test_remove_ansi(self): """ remove_ansi test """ correct_outputs = { '%s%s%s' % (TermColors.Green, TermColors.White, TermColors.Red) : '', 'hello%s' % TermColors.Blue: 'hello', 'he%s%sllo' % (TermColors.Yellow, TermColors.Cyan) : 'hello', '%shello' % TermColors.Blue : 'hello', '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.Red) : 'hello', 'hel%slo' % TermColors.Green : 'hello', 'hello' : 'hello'} for inval, outval in correct_outputs.items(): yield self._try_remove_ansi, inval, outval def _try_remove_ansi(self, inval, outval): assert outval == remove_ansi(inval) def test_ansi2html(self): """ ansi2html test """ correct_outputs = { '%s' % (TermColors.Red) : '', 'hello%s' % TermColors.Blue: 'hello', 'he%s%sllo' % (TermColors.Green, TermColors.Cyan) : 'hello', '%shello' % TermColors.Yellow : 'hello', '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.White) : 'hello', 'hel%slo' % TermColors.Green : 'hello', 'hello' : 'hello'} for inval, outval in correct_outputs.items(): yield self._try_ansi2html, inval, outval def _try_ansi2html(self, inval, outval): assert self.fuzzy_compare(outval, ansi2html(inval)) def test_ansi2latex(self): """ ansi2latex test """ correct_outputs = { '%s' % (TermColors.Red) : r'\red{}', 'hello%s' % TermColors.Blue: r'hello\blue{}', 'he%s%sllo' % (TermColors.Green, TermColors.Cyan) : r'he\green{}\cyan{llo}', '%shello' % TermColors.Yellow : r'\yellow{hello}', '{0}h{0}e{0}l{0}l{0}o{0}'.format(TermColors.White) : r'\white{h}\white{e}\white{l}\white{l}\white{o}\white{}', 'hel%slo' % TermColors.Green : r'hel\green{lo}', 'hello' : 'hello'} for inval, outval in correct_outputs.items(): yield self._try_ansi2latex, inval, outval def _try_ansi2latex(self, inval, outval): assert self.fuzzy_compare(outval, ansi2latex(inval), case_sensitive=True)