Exemple #1
0
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", "Prime Randomizer - MyHash"))
        output_directory.mkdir()
    else:
        output_directory = None
        expected_default_name = "Prime Randomizer - MyHash"

    options = MagicMock()
    options.options_for_game.return_value = PrimePerGameOptions(
        cosmetic_patches=PrimeCosmeticPatches.default(),
        output_directory=output_directory,
        output_format="iso",
    )

    window = PrimeGameExportDialog(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",
                                        window.valid_output_file_types)
    assert window.output_file_edit.text() == str(
        tmp_path.joinpath("foo", "game.iso"))
    assert tmp_path.joinpath("foo").is_dir()
Exemple #2
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,
    )
Exemple #4
0
def test_on_output_file_button_cancel(skip_qtbot, tmp_path, 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 = PrimePerGameOptions(
        cosmetic_patches=PrimeCosmeticPatches.default(),
        output_directory=None,
        output_format="iso",
    )
    window = PrimeGameExportDialog(options, {}, "MyHash", True, [])
    mock_prompt.return_value = None
    assert window.output_file_edit.text() == ""

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

    # Assert
    mock_prompt.assert_called_once_with(window, "Prime Randomizer - MyHash.iso", window.valid_output_file_types)
    assert window.output_file_edit.text() == ""
Exemple #5
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")),
        ])