예제 #1
0
def test_unknown_template_type():
    file = Path("temp.txt")

    configuration.write(file, {"data": 1})
    template = {"data": Path}

    with pytest.raises(ValueError):
        configuration.parse(file, template)

    file.unlink()
예제 #2
0
def test_load_bad_data_file():
    file = Path("temp.txt")

    # Make some noise
    with file.open("w") as stream:
        stream.write("\\ # this is a bad file.\n\n\n 42")

    with pytest.raises(ValueError):
        configuration.parse(file)

    file.unlink()
예제 #3
0
def _handle_configuration(args: argparse.Namespace) -> Dict[str, Any]:

    if args.example:
        if args.config:
            configuration.write(args.config, _EXAMPLE)
        else:
            print(yaml.dump(_EXAMPLE))
        sys.exit()

    if args.config.exists():
        return configuration.parse(args.config, _TEMPLATE)
    else:
        raise ValueError(f"{args.conf.name} doesn't exist!")
예제 #4
0
def test_reading_and_writing_configuration_with_minor_issues(file):
    configuration.write(file, LIGHT_ERROR)
    parsed = configuration.parse(file, TEMPLATE)
    check_contents_match(parsed, CONFIGURATION2)
예제 #5
0
def test_reading_and_writing_perfect_configuration(file):
    configuration.write(file, CONFIGURATION1)
    parsed = configuration.parse(file, TEMPLATE)
    check_contents_match(parsed, CONFIGURATION1)
예제 #6
0
def test_uncorrectable_configuration(file):
    configuration.write(file, NOFIX)

    with pytest.raises(ValueError):
        parsed = configuration.parse(file, TEMPLATE)
        check_contents_match(parsed, CONFIGURATION2)
예제 #7
0
def test_reading_and_writing_broken_configuration(file):
    configuration.write(file, HEAVY_ERROR)
    parsed = configuration.parse(file, TEMPLATE)
    check_contents_match(parsed, CONFIGURATION2)