Esempio n. 1
0
def test_colorize_text_calls_all_sub_methods():
    """colorize_text should call all of the helper colorize methods."""
    with patch('eg.color.EgColorizer.colorize_heading',
               return_value='text-heading') as heading:
        with patch('eg.color.EgColorizer.colorize_block_indent',
                   return_value='text-heading-indent') as indent:
            with patch(
                    'eg.color.EgColorizer.colorize_backticks',
                    return_value='text-heading-indent-backticks') as backticks:
                colorizer = color.EgColorizer(None)
                text = 'text'
                actual = colorizer.colorize_text(text)
                heading.assert_called_once_with(text)
                indent.assert_called_once_with('text-heading')
                backticks.assert_called_once_with('text-heading-indent')
                assert_equal('text-heading-indent-backticks', actual)
Esempio n. 2
0
def test_colorize_heading():
    """Makes sure we colorize things like '# find' correctly"""
    color_config = config.ColorConfig('P', 'H', _YELLOW, _MAGENTA, _BLACK,
                                      'RES', 'RES', '', '', '')

    clean = get_clean_find_file()

    raw_file = get_raw_find_test_file()
    target = get_data_with_subs(raw_file,
                                pound=color_config.pound,
                                pound_reset=color_config.pound_reset,
                                heading=color_config.heading,
                                heading_reset=color_config.heading_reset)

    colorizer = color.EgColorizer(color_config)

    actual = colorizer.colorize_heading(clean)

    assert_equal(actual, target)
Esempio n. 3
0
def test_colorize_backticks():
    """Makes sure we colorize backticks correctly."""
    color_config = config.ColorConfig(_BLACK, _MAGENTA, _YELLOW, 'B', _GREEN,
                                      '', '', '', 'res', '')

    clean = get_clean_find_file()

    raw_file = get_raw_find_test_file()
    target = get_data_with_subs(
        raw_file,
        backticks=color_config.backticks,
        backticks_reset=color_config.backticks_reset,
    )

    colorizer = color.EgColorizer(color_config)

    actual = colorizer.colorize_backticks(clean)

    assert_equal(actual, target)
Esempio n. 4
0
def test_colorize_block_indents():
    """Makes sure we colorize block indents correctly."""
    color_config = config.ColorConfig(_BLACK, _MAGENTA, 'C', _YELLOW, 'P', '',
                                      '', 'res', '', 'res')

    clean = get_clean_find_file()

    raw_file = get_raw_find_test_file()
    target = get_data_with_subs(raw_file,
                                code=color_config.code,
                                code_reset=color_config.code_reset,
                                prompt=color_config.prompt,
                                prompt_reset=color_config.prompt_reset)

    colorizer = color.EgColorizer(color_config)

    actual = colorizer.colorize_block_indent(clean)

    assert_equal(actual, target)
Esempio n. 5
0
File: util.py Progetto: moyiz/eg
def open_pager_for_file(default_file_path=None,
                        custom_file_path=None,
                        use_color=False,
                        color_config=None,
                        pager_cmd=None):
    """
    Open pager to file_path. If a custom_file_path is also included, it will be
    shown before file_path in the same pager.
    """
    file_data = ''

    if custom_file_path:
        file_data += _get_contents_of_file(custom_file_path)

    if default_file_path:
        file_data += _get_contents_of_file(default_file_path)

    if use_color:
        colorizer = color.EgColorizer(color_config)
        file_data = colorizer.colorize_text(file_data)

    page_string(file_data, pager_cmd)
Esempio n. 6
0
def get_colorized_contents(contents, color_config):
    """Colorize the contents based on the color_config."""
    colorizer = color.EgColorizer(color_config)
    result = colorizer.colorize_text(contents)
    return result