def test_allow_list_keys_are_not_change_checksums():
    with pytest.raises(InvalidAllowlist, match='All keys must be a valid md5 checksum'):
        read_allowed_changes(json.dumps(
            {
                '1e3b776bda2dd8b11804e7341bb8b2d1': 'md5 checksum key',
                'bad key': 'some message'
            }
        ))
def test_read_from_valid_json():
    original = """{
            "1e3b776bda2dd8b11804e7341bb8b2d1": "lorem",
            "1234776bda2dd8b11804e7341bb8b2d1": "ipsum"
    }"""
    assert read_allowed_changes(original) == json.loads(original) == {
        "1e3b776bda2dd8b11804e7341bb8b2d1": "lorem",
        "1234776bda2dd8b11804e7341bb8b2d1": "ipsum",
    }
def main(args) -> int:
    # Load schemas from file path args
    old_schema = SchemaLoader.from_sdl(args.old_schema.read())
    new_schema = SchemaLoader.from_sdl(args.new_schema.read())
    args.old_schema.close()
    args.new_schema.close()

    diff = Schema(old_schema, new_schema).diff()
    restricted = evaluate_rules(diff, args.validation_rules)
    if args.allow_list:
        allow_list = args.allow_list.read()
        args.allow_list.close()
        allowed_changes = read_allowed_changes(allow_list)
        diff = [change for change in diff if change.checksum() not in allowed_changes]
    if args.as_json:
        print_json(diff)
    else:
        print_diff(diff)

    return exit_code(diff, args.strict, restricted, args.tolerant)
def test_read_from_invalid_json():
    with pytest.raises(InvalidAllowlist, match='Invalid json format provided.'):
        read_allowed_changes("")
def test_allow_list_is_not_a_mapping():
    with pytest.raises(InvalidAllowlist, match='Allowlist must be a mapping.'):
        read_allowed_changes("[]")