def test_round_trip(tmp_path):
    reference = EchoesPerGameOptions(
        cosmetic_patches=RandovaniaGame.METROID_PRIME_ECHOES.data.layout.
        cosmetic_patches.default(),
        input_path=tmp_path.joinpath("input.iso"),
        output_directory=tmp_path.joinpath("output"),
    )

    # Run
    decoded = EchoesPerGameOptions.from_json(reference.as_json)

    # Assert
    assert decoded == reference
def test_on_output_file_button_exists(skip_qtbot, tmp_path, mocker,
                                      has_output_dir):
    # Setup
    mock_prompt = mocker.patch(
        "randovania.gui.lib.common_qt_lib.prompt_user_for_output_file",
        autospec=True)

    if has_output_dir:
        output_directory = tmp_path.joinpath("output_path")
        expected_default_name = str(
            tmp_path.joinpath("output_path", "Echoes Randomizer - MyHash"))
        output_directory.mkdir()
    else:
        output_directory = None
        expected_default_name = "Echoes Randomizer - MyHash"

    options = MagicMock()
    options.options_for_game.return_value = EchoesPerGameOptions(
        cosmetic_patches=EchoesCosmeticPatches.default(),
        output_directory=output_directory,
    )

    window = EchoesGameExportDialog(options, {}, "MyHash", True, [])
    mock_prompt.return_value = tmp_path.joinpath("foo", "game.iso")

    # Run
    skip_qtbot.mouseClick(window.output_file_button, QtCore.Qt.LeftButton)

    # Assert
    mock_prompt.assert_called_once_with(window, expected_default_name + ".iso",
                                        ["iso"])
    assert window.output_file_edit.text() == str(
        tmp_path.joinpath("foo", "game.iso"))
    assert tmp_path.joinpath("foo").is_dir()
示例#3
0
def test_set_options_for_game_with_wrong_type(option: Options):
    # Run
    with pytest.raises(ValueError) as exception:
        option.set_options_for_game(RandovaniaGame.METROID_PRIME, EchoesPerGameOptions(
            cosmetic_patches=RandovaniaGame.METROID_PRIME_ECHOES.data.layout.cosmetic_patches.default(),
        ))

    # Assert
    assert str(exception.value) == (
        "Expected <class 'randovania.games.prime1.exporter.options.PrimePerGameOptions'>, "
        "got <class 'randovania.games.prime2.exporter.options.EchoesPerGameOptions'>"
    )
示例#4
0
def test_get_game_export_params(skip_qtbot, tmp_path, is_echoes_multi, use_external_models):
    # Setup
    games = [RandovaniaGame.METROID_PRIME]
    if is_echoes_multi:
        games.append(RandovaniaGame.METROID_PRIME_ECHOES)
        echoes_path = tmp_path.joinpath("input/echoes.iso")
    else:
        echoes_path = None

    if use_external_models:
        models = {RandovaniaGame.METROID_PRIME_ECHOES}
    else:
        models = {}

    options = MagicMock()
    options.internal_copies_path = tmp_path.joinpath("internal_copies")
    options.options_for_game.side_effect = [PrimePerGameOptions(
        cosmetic_patches=PrimeCosmeticPatches.default(),
        input_path=tmp_path.joinpath("input/game.iso"),
        output_directory=tmp_path.joinpath("output"),
        output_format="iso",
        use_external_models=models,
    ),
        EchoesPerGameOptions(
            cosmetic_patches=EchoesCosmeticPatches.default(),
            input_path=echoes_path
        )]

    expected_backup_path = None
    expected_contents_path = None
    if is_echoes_multi:
        expected_contents_path = tmp_path.joinpath("internal_copies", "prime2", "contents")
        if use_external_models:
            expected_backup_path = tmp_path.joinpath("internal_copies", "prime2", "vanilla")

    window = PrimeGameExportDialog(options, {}, "MyHash", True, games)

    # Run
    result = window.get_game_export_params()

    # Assert
    assert result == PrimeGameExportParams(
        spoiler_output=tmp_path.joinpath("output", "Prime Randomizer - MyHash.rdvgame"),
        input_path=tmp_path.joinpath("input/game.iso"),
        output_path=tmp_path.joinpath("output", "Prime Randomizer - MyHash.iso"),
        echoes_input_path=echoes_path,
        echoes_backup_path=expected_backup_path,
        echoes_contents_path=expected_contents_path,
        asset_cache_path=tmp_path.joinpath("internal_copies", "prime1", "prime2_models"),
        use_echoes_models=is_echoes_multi and use_external_models,
        cache_path=tmp_path.joinpath("internal_copies", "prime1", "randomprime_cache"),
    )
