Ejemplo n.º 1
0
 def test_colorizer_changes_colorizable_types(self, _, value):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
     })
     self.assertEqual(
         ColorizedObject(Mark(value, 'a'), ('[', ']')),
         colorizer.colorize(Mark(value, 'a')),
     )
Ejemplo n.º 2
0
 def test_colorizer_changes_colorizable_types(self, _, value):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
     })
     self.assertEqual(
         ColorizedObject(Mark(value, 'a'), ('[', ']')),
         colorizer.colorize(Mark(value, 'a')),
     )
Ejemplo n.º 3
0
 def test_colorizer_changes_colorizable_types_with_tags(self, _, value):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
         'b': ('<', '>'),
     })
     self.assertEqual(
         ColorizedObject(Mark(value, ['a', 'b']), ('[<', '>]')),
         colorizer.colorize(Mark(value, ['a', 'b'])),
     )
Ejemplo n.º 4
0
 def test_colorizer_get_color_pair_not_found_with_default(self):
     colorizer = Colorizer(
         {
             'a': ('[', ']'),
             'b': ('<', '>'),
         },
         default_color_tag='b',
     )
     self.assertEqual(('<', '>'), colorizer.get_color_pair(color_tag=['c']))
Ejemplo n.º 5
0
 def test_colorizer_get_color_pair_found_with_context(self):
     colorizer = Colorizer({
         'a': ('[', ']'),
         'b': ('<', '>'),
     }, )
     self.assertEqual(
         ('><[', ']><'),
         colorizer.get_color_pair(color_tag=['a'], context_color_tag='b'),
     )
Ejemplo n.º 6
0
 def test_colorizer_changes_colorizable_types_with_tags(self, _, value):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
         'b': ('<', '>'),
     })
     self.assertEqual(
         ColorizedObject(Mark(value, ['a', 'b']), ('[<', '>]')),
         colorizer.colorize(Mark(value, ['a', 'b'])),
     )
Ejemplo n.º 7
0
 def test_colorizer_get_color_pair_found_double(self):
     colorizer = Colorizer({
         'a': ('[', ']'),
         'b': ('<', '>'),
     })
     self.assertEqual(
         ('[<', '>]'),
         colorizer.get_color_pair(color_tag=['a', 'b']),
     )
Ejemplo n.º 8
0
 def test_colorizer_doesnt_colorize_with_unknown_color_tag(self):
     colorizer = Colorizer(color_map={
         'my_tag': ('START_MARK', 'STOP_MARK'),
     }, )
     result = colorizer.colorize(Mark('hello', color_tag='my_unknown_tag'))
     self.assertEqual(
         ColorizedObject(Mark('hello', 'my_unknown_tag'), ('', '')),
         result,
     )
Ejemplo n.º 9
0
 def test_colorizer_get_color_pair_not_found_with_default(self):
     colorizer = Colorizer(
         {
             'a': ('[', ']'),
             'b': ('<', '>'),
         },
         default_color_tag='b',
     )
     self.assertEqual(('<', '>'), colorizer.get_color_pair(color_tag=['c']))
Ejemplo n.º 10
0
 def test_colorizer_get_color_pair_found_double(self):
     colorizer = Colorizer({
         'a': ('[', ']'),
         'b': ('<', '>'),
     })
     self.assertEqual(
         ('[<', '>]'),
         colorizer.get_color_pair(color_tag=['a', 'b']),
     )
Ejemplo n.º 11
0
 def test_colorizer_changes_colorizable_types_with_context(self, _, value):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
         'b': ('<', '>'),
     })
     self.assertEqual(
         ColorizedObject(Mark(value, 'a'), ('><[', ']><')),
         colorizer.colorize(Mark(value, 'a'), context_color_tag='b'),
     )
Ejemplo n.º 12
0
 def test_colorizer_changes_colorizable_types_with_context(self, _, value):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
         'b': ('<', '>'),
     })
     self.assertEqual(
         ColorizedObject(Mark(value, 'a'), ('><[', ']><')),
         colorizer.colorize(Mark(value, 'a'), context_color_tag='b'),
     )
