def test_invalid_pop(self):
        stack = OutputFormatterStyleStack()
        s1 = OutputFormatterStyle('white', 'black')
        s2 = OutputFormatterStyle('yellow', 'blue')
        stack.push(s1)

        self.assertRaises(Exception, stack.pop, s2)
    def test_pop(self):
        stack = OutputFormatterStyleStack()
        s1 = OutputFormatterStyle('white', 'black')
        s2 = OutputFormatterStyle('yellow', 'blue')
        stack.push(s1)
        stack.push(s2)

        self.assertEqual(s2, stack.pop())
        self.assertEqual(s1, stack.pop())
    def test_init(self):
        style = OutputFormatterStyle('green', 'black', ['bold', 'underscore'])
        self.assertEqual('\033[32;40;1;4mfoo\033[0m', style.apply('foo'))

        style = OutputFormatterStyle('red', None, ['blink'])
        self.assertEqual('\033[31;5mfoo\033[0m', style.apply('foo'))

        style = OutputFormatterStyle(None, 'white')
        self.assertEqual('\033[47mfoo\033[0m', style.apply('foo'))
    def test_push(self):
        stack = OutputFormatterStyleStack()
        s1 = OutputFormatterStyle('white', 'black')
        s2 = OutputFormatterStyle('yellow', 'blue')
        stack.push(s1)
        stack.push(s2)

        self.assertEqual(s2, stack.get_current())

        s3 = OutputFormatterStyle('green', 'red')
        stack.push(s3)

        self.assertEqual(s3, stack.get_current())
Example #5
0
    def test_new_style(self):
        formatter = OutputFormatter(True)

        style = OutputFormatterStyle('blue', 'white')
        formatter.set_style('test', style)

        self.assertEqual(style, formatter.get_style('test'))
        self.assertNotEqual(style, formatter.get_style('info'))

        style = OutputFormatterStyle('blue', 'white')
        formatter.set_style('b', style)

        self.assertEqual(
            '\033[34;47msome \033[0m\033[34;47mcustom\033[0m\033[34;47m msg\033[0m',
            formatter.format('<test>some <b>custom</b> msg</test>'))
Example #6
0
 def test_write_decorated_message(self):
     foo_style = OutputFormatterStyle('yellow', 'red', ['blink'])
     output = MyOutput()
     output.get_formatter().set_style('foo', foo_style)
     output.set_decorated(True)
     output.writeln('<foo>foo</foo>')
     self.assertEqual('\033[33;41;5mfoo\033[0m\n', output.output)
Example #7
0
    def test_redefined_style(self):
        formatter = OutputFormatter(True)

        style = OutputFormatterStyle('blue', 'white')
        formatter.set_style('info', style)

        self.assertEqual('\033[34;47msome custom msg\033[0m',
                         formatter.format('<info>some custom msg</info>'))
    def test_background(self):
        style = OutputFormatterStyle()

        style.set_background('black')
        self.assertEqual('\033[40mfoo\033[0m', style.apply('foo'))

        style.set_background('yellow')
        self.assertEqual('\033[43mfoo\033[0m', style.apply('foo'))

        self.assertRaises(Exception, style.set_background, 'undefined-color')
    def test_foreground(self):
        style = OutputFormatterStyle()

        style.set_foreground('black')
        self.assertEqual('\033[30mfoo\033[0m', style.apply('foo'))

        style.set_foreground('blue')
        self.assertEqual('\033[34mfoo\033[0m', style.apply('foo'))

        self.assertRaises(Exception, style.set_foreground, 'undefined-color')
Example #10
0
    def test_init(self):
        style = OutputFormatterStyle('green', 'black', ['bold', 'underscore'])
        self.assertEqual('\033[32;40;1;4mfoo\033[0m', style.apply('foo'))

        style = OutputFormatterStyle('red', None, ['blink'])
        self.assertEqual('\033[31;5mfoo\033[0m', style.apply('foo'))

        style = OutputFormatterStyle(None, 'white')
        self.assertEqual('\033[47mfoo\033[0m', style.apply('foo'))
Example #11
0
    def test_background(self):
        style = OutputFormatterStyle()

        style.set_background('black')
        self.assertEqual('\033[40mfoo\033[0m', style.apply('foo'))

        style.set_background('yellow')
        self.assertEqual('\033[43mfoo\033[0m', style.apply('foo'))

        self.assertRaises(
            Exception,
            style.set_background,
            'undefined-color'
        )
Example #12
0
    def test_foreground(self):
        style = OutputFormatterStyle()

        style.set_foreground('black')
        self.assertEqual('\033[30mfoo\033[0m', style.apply('foo'))

        style.set_foreground('blue')
        self.assertEqual('\033[34mfoo\033[0m', style.apply('foo'))

        self.assertRaises(
            Exception,
            style.set_foreground,
            'undefined-color'
        )
Example #13
0
    def test_options(self):
        style = OutputFormatterStyle()

        style.set_options(['reverse', 'conceal'])
        self.assertEqual('\033[7;8mfoo\033[0m', style.apply('foo'))

        style.set_option('bold')
        self.assertEqual('\033[7;8;1mfoo\033[0m', style.apply('foo'))

        style.unset_option('reverse')
        self.assertEqual('\033[8;1mfoo\033[0m', style.apply('foo'))

        style.set_option('bold')
        self.assertEqual('\033[8;1mfoo\033[0m', style.apply('foo'))

        style.set_options(['bold'])
        self.assertEqual('\033[1mfoo\033[0m', style.apply('foo'))

        self.assertRaisesRegexp(
            Exception,
            'Invalid option specified: "foo"',
            style.set_option,
            'foo'
        )

        self.assertRaisesRegexp(
            Exception,
            'Invalid option specified: "foo"',
            style.unset_option,
            'foo'
        )
Example #14
0
    def test_options(self):
        style = OutputFormatterStyle()

        style.set_options(['reverse', 'conceal'])
        self.assertEqual('\033[7;8mfoo\033[0m', style.apply('foo'))

        style.set_option('bold')
        self.assertEqual('\033[7;8;1mfoo\033[0m', style.apply('foo'))

        style.unset_option('reverse')
        self.assertEqual('\033[8;1mfoo\033[0m', style.apply('foo'))

        style.set_option('bold')
        self.assertEqual('\033[8;1mfoo\033[0m', style.apply('foo'))

        style.set_options(['bold'])
        self.assertEqual('\033[1mfoo\033[0m', style.apply('foo'))

        self.assertRaisesRegexp(Exception, 'Invalid option specified: "foo"',
                                style.set_option, 'foo')

        self.assertRaisesRegexp(Exception, 'Invalid option specified: "foo"',
                                style.unset_option, 'foo')