def test_get_game_export_params(skip_qtbot, tmp_path, is_prime_multi,
                                use_external_models):
    # Setup
    games = [RandovaniaGame.METROID_PRIME_ECHOES]
    if is_prime_multi:
        games.append(RandovaniaGame.METROID_PRIME)
        prime_path = tmp_path.joinpath("input/prime.iso")
    else:
        prime_path = None

    if use_external_models:
        models = {RandovaniaGame.METROID_PRIME}
    else:
        models = {}

    options = MagicMock()
    options.internal_copies_path = tmp_path.joinpath("internal_copies")
    options.options_for_game.side_effect = [
        EchoesPerGameOptions(
            cosmetic_patches=EchoesCosmeticPatches.default(),
            input_path=tmp_path.joinpath("input/game.iso"),
            output_directory=tmp_path.joinpath("output"),
            use_external_models=models,
        ),
        PrimePerGameOptions(
            cosmetic_patches=PrimeCosmeticPatches.default(),
            input_path=prime_path,
        )
    ]
    window = EchoesGameExportDialog(options, {}, "MyHash", True, games)

    # Run
    result = window.get_game_export_params()

    # Assert
    assert result == EchoesGameExportParams(
        spoiler_output=tmp_path.joinpath("output",
                                         "Echoes Randomizer - MyHash.rdvgame"),
        input_path=tmp_path.joinpath("input/game.iso"),
        output_path=tmp_path.joinpath("output",
                                      "Echoes Randomizer - MyHash.iso"),
        contents_files_path=tmp_path.joinpath("internal_copies", "prime2",
                                              "contents"),
        backup_files_path=tmp_path.joinpath("internal_copies", "prime2",
                                            "vanilla"),
        asset_cache_path=tmp_path.joinpath("internal_copies", "prime2",
                                           "prime1_models"),
        prime_path=prime_path,
        use_prime_models=is_prime_multi and use_external_models,
    )
def test_on_output_file_button_cancel(skip_qtbot, tmpdir, mocker):
    # Setup
    mock_prompt = mocker.patch(
        "randovania.gui.lib.common_qt_lib.prompt_user_for_output_file",
        autospec=True)

    options = MagicMock()
    options.options_for_game.return_value = EchoesPerGameOptions(
        cosmetic_patches=EchoesCosmeticPatches.default(),
        output_directory=None,
    )
    window = EchoesGameExportDialog(options, {}, "MyHash", True, [])
    mock_prompt.return_value = None

    # Run
    skip_qtbot.mouseClick(window.output_file_button, QtCore.Qt.LeftButton)

    # Assert
    mock_prompt.assert_called_once_with(window,
                                        "Echoes Randomizer - MyHash.iso",
                                        ["iso"])
    assert window.output_file_edit.text() == ""
