Exemplo n.º 1
0
def test_round_trip_node_conflict(test_files_dir):
    with test_files_dir.joinpath("prime2_small_v1.json").open(
            "r") as data_file:
        json_data = json.load(data_file)

    json_data["worlds"][0]["areas"][0]["nodes"].append(
        dict(json_data["worlds"][0]["areas"][0]["nodes"][0]))

    with pytest.raises(ValueError):
        game_migration.migrate_to_current(json_data)
Exemplo n.º 2
0
def decode_data_with_world_reader(
        data: Dict) -> Tuple[WorldReader, GameDescription]:
    data = game_migration.migrate_to_current(copy.deepcopy(data))

    game = RandovaniaGame(data["game"])

    resource_database = read_resource_database(game, data["resource_database"])
    dock_weakness_database = read_dock_weakness_database(
        data["dock_weakness_database"], resource_database)

    layers = frozen_lib.wrap(data["layers"])
    world_reader = WorldReader(resource_database, dock_weakness_database)
    world_list = world_reader.read_world_list(data["worlds"])

    victory_condition = read_requirement(data["victory_condition"],
                                         resource_database)
    starting_location = AreaIdentifier.from_json(data["starting_location"])
    initial_states = read_initial_states(data["initial_states"],
                                         resource_database)
    minimal_logic = read_minimal_logic_db(data["minimal_logic"])

    return world_reader, GameDescription(
        game=game,
        resource_database=resource_database,
        layers=layers,
        dock_weakness_database=dock_weakness_database,
        world_list=world_list,
        victory_condition=victory_condition,
        starting_location=starting_location,
        initial_states=initial_states,
        minimal_logic=minimal_logic,
    )
def test_round_trip_small(test_files_dir):
    # Setup
    with test_files_dir.joinpath("prime2_small_v1.json").open("r") as data_file:
        original_data = game_migration.migrate_to_current(json.load(data_file))

    game = data_reader.decode_data(original_data)

    encoded_data = data_writer.write_game_description(game)
    assert encoded_data == original_data
Exemplo n.º 4
0
def test_complex_decode(test_files_dir):
    # Run
    decoded_data = binary_data.decode_file_path(
        Path(test_files_dir.joinpath("prime_data_as_binary.bin")))

    # Assert
    with test_files_dir.joinpath("prime_data_as_json.json").open(
            "r") as data_file:
        saved_data = json.load(data_file)
    saved_data = game_migration.migrate_to_current(saved_data)

    assert decoded_data == saved_data
Exemplo n.º 5
0
def test_complex_encode(test_files_dir):
    with test_files_dir.joinpath("prime_data_as_json.json").open(
            "r") as data_file:
        data = json.load(data_file)

    data = game_migration.migrate_to_current(data)

    b = io.BytesIO()

    # Run
    binary_data.encode(data, b)
    # # Whenever the file format changes, we can use the following line to force update our test file
    # test_files_dir.joinpath("prime_data_as_binary.bin").write_bytes(b.getvalue()); assert False

    # Assert
    assert test_files_dir.joinpath(
        "prime_data_as_binary.bin").read_bytes() == b.getvalue()