Ejemplo n.º 13
0
 def test_colorizer_get_color_pair_found_with_context(self):
     colorizer = Colorizer(
         {
             'a': ('[', ']'),
             'b': ('<', '>'),
         },
     )
     self.assertEqual(
         ('><[', ']><'),
         colorizer.get_color_pair(color_tag=['a'], context_color_tag='b'),
     )
Ejemplo n.º 14
0
 def test_colorizer_doesnt_colorize_with_unknown_color_tag(self):
     colorizer = Colorizer(
         color_map={
             'my_tag': ('START_MARK', 'STOP_MARK'),
         },
     )
     result = colorizer.colorize(Mark('hello', color_tag='my_unknown_tag'))
     self.assertEqual(
         ColorizedObject(Mark('hello', 'my_unknown_tag'), ('', '')),
         result,
     )
Ejemplo n.º 15
0
 def test_colorizer_changes_colorizable_types_with_tags_and_context(
     self,
     _,
     value,
 ):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
         'b': ('(', ')'),
         'c': ('<', '>'),
     })
     self.assertEqual(
         ColorizedObject(Mark(value, ['a', 'b']), ('><[(', ')]><')),
         colorizer.colorize(Mark(value, ['a', 'b']), context_color_tag='c'),
     )
Ejemplo n.º 16
0
 def test_colorizer_get_color_pair_found_with_list_context(self):
     colorizer = Colorizer(
         {
             'a': ('[', ']'),
             'b': ('<', '>'),
             'c': ('(', ')'),
         }, )
     self.assertEqual(
         (')><([', '])><('),
         colorizer.get_color_pair(
             color_tag=['a'],
             context_color_tag=['b', 'c'],
         ),
     )
Ejemplo n.º 17
0
 def test_colorizer_changes_colorizable_types_with_tags_and_context(
     self,
     _,
     value,
 ):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
         'b': ('(', ')'),
         'c': ('<', '>'),
     })
     self.assertEqual(
         ColorizedObject(Mark(value, ['a', 'b']), ('><[(', ')]><')),
         colorizer.colorize(Mark(value, ['a', 'b']), context_color_tag='c'),
     )
Ejemplo n.º 18
0
 def test_colorize_message(self):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
         'b': ('(', ')'),
     })
     message = '{}-{}_{a}~{b}'
     args = [42, Mark(42, ['a', 'b'])]
     kwargs = {
         'a': 0,
         'b': Mark(0, ['b', 'a']),
     }
     self.assertEqual(
         '42-[(42)]_0~([0])',
         colorizer.colorize_message(message, *args, **kwargs),
     )
Ejemplo n.º 19
0
 def test_colorize_message(self):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
         'b': ('(', ')'),
     })
     message = '{0}-{1}_{a}~{b}'
     args = [42, Mark(42, ['a', 'b'])]
     kwargs = {
         'a': 0,
         'b': Mark(0, ['b', 'a']),
     }
     self.assertEqual(
         '42-[(42)]_0~([0])',
         colorizer.colorize_message(message, *args, **kwargs),
     )
Ejemplo n.º 20
0
 def test_colorizer_get_color_pair_found_with_list_context(self):
     colorizer = Colorizer(
         {
             'a': ('[', ']'),
             'b': ('<', '>'),
             'c': ('(', ')'),
         },
     )
     self.assertEqual(
         (')><([', '])><('),
         colorizer.get_color_pair(
             color_tag=['a'],
             context_color_tag=['b', 'c'],
         ),
     )
Ejemplo n.º 21
0
 def test_colorize_message_with_context(self):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
         'b': ('(', ')'),
         'c': ('<', '>'),
     })
     message = Mark('{0}-{1}_{a}~{b}', 'c')
     args = [42, Mark(42, ['a', 'b'])]
     kwargs = {
         'a': 0,
         'b': Mark(0, ['b', 'a']),
     }
     self.assertEqual(
         '<42-><[(42)]><_0~><([0])><>',
         colorizer.colorize_message(message, *args, **kwargs),
     )