示例#7
0
def test_on_input_file_button(skip_qtbot, tmp_path, mocker, test_echoes):
    # Setup
    tmp_path.joinpath("existing.iso").write_bytes(b"foo")
    mock_prompt = mocker.patch(
        "randovania.gui.lib.common_qt_lib.prompt_user_for_vanilla_input_file",
        autospec=True,
        side_effect=[
            None,
            tmp_path.joinpath("some/game.iso"),
            tmp_path.joinpath("existing.iso"),
            tmp_path.joinpath("missing_again.iso"),
        ])

    options = MagicMock()
    options.options_for_game.side_effect = [
        PrimePerGameOptions(
            cosmetic_patches=PrimeCosmeticPatches.default(),
            input_path=None,
            output_format="iso",
            use_external_models=[RandovaniaGame.METROID_PRIME_ECHOES]),
        EchoesPerGameOptions(
            cosmetic_patches=EchoesCosmeticPatches.default(),
            input_path=None,
        )
    ]

    games = [RandovaniaGame.METROID_PRIME]
    if test_echoes:
        mocker.patch(
            "randovania.games.prime2.gui.dialog.game_export_dialog.has_internal_copy",
            return_value=False)
        games.append(RandovaniaGame.METROID_PRIME_ECHOES)

    window = PrimeGameExportDialog(options, {}, "MyHash", True, games)

    if test_echoes:
        button = window.echoes_file_button
        file_edit = window.echoes_file_edit
    else:
        button = window.input_file_button
        file_edit = window.input_file_edit

    assert file_edit.text() == ""
    assert file_edit.has_error

    skip_qtbot.mouseClick(button, QtCore.Qt.LeftButton)
    assert file_edit.text() == ""
    assert file_edit.has_error

    skip_qtbot.mouseClick(button, QtCore.Qt.LeftButton)
    assert file_edit.text() == str(tmp_path.joinpath("some/game.iso"))
    assert file_edit.has_error

    skip_qtbot.mouseClick(button, QtCore.Qt.LeftButton)
    assert file_edit.text() == str(tmp_path.joinpath("existing.iso"))
    assert not file_edit.has_error

    skip_qtbot.mouseClick(button, QtCore.Qt.LeftButton)
    assert file_edit.text() == str(tmp_path.joinpath("missing_again.iso"))
    assert file_edit.has_error

    if not test_echoes:
        mock_prompt.assert_has_calls([
            call(window, window.valid_input_file_types, existing_file=None),
            call(window, window.valid_input_file_types, existing_file=None),
            call(window, window.valid_input_file_types, existing_file=None),
            call(window,
                 window.valid_input_file_types,
                 existing_file=tmp_path.joinpath("existing.iso")),
        ])
def test_on_input_file_button(skip_qtbot, tmp_path, mocker):
    # Setup
    tmp_path.joinpath("existing.iso").write_bytes(b"foo")
    mock_prompt = mocker.patch(
        "randovania.gui.lib.common_qt_lib.prompt_user_for_vanilla_input_file",
        autospec=True,
        side_effect=[
            None,
            tmp_path.joinpath("some/game.iso"),
            tmp_path.joinpath("existing.iso"),
            tmp_path.joinpath("missing_again.iso"),
        ])

    options = MagicMock()
    options.internal_copies_path = tmp_path.joinpath("internal_copies")
    options.options_for_game.return_value = EchoesPerGameOptions(
        cosmetic_patches=EchoesCosmeticPatches.default(),
        input_path=None,
    )

    contents_path = tmp_path.joinpath("internal_copies", "prime2", "contents")
    contents_path.mkdir(parents=True)
    mocker.patch("randovania.interface_common.game_workdir.discover_game",
                 side_effect=[
                     ("G2M", 1),
                     None,
                 ])

    window = EchoesGameExportDialog(options, {}, "MyHash", True, [])
    assert window.input_file_edit.text() == "(internal game copy)"
    assert not window.input_file_edit.has_error

    # Deletes the internal data
    skip_qtbot.mouseClick(window.input_file_button, QtCore.Qt.LeftButton)
    assert window.input_file_edit.text() == ""
    assert window.input_file_edit.has_error

    # User cancelled, stays unchanged
    skip_qtbot.mouseClick(window.input_file_button, QtCore.Qt.LeftButton)
    assert window.input_file_edit.text() == ""
    assert window.input_file_edit.has_error

    skip_qtbot.mouseClick(window.input_file_button, QtCore.Qt.LeftButton)
    assert window.input_file_edit.text() == str(
        tmp_path.joinpath("some/game.iso"))
    assert window.input_file_edit.has_error

    skip_qtbot.mouseClick(window.input_file_button, QtCore.Qt.LeftButton)
    assert window.input_file_edit.text() == str(
        tmp_path.joinpath("existing.iso"))
    assert not window.input_file_edit.has_error

    skip_qtbot.mouseClick(window.input_file_button, QtCore.Qt.LeftButton)
    assert window.input_file_edit.text() == str(
        tmp_path.joinpath("missing_again.iso"))
    assert window.input_file_edit.has_error

    mock_prompt.assert_has_calls([
        call(window, ["iso"], existing_file=None),
        call(window, ["iso"], existing_file=None),
        call(window, ["iso"], existing_file=None),
        call(window, ["iso"], existing_file=tmp_path.joinpath("existing.iso")),
    ])