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
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
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
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
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
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
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
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
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
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)
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'])