Ejemplo n.º 22
0
 def test_colorize_message_with_context(self):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
         'b': ('(', ')'),
         'c': ('<', '>'),
     })
     message = Mark('{}-{}_{a}~{b}', 'c')
     args = [42, Mark(42, ['a', 'b'])]
     kwargs = {
         'a': 0,
         'b': Mark(0, ['b', 'a']),
     }
     self.assertEqual(
         '<42-><[(42)]><_0~><([0])><>',
         colorizer.colorize_message(message, *args, **kwargs),
     )
Ejemplo n.º 23
0
 def test_colorizer_colorizes_with_unknown_color_tag_and_default(self):
     colorizer = Colorizer(
         color_map={
             'my_tag': ('START_MARK', 'STOP_MARK'),
             'default': ('START_DEFAULT_MARK', 'STOP_DEFAULT_MARK')
         },
         default_color_tag='default',
     )
     result = colorizer.colorize(Mark('hello', color_tag='my_unknown_tag'))
     self.assertEqual(
         ColorizedObject(
             Mark(
                 'hello',
                 'my_unknown_tag',
             ),
             (
                 'START_DEFAULT_MARK',
                 'STOP_DEFAULT_MARK',
             ),
         ),
         result,
     )
Ejemplo n.º 24
0
 def test_colorizer_colorizes_with_unknown_color_tag_and_default(self):
     colorizer = Colorizer(
         color_map={
             'my_tag': ('START_MARK', 'STOP_MARK'),
             'default': ('START_DEFAULT_MARK', 'STOP_DEFAULT_MARK')
         },
         default_color_tag='default',
     )
     result = colorizer.colorize(Mark('hello', color_tag='my_unknown_tag'))
     self.assertEqual(
         ColorizedObject(
             Mark(
                 'hello',
                 'my_unknown_tag',
             ),
             (
                 'START_DEFAULT_MARK',
                 'STOP_DEFAULT_MARK',
             ),
         ),
         result,
     )
Ejemplo n.º 25
0
    def __init__(self, stream, colorizer=Colorizer()):
        """
        Initialize the :class:`StreamDisplay`.

        :param stream: The stream to be attached too.
        """
        super(StreamDisplay, self).__init__()
        self.colorizer = colorizer
        self.output_map = {}

        if stream_has_color_support(stream):
            self.stream = AnsiToWin32(stream).stream
        else:
            self.stream = stream

        # Python 3 differentiates binary streams.
        if hasattr(stream, 'buffer'):
            self.binary_stream = stream.buffer
        else:
            self.binary_stream = stream
Ejemplo n.º 26
0
 def test_colorizer_get_color_pair_not_found(self):
     colorizer = Colorizer({})
     self.assertEqual(('', ''), colorizer.get_color_pair(color_tag=['a']))
Ejemplo n.º 27
0
 def test_colorizer_converts_unknown_types(self, _, value):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
         'b': ('<', '>'),
     })
     self.assertEqual(ColorizedObject(value), colorizer.colorize(value))
Ejemplo n.º 28
0
 def test_colorizer_get_color_pair_found(self):
     colorizer = Colorizer({
         'a': ('[', ']'),
     })
     self.assertEqual(('[', ']'), colorizer.get_color_pair(color_tag=['a']))
Ejemplo n.º 29
0
 def test_colorizer_converts_unknown_types(self, _, value):
     colorizer = Colorizer(color_map={
         'a': ('[', ']'),
         'b': ('<', '>'),
     })
     self.assertEqual(ColorizedObject(value), colorizer.colorize(value))
Ejemplo n.º 30
0
 def test_colorizer_get_color_pair_not_found(self):
     colorizer = Colorizer({})
     self.assertEqual(('', ''), colorizer.get_color_pair(color_tag=['a']))
Ejemplo n.º 31
0
 def test_colorizer_get_color_pair_found(self):
     colorizer = Colorizer({
         'a': ('[', ']'),
     })
     self.assertEqual(('[', ']'), colorizer.get_color_pair(color_tag=['a']))