Exemplo n.º 1
0
def test_bad_option():
    res_1 = parse_color_setting('error=green,unknown')
    res_2 = parse_color_setting('error=green,unknown,blink')

    assert res_1 == dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'})
    assert res_2 == dict(PALETTES[NOCOLOR_PALETTE],
                         ERROR={
                             'fg': 'green',
                             'opts': ('blink', )
                         })
Exemplo n.º 2
0
def test_empty_options():
    res_1 = parse_color_setting('error=green,')
    res_2 = parse_color_setting('error=green,,,')
    res_3 = parse_color_setting('error=green,,blink,,')

    assert res_1 == dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'})
    assert res_2 == dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'})
    assert res_3 == dict(PALETTES[NOCOLOR_PALETTE],
                         ERROR={
                             'fg': 'green',
                             'opts': ('blink', )
                         })
Exemplo n.º 3
0
def test_opts_case():
    res_1 = parse_color_setting('error=green,BLINK')
    res_2 = parse_color_setting('error=green,bLiNk')

    assert res_1 == dict(PALETTES[NOCOLOR_PALETTE],
                         ERROR={
                             'fg': 'green',
                             'opts': ('blink', )
                         })
    assert res_2 == dict(PALETTES[NOCOLOR_PALETTE],
                         ERROR={
                             'fg': 'green',
                             'opts': ('blink', )
                         })
Exemplo n.º 4
0
def test_fg_opts():
    res_green_blink = parse_color_setting('error=green,blink')
    res_green_bold_blink = parse_color_setting('error=green,bold,blink')

    assert res_green_blink == dict(PALETTES[NOCOLOR_PALETTE],
                                   ERROR={
                                       'fg': 'green',
                                       'opts': ('blink', )
                                   })
    assert res_green_bold_blink == dict(PALETTES[NOCOLOR_PALETTE],
                                        ERROR={
                                            'fg': 'green',
                                            'opts': ('blink', 'bold')
                                        })
Exemplo n.º 5
0
def test_fg_bg():
    res = parse_color_setting('error=green/blue')
    assert res == dict(PALETTES[NOCOLOR_PALETTE],
                       ERROR={
                           'fg': 'green',
                           'bg': 'blue'
                       })
Exemplo n.º 6
0
def make_style(config_string=''):
    """
    Create a Style object from the given config_string.
    If config_string is empty django.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
Exemplo n.º 7
0
def test_color_case():
    res_1 = parse_color_setting('error=GREEN')
    res_2 = parse_color_setting('error=GREEN/BLUE')
    res_3 = parse_color_setting('error=gReEn')
    res_4 = parse_color_setting('error=gReEn/bLuE')

    assert res_1 == dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'})
    assert res_2 == dict(PALETTES[NOCOLOR_PALETTE],
                         ERROR={
                             'fg': 'green',
                             'bg': 'blue'
                         })
    assert res_3 == dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'})
    assert res_4 == dict(PALETTES[NOCOLOR_PALETTE],
                         ERROR={
                             'fg': 'green',
                             'bg': 'blue'
                         })
Exemplo n.º 8
0
def test_bad_color():
    res_1 = parse_color_setting('error=;sql_field=blue')
    res_2 = parse_color_setting('error=unknown;sql_field=blue')
    res_3 = parse_color_setting('error=green/unknown')
    res_4 = parse_color_setting('error=green/blue/something')
    res_5 = parse_color_setting('error=green/blue/something,blink')

    assert res_1 == dict(PALETTES[NOCOLOR_PALETTE], SQL_FIELD={'fg': 'blue'})
    assert res_2 == dict(PALETTES[NOCOLOR_PALETTE], SQL_FIELD={'fg': 'blue'})
    assert res_3 == dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'})
    assert res_4 == dict(PALETTES[NOCOLOR_PALETTE],
                         ERROR={
                             'fg': 'green',
                             'bg': 'blue'
                         })
    assert res_5 == dict(PALETTES[NOCOLOR_PALETTE],
                         ERROR={
                             'fg': 'green',
                             'bg': 'blue',
                             'opts': ('blink', )
                         })
    assert parse_color_setting('error=') is None
    assert parse_color_setting('error=unknown') is None
Exemplo n.º 9
0
def test_empty_definition():
    assert parse_color_setting(';') is None
    assert parse_color_setting(';;;') is None
    assert parse_color_setting('light;') == PALETTES[LIGHT_PALETTE]
Exemplo n.º 10
0
def test_override_with_multiple_roles():
    res = parse_color_setting('light;error=green;sql_field=blue')

    assert res == dict(PALETTES[LIGHT_PALETTE],
                       ERROR={'fg': 'green'},
                       SQL_FIELD={'fg': 'blue'})
Exemplo n.º 11
0
def test_multiple_roles():
    res = parse_color_setting('error=green;sql_field=blue')

    assert res == dict(PALETTES[NOCOLOR_PALETTE],
                       ERROR={'fg': 'green'},
                       SQL_FIELD={'fg': 'blue'})
Exemplo n.º 12
0
def test_reverse_override():
    assert parse_color_setting('error=green;light') == PALETTES[LIGHT_PALETTE]
Exemplo n.º 13
0
def test_override_nocolor():
    res = parse_color_setting('nocolor;error=green')

    assert res == dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'})
Exemplo n.º 14
0
def test_override_palette():
    res = parse_color_setting('light;error=green')

    assert res == dict(PALETTES[LIGHT_PALETTE], ERROR={'fg': 'green'})
Exemplo n.º 15
0
def test_empty_string():
    assert parse_color_setting('') == PALETTES[DEFAULT_PALETTE]
Exemplo n.º 16
0
def test_bad_palette():
    assert parse_color_setting('unknown') is None
Exemplo n.º 17
0
def test_bad_role():
    res_1 = parse_color_setting('unknown=green;sql_field=blue')

    assert res_1 == dict(PALETTES[NOCOLOR_PALETTE], SQL_FIELD={'fg': 'blue'})
    assert parse_color_setting('unknown=') is None
    assert parse_color_setting('unknown=green') is None
Exemplo n.º 18
0
def test_role_case():
    res_1 = parse_color_setting('ERROR=green')
    res_2 = parse_color_setting('eRrOr=green')

    assert res_1 == dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'})
    assert res_2 == dict(PALETTES[NOCOLOR_PALETTE], ERROR={'fg': 'green'})
Exemplo n.º 19
0
def test_simple_palette():
    assert parse_color_setting('light') == PALETTES[LIGHT_PALETTE]
    assert parse_color_setting('dark') == PALETTES[DARK_PALETTE]
    assert parse_color_setting('nocolor') is None