Пример #1
0
def main():  # pragma: no cover
    try:
        args = parse_arguments(*sys.argv[1:])
        schema = yaml.round_trip_load(open(validate.schema_filename()).read())
        source_config = legacy.parse_configuration(
            args.source_config_filename, legacy.CONFIG_FORMAT
        )
        source_config_file_mode = os.stat(args.source_config_filename).st_mode
        source_excludes = (
            open(args.source_excludes_filename).read().splitlines()
            if args.source_excludes_filename
            else []
        )

        destination_config = convert.convert_legacy_parsed_config(
            source_config, source_excludes, schema
        )

        generate.write_configuration(
            args.destination_config_filename, destination_config, mode=source_config_file_mode
        )

        display_result(args)
    except (ValueError, OSError) as error:
        print(error, file=sys.stderr)
        sys.exit(1)
Пример #2
0
def main():  # pragma: no cover
    try:
        args = parse_arguments(*sys.argv[1:])
        schema = yaml.round_trip_load(open(validate.schema_filename()).read())
        source_config = legacy.parse_configuration(
            args.source_config_filename, legacy.CONFIG_FORMAT
        )
        source_config_file_mode = os.stat(args.source_config_filename).st_mode
        source_excludes = (
            open(args.source_excludes_filename).read().splitlines()
            if args.source_excludes_filename
            else []
        )

        destination_config = convert.convert_legacy_parsed_config(
            source_config, source_excludes, schema
        )

        generate.write_configuration(
            args.destination_config_filename,
            generate.render_configuration(destination_config),
            mode=source_config_file_mode,
        )

        display_result(args)
    except (ValueError, OSError) as error:
        print(error, file=sys.stderr)
        sys.exit(1)
Пример #3
0
def test_parse_configuration_should_return_section_configs():
    parser = insert_mock_parser()
    config_format = (flexmock(name='items'), flexmock(name='things'))
    mock_module = flexmock(module)
    mock_module.should_receive('validate_configuration_format').with_args(
        parser, config_format).once()
    mock_section_configs = (flexmock(), flexmock())

    for section_format, section_config in zip(config_format,
                                              mock_section_configs):
        mock_module.should_receive('parse_section_options').with_args(
            parser, section_format).and_return(section_config).once()

    parsed_config = module.parse_configuration('filename', config_format)

    assert parsed_config == type(parsed_config)(*mock_section_configs)
Пример #4
0
def test_parse_configuration_should_return_section_configs():
    parser = insert_mock_parser()
    config_format = (flexmock(name='items'), flexmock(name='things'))
    mock_module = flexmock(module)
    mock_module.should_receive('validate_configuration_format').with_args(
        parser, config_format
    ).once()
    mock_section_configs = (flexmock(), flexmock())

    for section_format, section_config in zip(config_format, mock_section_configs):
        mock_module.should_receive('parse_section_options').with_args(
            parser, section_format
        ).and_return(section_config).once()

    parsed_config = module.parse_configuration('filename', config_format)

    assert parsed_config == type(parsed_config)(*mock_section_configs)
Пример #5
0
def test_parse_configuration_with_file_open_error_should_raise():
    parser = insert_mock_parser()
    parser.should_receive('read').and_return([])

    with pytest.raises(ValueError):
        module.parse_configuration('filename', config_format=flexmock())
Пример #6
0
def test_parse_configuration_with_file_open_error_should_raise():
    parser = insert_mock_parser()
    parser.should_receive('read').and_return([])

    with pytest.raises(ValueError):
        module.parse_configuration('filename', config_format=flexmock())