Ejemplo n.º 1
0
def test_process_buffer_rule_group(capsys):
    """Output processing with a group-specific rule."""
    config = chromaterm.config.get_default_config()
    rule = {'regex': 'hello (world)', 'color': {1: 'b#fffaaa'}}

    config['rules'].append(chromaterm.config.parse_rule(rule))
    data = 'test hello world test'
    success = r'^test hello \x1b\[48;5;[0-9]{1,3}mworld\x1b\[49m test$'

    chromaterm.process_buffer(config, data, False)
    captured = capsys.readouterr()

    assert re.search(success, captured.out)
Ejemplo n.º 2
0
def test_process_buffer_rule_multiple_colors(capsys):
    """Output processing with a multi-color rule."""
    config = chromaterm.config.get_default_config()
    rule = {'regex': 'hello', 'color': 'b#fffaaa f#aaafff'}

    config['rules'].append(chromaterm.config.parse_rule(rule))
    data = 'hello world'
    success = r'^(\x1b\[[34]8;5;[0-9]{1,3}m){2}hello(\x1b\[[34]9m){2} world$'

    chromaterm.process_buffer(config, data, False)
    captured = capsys.readouterr()

    assert re.search(success, captured.out)
Ejemplo n.º 3
0
def test_process_buffer_rule_simple(capsys):
    """Output processing with a simple rule."""
    config = chromaterm.config.get_default_config()
    rule = {'regex': 'hello world', 'color': 'b#fffaaa'}

    config['rules'].append(chromaterm.config.parse_rule(rule))
    data = 'test hello world test\n'
    success = r'^test \x1b\[48;5;\d{1,3}mhello world\x1b\[49m test$'

    chromaterm.process_buffer(config, data, False)
    captured = capsys.readouterr()

    assert re.search(success, captured.out)
Ejemplo n.º 4
0
def test_process_buffer_multiline(capsys):
    """Output processing with multiple lines of input."""
    config = chromaterm.config.get_default_config()
    rule = {'regex': 'hello world', 'color': 'b#fffaaa'}

    config['rules'].append(chromaterm.config.parse_rule(rule))
    data = '\ntest hello world test\n'
    success = r'^test \x1b\[[34]8;5;[0-9]{1,3}mhello world\x1b\[49m test$'

    chromaterm.process_buffer(config, data * 2, False)
    captured = capsys.readouterr()

    for line in [x for x in captured.out.splitlines() if x]:
        assert re.search(success, line)
Ejemplo n.º 5
0
def test_process_buffer_more_single_character(capsys):
    """Output processing when more data is hinted and input is a single
    character. The output should not highlighted as it's possibly typing."""
    try:
        config = chromaterm.config.get_default_config()
        rule = {'regex': 't', 'color': 'b#fffaaa'}
        pipe_r, pipe_w = os.pipe()

        config['read_fd'] = pipe_r
        config['rules'].append(chromaterm.config.parse_rule(rule))
        data = 't'
        success = r'^t$'

        chromaterm.process_buffer(config, data, True)
        captured = capsys.readouterr()

        assert re.search(success, captured.out)
    finally:
        os.close(pipe_r)
        os.close(pipe_w)
Ejemplo n.º 6
0
def test_process_buffer_more_multiple_characters(capsys):
    """Output processing when more data is hinted and input is multiple
    characters. The output should be highlighted as it isn't typing."""
    try:
        config = chromaterm.config.get_default_config()
        rule = {'regex': 'hello world', 'color': 'b#fffaaa'}
        pipe_r, pipe_w = os.pipe()

        config['read_fd'] = pipe_r
        config['rules'].append(chromaterm.config.parse_rule(rule))
        data = 'test hello world test'
        success = r'^test \x1b\[48;5;\d{1,3}mhello world\x1b\[49m test$'

        chromaterm.process_buffer(config, data, True)
        captured = capsys.readouterr()

        assert re.search(success, captured.out)
    finally:
        os.close(pipe_r)
        os.close(pipe_w)
Ejemplo n.º 7
0
def test_process_buffer_more(capsys):
    """Output processing of empty input."""
    config = chromaterm.config.get_default_config()
    chromaterm.process_buffer(config, '', False)
    assert capsys.readouterr().out == ''