Example #1
0
def load_builtin_config(config):
    stdout_builder = TransformerBuilder()
    errors = []
    ConfigLoader(stdout_builder=stdout_builder,
                 stderr_builder=DummyTransformerBuilder(),
                 paths=['rainbow/config/builtin'],
                 error_handler=errors.append) \
        .load_config_by_name(config, )
    return stdout_builder.build(), errors
Example #2
0
def load_builtin_config(config):
    stdout_builder = TransformerBuilder()
    errors = []
    ConfigLoader(stdout_builder=stdout_builder,
                 stderr_builder=DummyTransformerBuilder(),
                 paths=['rainbow/config/builtin'],
                 error_handler=errors.append) \
        .load_config_by_name(config)
    return stdout_builder.build(), errors
Example #3
0
def test_command_with_short_option_filter(filter):
    (command, errors) = parse(['-' + filter.short_option, 'test', 'true'])
    assert not errors
    assert isinstance(command, ExecuteCommand)
    assert command.args == ['true']
    transformer = TransformerBuilder.make_transformer(re.compile('test'),
                                                      filter)
    assert command.stdout_transformer == transformer
    assert command.stderr_transformer == transformer
Example #4
0
def test_command_with_option_remaining_args_separator_with_long_option_filter(
        filter):
    (command, errors) = parse(
        ['--' + filter.long_option, 'test', '--', 'true', '--option'])
    assert not errors
    assert isinstance(command, ExecuteCommand)
    assert command.args == ['true', '--option']
    transformer = TransformerBuilder.make_transformer(re.compile('test'),
                                                      filter)
    assert command.stdout_transformer == transformer
    assert command.stderr_transformer == transformer
Example #5
0
def load_from_command_line(args):
    stdout_builder = TransformerBuilder()
    stderr_builder = TransformerBuilder()
    errors = []

    ConfigLoader(stdout_builder=stdout_builder,
                 stderr_builder=stderr_builder,
                 paths=['tests/data/cfg'],
                 error_handler=errors.append) \
        .load_config_from_command_line(args)

    return stdout_builder.build(), stderr_builder.build(), errors
Example #6
0
def load_by_name(config):
    stdout_builder = TransformerBuilder()
    stderr_builder = TransformerBuilder()
    errors = []

    ConfigLoader(stdout_builder=stdout_builder,
                 stderr_builder=stderr_builder,
                 paths=['tests/data/cfg'],
                 error_handler=errors.append) \
        .load_config_by_name(config)

    return stdout_builder.build(), stderr_builder.build(), errors
Example #7
0
def parse(config):
    stdout_builder = TransformerBuilder()
    stderr_builder = TransformerBuilder()
    errors = []

    ConfigParser(stdout_builder=stdout_builder,
                 stderr_builder=stderr_builder,
                 paths=None,
                 error_handler=errors.append) \
        .parse_file(config)

    return stdout_builder.build(), stderr_builder.build(), errors
Example #8
0
def test_transformer_builder():
    builder = TransformerBuilder()
    builder.add_mapping("test1", FILTERS_BY_NAME['foreground-red'])
    builder.add_mapping("test2", FILTERS_BY_NAME['background-green-before'])
    builder.add_mapping("test3", FILTERS_BY_NAME['foreground-yellow-after'])
    transformer = builder.build()
    assert isinstance(transformer, ListTransformer)
    assert isinstance(transformer.transformers[0],
                      InsertBeforeAndAfterRegexTransformer)
    assert transformer.transformers[0].regex.pattern == 'test1'
    assert transformer.transformers[0].before == ansi.ANSI_FOREGROUND_RED
    assert transformer.transformers[0].after == ansi.ANSI_FOREGROUND_RESET
    assert isinstance(transformer.transformers[1],
                      InsertBeforeRegexTransformer)
    assert transformer.transformers[1].regex.pattern == 'test2'
    assert transformer.transformers[1].before == ansi.ANSI_BACKGROUND_GREEN
    assert isinstance(transformer.transformers[2], InsertAfterRegexTransformer)
    assert transformer.transformers[2].regex.pattern == 'test3'
    assert transformer.transformers[2].after == ansi.ANSI_FOREGROUND_YELLOW
Example #9
0
def test_transformer_builder():
    builder = TransformerBuilder()
    builder.add_mapping("test1", FILTERS_BY_NAME['foreground-red'])
    builder.add_mapping("test2", FILTERS_BY_NAME['background-green-before'])
    builder.add_mapping("test3", FILTERS_BY_NAME['foreground-yellow-after'])
    transformer = builder.build()
    assert isinstance(transformer, ListTransformer)
    assert isinstance(transformer.transformers[0], InsertBeforeAndAfterRegexTransformer)
    assert transformer.transformers[0].regex.pattern == 'test1'
    assert transformer.transformers[0].before == ansi.ANSI_FOREGROUND_RED
    assert transformer.transformers[0].after == ansi.ANSI_FOREGROUND_RESET
    assert isinstance(transformer.transformers[1], InsertBeforeRegexTransformer)
    assert transformer.transformers[1].regex.pattern == 'test2'
    assert transformer.transformers[1].before == ansi.ANSI_BACKGROUND_GREEN
    assert isinstance(transformer.transformers[2], InsertAfterRegexTransformer)
    assert transformer.transformers[2].regex.pattern == 'test3'
    assert transformer.transformers[2].after == ansi.ANSI_FOREGROUND_YELLOW
Example #10
0
def test_filter_long_option(filter):
    (command, errors) = parse(['--' + filter.long_option, 'test'])
    assert not errors
    assert isinstance(command, STDINCommand)
    assert command.transformer == TransformerBuilder.make_transformer(
        re.compile('test'), filter)
Example #11
0
def test_config_file_by_relative_path_without_extension_long_option():
    (command, errors) = parse(['--config', u'tests/data/cfg/config006'])
    assert not errors
    assert isinstance(command, STDINCommand)
    assert command.transformer == TransformerBuilder.make_transformer(
        re.compile(u'ERROR'), FILTERS_BY_NAME['foreground-red'])