def test_custom_hud_color(skip_qtbot): cosmetic_patches = PrimeCosmeticPatches(use_hud_color=False) dialog = PrimeCosmeticPatchesDialog(None, cosmetic_patches) skip_qtbot.addWidget(dialog) skip_qtbot.mouseClick(dialog.custom_hud_color, QtCore.Qt.LeftButton) assert dialog.cosmetic_patches == PrimeCosmeticPatches(use_hud_color=True)
def test_qol_cosmetic(skip_qtbot): cosmetic_patches = PrimeCosmeticPatches(qol_cosmetic=False) dialog = PrimeCosmeticPatchesDialog(None, cosmetic_patches) skip_qtbot.addWidget(dialog) skip_qtbot.mouseClick(dialog.qol_cosmetic_check, QtCore.Qt.LeftButton) assert dialog.cosmetic_patches == PrimeCosmeticPatches(qol_cosmetic=True)
def test_force_fusion(skip_qtbot): cosmetic_patches = PrimeCosmeticPatches(force_fusion=True) dialog = PrimeCosmeticPatchesDialog(None, cosmetic_patches) skip_qtbot.addWidget(dialog) skip_qtbot.mouseClick(dialog.force_fusion_check, QtCore.Qt.LeftButton) assert dialog.cosmetic_patches == PrimeCosmeticPatches(force_fusion=False)
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()
def _test_preset(rdvgame_file, expected_results_file, mocker): # Setup description = LayoutDescription.from_file(rdvgame_file) players_config = PlayersConfiguration(0, {0: "Prime", 1: "Echoes"}) cosmetic_patches = PrimeCosmeticPatches(use_hud_color=True, hud_color=(255, 0, 0), suit_color_rotations=(0, 40, 350, 12)) mocker.patch( "randovania.layout.layout_description.LayoutDescription.shareable_hash_bytes", new_callable=PropertyMock, return_value=b"\x00\x00\x00\x00\x00") # Run data = PrimePatchDataFactory(description, players_config, cosmetic_patches).create_data() # Expected Result with expected_results_file.open("r") as file: expected_data = json.load(file) # Uncomment to easily view diff of failed test # with expected_results_file.open("w") as file: # file.write(json.dumps(data, indent=4, separators=(',', ': '))) # Ignore the part of the main menu message which has the randovania version in it data["gameConfig"]["mainMenuMessage"] = data["gameConfig"][ "mainMenuMessage"].split("\n")[1] expected_data["gameConfig"]["mainMenuMessage"] = expected_data[ "gameConfig"]["mainMenuMessage"].split("\n")[1] assert data == expected_data
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, 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() == ""
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 reset(self): self.on_new_cosmetic_patches(PrimeCosmeticPatches())
def test_invalid_tuple_sizes(): with pytest.raises(ValueError): PrimeCosmeticPatches(hud_color=(0, 0, 0, 0)) with pytest.raises(ValueError): PrimeCosmeticPatches(suit_color_rotations=(0, 0, 0))
def test_valid_construction(): PrimeCosmeticPatches(hud_color=(0, 0, 0), suit_color_rotations=(0, 0, 0, 0))