Пример #1
0
 def test_role_case(self):
     self.assertEqual(
         parse_color_setting('ERROR=green'),
         dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'}))
     self.assertEqual(
         parse_color_setting('eRrOr=green'),
         dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'}))
Пример #2
0
 def test_bad_option(self):
     self.assertEqual(
         parse_color_setting('error=green,unknown'),
         dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'}))
     self.assertEqual(
         parse_color_setting('error=green,unknown,blink'),
         dict(PALETTES[NOCOLOR_PALETTE],
              ERROR={
                  'fg': 'green',
                  'opts': ('blink', )
              }))
Пример #3
0
 def test_empty_options(self):
     self.assertEqual(
         parse_color_setting('error=green,'),
         dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'}))
     self.assertEqual(
         parse_color_setting('error=green,,,'),
         dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'}))
     self.assertEqual(
         parse_color_setting('error=green,,blink,,'),
         dict(PALETTES[NOCOLOR_PALETTE],
              ERROR={
                  'fg': 'green',
                  'opts': ('blink', )
              }))
Пример #4
0
 def test_opts_case(self):
     self.assertEqual(
         parse_color_setting('error=green,BLINK'),
         dict(PALETTES[NOCOLOR_PALETTE],
              ERROR={
                  'fg': 'green',
                  'opts': ('blink', )
              }))
     self.assertEqual(
         parse_color_setting('error=green,bLiNk'),
         dict(PALETTES[NOCOLOR_PALETTE],
              ERROR={
                  'fg': 'green',
                  'opts': ('blink', )
              }))
Пример #5
0
 def test_fg_opts(self):
     self.assertEqual(
         parse_color_setting('error=green,blink'),
         dict(PALETTES[NOCOLOR_PALETTE],
              ERROR={
                  'fg': 'green',
                  'opts': ('blink', )
              }))
     self.assertEqual(
         parse_color_setting('error=green,bold,blink'),
         dict(PALETTES[NOCOLOR_PALETTE],
              ERROR={
                  'fg': 'green',
                  'opts': ('blink', 'bold')
              }))
Пример #6
0
def make_style(config_string=''):
    """
    Create a Style object from the given config_string.

    If config_string is empty djmodels.utils.termcolors.DEFAULT_PALETTE is used.
    """

    style = Style()

    color_settings = termcolors.parse_color_setting(config_string)

    # The nocolor palette has all available roles.
    # Use that palette as the basis for populating
    # the palette as defined in the environment.
    for role in termcolors.PALETTES[termcolors.NOCOLOR_PALETTE]:
        if color_settings:
            format = color_settings.get(role, {})
            style_func = termcolors.make_style(**format)
        else:

            def style_func(x):
                return x

        setattr(style, role, style_func)

    # For backwards compatibility,
    # set style for ERROR_OUTPUT == ERROR
    style.ERROR_OUTPUT = style.ERROR

    return style
Пример #7
0
 def test_fg_bg(self):
     self.assertEqual(
         parse_color_setting('error=green/blue'),
         dict(PALETTES[NOCOLOR_PALETTE],
              ERROR={
                  'fg': 'green',
                  'bg': 'blue'
              }))
Пример #8
0
 def test_bad_color(self):
     self.assertIsNone(parse_color_setting('error='))
     self.assertEqual(
         parse_color_setting('error=;sql_field=blue'),
         dict(PALETTES[NOCOLOR_PALETTE], SQL_FIELD={'fg': 'blue'}))
     self.assertIsNone(parse_color_setting('error=unknown'))
     self.assertEqual(
         parse_color_setting('error=unknown;sql_field=blue'),
         dict(PALETTES[NOCOLOR_PALETTE], SQL_FIELD={'fg': 'blue'}))
     self.assertEqual(
         parse_color_setting('error=green/unknown'),
         dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'}))
     self.assertEqual(
         parse_color_setting('error=green/blue/something'),
         dict(PALETTES[NOCOLOR_PALETTE],
              ERROR={
                  'fg': 'green',
                  'bg': 'blue'
              }))
     self.assertEqual(
         parse_color_setting('error=green/blue/something,blink'),
         dict(PALETTES[NOCOLOR_PALETTE],
              ERROR={
                  'fg': 'green',
                  'bg': 'blue',
                  'opts': ('blink', )
              }))
Пример #9
0
 def test_color_case(self):
     self.assertEqual(
         parse_color_setting('error=GREEN'),
         dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'}))
     self.assertEqual(
         parse_color_setting('error=GREEN/BLUE'),
         dict(PALETTES[NOCOLOR_PALETTE],
              ERROR={
                  'fg': 'green',
                  'bg': 'blue'
              }))
     self.assertEqual(
         parse_color_setting('error=gReEn'),
         dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'}))
     self.assertEqual(
         parse_color_setting('error=gReEn/bLuE'),
         dict(PALETTES[NOCOLOR_PALETTE],
              ERROR={
                  'fg': 'green',
                  'bg': 'blue'
              }))
Пример #10
0
 def test_empty_definition(self):
     self.assertIsNone(parse_color_setting(';'))
     self.assertEqual(parse_color_setting('light;'),
                      PALETTES[LIGHT_PALETTE])
     self.assertIsNone(parse_color_setting(';;;'))
Пример #11
0
 def test_multiple_roles(self):
     self.assertEqual(
         parse_color_setting('error=green;sql_field=blue'),
         dict(PALETTES[NOCOLOR_PALETTE],
              ERROR={'fg': 'green'},
              SQL_FIELD={'fg': 'blue'}))
Пример #12
0
 def test_override_with_multiple_roles(self):
     self.assertEqual(
         parse_color_setting('light;error=green;sql_field=blue'),
         dict(PALETTES[LIGHT_PALETTE],
              ERROR={'fg': 'green'},
              SQL_FIELD={'fg': 'blue'}))
Пример #13
0
 def test_override_nocolor(self):
     self.assertEqual(
         parse_color_setting('nocolor;error=green'),
         dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'}))
Пример #14
0
 def test_reverse_override(self):
     self.assertEqual(parse_color_setting('error=green;light'),
                      PALETTES[LIGHT_PALETTE])
Пример #15
0
 def test_override_palette(self):
     self.assertEqual(parse_color_setting('light;error=green'),
                      dict(PALETTES[LIGHT_PALETTE], ERROR={'fg': 'green'}))
Пример #16
0
 def test_bad_palette(self):
     self.assertIsNone(parse_color_setting('unknown'))
Пример #17
0
 def test_bad_role(self):
     self.assertIsNone(parse_color_setting('unknown='))
     self.assertIsNone(parse_color_setting('unknown=green'))
     self.assertEqual(
         parse_color_setting('unknown=green;sql_field=blue'),
         dict(PALETTES[NOCOLOR_PALETTE], SQL_FIELD={'fg': 'blue'}))
Пример #18
0
 def test_empty_string(self):
     self.assertEqual(parse_color_setting(''), PALETTES[DEFAULT_PALETTE])
Пример #19
0
 def test_simple_palette(self):
     self.assertEqual(parse_color_setting('light'), PALETTES[LIGHT_PALETTE])
     self.assertEqual(parse_color_setting('dark'), PALETTES[DARK_PALETTE])
     self.assertIsNone(parse_color_setting('nocolor'))