def test_create_hints_all_starting(hide_area: bool, multiworld: bool, empty_patches, echoes_game_description): # Setup players_config = PlayersConfiguration(0, { 0: "you", 1: "them" } if multiworld else {0: "you"}) area_namer = {0: None, 1: None} if multiworld else {0: None} patches = empty_patches.assign_extra_initial_items({ echoes_game_description.resource_database.get_item( echoes_items.SKY_TEMPLE_KEY_ITEMS[key]): 1 for key in range(9) }) expected = [ { "asset_id": 0xD97685FE, "strings": make_starting_stk_hint(1) }, { "asset_id": 0x32413EFD, "strings": make_starting_stk_hint(2) }, { "asset_id": 0xDD8355C3, "strings": make_starting_stk_hint(3) }, { "asset_id": 0x3F5F4EBA, "strings": make_starting_stk_hint(4) }, { "asset_id": 0xD09D2584, "strings": make_starting_stk_hint(5) }, { "asset_id": 0x3BAA9E87, "strings": make_starting_stk_hint(6) }, { "asset_id": 0xD468F5B9, "strings": make_starting_stk_hint(7) }, { "asset_id": 0x2563AE34, "strings": make_starting_stk_hint(8) }, { "asset_id": 0xCAA1C50A, "strings": make_starting_stk_hint(9) }, ] # Run result = sky_temple_key_hint.create_hints( {0: patches}, players_config, echoes_game_description.resource_database, area_namer, hide_area) # Assert assert result == expected
def test_update_content(skip_qtbot, test_files_dir): # Setup description = LayoutDescription.from_file(test_files_dir.joinpath("log_files", "seed_a.rdvgame")) tab = TranslatorGateDetailsTab(None, RandovaniaGame.METROID_PRIME_ECHOES) # Run tab.update_content( description.get_preset(0).configuration, description.all_patches, PlayersConfiguration(0, {0: "You"}), ) # Assert counts = {} for i in range(tab.tree_widget.topLevelItemCount()): item = tab.tree_widget.topLevelItem(i) counts[item.text(0)] = item.childCount() assert counts == { 'Agon Wastes': 2, 'Great Temple': 3, 'Sanctuary Fortress': 2, 'Temple Grounds': 7, 'Torvus Bog': 3, }
def test_patcher_data_logic(mocker): mock_from_file: MagicMock = mocker.patch( "randovania.layout.layout_description.LayoutDescription.from_file") mock_json = mocker.patch("json.dumps", autospec=True) args = MagicMock() layout_description = mock_from_file.return_value preset = MagicMock() layout_description.player_count = 4 layout_description.get_preset = MagicMock(return_value=preset) players_config = PlayersConfiguration(args.player_index, { 0: "Player 1", 1: "Player 2", 2: "Player 3", 3: "Player 4", }) cosmetic_patches = preset.game.data.layout.cosmetic_patches.default.return_value # Run patcher_data.patcher_data_command_logic(args) # Assert preset.game.data.layout.cosmetic_patches.default.assert_called_once_with() preset.game.patch_data_factory.assert_called_once_with( layout_description, players_config, cosmetic_patches) mock_json.assert_called_once_with( preset.game.patch_data_factory.return_value.create_data.return_value, indent=4, )
def test_game_session_admin_player_patcher_file(mock_layout_description: PropertyMock, mock_create_patcher_file: MagicMock, flask_app, clean_database): user1 = database.User.create(id=1234, name="The Name") user2 = database.User.create(id=1235, name="Brother") session = database.GameSession.create(id=1, name="Debug", state=GameSessionState.IN_PROGRESS, creator=user1) database.GameSessionPreset.create(session=session, row=0, preset="{}") database.GameSessionPreset.create(session=session, row=1, preset="{}") database.GameSessionPreset.create(session=session, row=2, preset="{}") database.GameSessionMembership.create(user=user1, session=session, row=2, admin=False) database.GameSessionMembership.create(user=user2, session=session, row=1, admin=False) sio = MagicMock() sio.get_current_user.return_value = user1 cosmetic = CosmeticPatches(open_map=False) # Run with flask_app.test_request_context(): result = game_session.game_session_admin_player(sio, 1, 1234, "create_patcher_file", cosmetic.as_json) # Assert mock_create_patcher_file.assert_called_once_with( mock_layout_description.return_value, PlayersConfiguration(2, { 0: "Player 1", 1: "Brother", 2: "The Name", }), cosmetic ) assert result is mock_create_patcher_file.return_value
def test_multi_create_pickup_data_for_self(pickup_for_create_pickup_data): # Setup solo = pickup_exporter.PickupExporterSolo( pickup_exporter.GenericAcquiredMemo()) creator = pickup_exporter.PickupExporterMulti( solo, MagicMock(), PlayersConfiguration(0, { 0: "You", 1: "Someone" })) model = MagicMock() resource_a = ItemResourceInfo(1, "A", "A", 10, None) resource_b = ItemResourceInfo(2, "B", "B", 10, None) # Run data = creator.create_details( PickupIndex(10), PickupTarget(pickup_for_create_pickup_data, 0), pickup_for_create_pickup_data, PickupModelStyle.ALL_VISIBLE, "Scan Text", model) # Assert assert data == pickup_exporter.ExportedPickupDetails( index=PickupIndex(10), scan_text="Your Scan Text", hud_text=['A acquired!', 'B acquired!'], conditional_resources=[ ConditionalResources("A", None, ((resource_a, 1), )), ConditionalResources("B", resource_a, ((resource_b, 1), )), ], conversion=[], model=model, )
def test_create_message_for_hint_relative_area(echoes_game_patches, blank_pickup, players_config, echoes_hint_exporter, offset, distance_text): patches = echoes_game_patches.assign_new_pickups([ (PickupIndex(5), PickupTarget(blank_pickup, 0)), ]) hint = Hint( HintType.LOCATION, PrecisionPair(HintLocationPrecision.RELATIVE_TO_AREA, HintItemPrecision.DETAILED, include_owner=False, relative=RelativeDataArea( offset, AreaIdentifier("Torvus Bog", "Great Bridge"), HintRelativeAreaName.NAME)), PickupIndex(5)) namer = EchoesHintNamer({0: patches}, PlayersConfiguration(0, {0: "You"})) exporter = HintExporter(namer, random.Random(0), ["A Joke"]) # Run result = exporter.create_message_for_hint(hint, {0: patches}, players_config, True) # Assert assert result == ( f'The &push;&main-color=#FF6705B3;Blank Pickup&pop; can be found ' f'&push;&main-color=#FF3333;{distance_text} {10 + (offset or 0)} rooms&pop; away from ' f'Torvus Bog - Great Bridge.')
def test_multi_create_pickup_data_for_other(pickup_for_create_pickup_data): # Setup multi = ItemResourceInfo(10, "Multiworld", "Multiworld", 30, None) solo = pickup_exporter.PickupExporterSolo( pickup_exporter.GenericAcquiredMemo()) creator = pickup_exporter.PickupExporterMulti( solo, multi, PlayersConfiguration(0, { 0: "You", 1: "Someone" })) model = MagicMock() resource_a = ItemResourceInfo(1, "A", "A", 10, None) resource_b = ItemResourceInfo(2, "B", "B", 10, None) # Run data = creator.create_details( PickupIndex(10), PickupTarget(pickup_for_create_pickup_data, 1), pickup_for_create_pickup_data, PickupModelStyle.ALL_VISIBLE, "Scan Text", model) # Assert assert data == pickup_exporter.ExportedPickupDetails( index=PickupIndex(10), scan_text="Someone's Scan Text", hud_text=['Sent Cake to Someone!'], conditional_resources=[ ConditionalResources(None, None, ((multi, 11), )), ], conversion=[], model=model, )
def test_create_hints_item_dark_temple_keys_cross_game( blank_pickup, echoes_resource_database, echoes_game_patches, default_echoes_configuration, prime_game_patches, default_prime_configuration, ): # Setup players_config = PlayersConfiguration( player_index=0, player_names={ 0: "Player 1", 1: "Player 2", }, ) keys = [ dataclasses.replace( blank_pickup, progression=((echoes_resource_database.get_item(item), 1), )) for item in echoes_items.DARK_TEMPLE_KEY_ITEMS[1] ] echoes_patches = dataclasses.replace( echoes_game_patches, configuration=default_echoes_configuration, pickup_assignment={ PickupIndex(14): PickupTarget(keys[0], 0), PickupIndex(80): PickupTarget(keys[2], 0), }) prime_patches = dataclasses.replace( prime_game_patches, configuration=default_prime_configuration, pickup_assignment={ PickupIndex(23): PickupTarget(keys[1], 0), }) hint = Hint(HintType.RED_TEMPLE_KEY_SET, None, dark_temple=HintDarkTemple.TORVUS_BOG) namer = EchoesHintNamer({ 0: echoes_patches, 1: prime_patches }, players_config) exporter = HintExporter(namer, random.Random(0), ["A Joke"]) # Run result = exporter.create_message_for_hint(hint, { 0: echoes_patches, 1: prime_patches }, players_config, True) # Assert assert result == ( 'The keys to &push;&main-color=#FF6705B3;Dark Torvus Temple&pop; can be found ' 'in &push;&main-color=#FF3333;Chozo Ruins&pop;, ' '&push;&main-color=#FF3333;Dark Torvus Bog&pop; and ' '&push;&main-color=#FF3333;Temple Grounds&pop;.')
def test_create_message_for_hint_relative_item(echoes_game_patches, blank_pickup, players_config, distance_precise, distance_text, reference_precision, reference_name): patches = echoes_game_patches.assign_new_pickups([ (PickupIndex(5), PickupTarget(blank_pickup, 0)), (PickupIndex(15), PickupTarget( dataclasses.replace(blank_pickup, name="Reference Pickup"), 0)), ]) hint = Hint( HintType.LOCATION, PrecisionPair(HintLocationPrecision.RELATIVE_TO_INDEX, HintItemPrecision.DETAILED, include_owner=False, relative=RelativeDataItem(distance_precise, PickupIndex(15), reference_precision)), PickupIndex(5)) namer = EchoesHintNamer({0: patches}, PlayersConfiguration(0, {0: "You"})) exporter = HintExporter(namer, random.Random(0), ["A Joke"]) # Run result = exporter.create_message_for_hint(hint, {0: patches}, players_config, True) # Assert assert result == ( f'The &push;&main-color=#FF6705B3;Blank Pickup&pop; can be found ' f'&push;&main-color=#FF3333;{distance_text} {7 + (distance_precise or 0)} ' f'rooms&pop; away from {reference_name}.')
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 work(progress_update: ProgressUpdateCallable): num_updaters = 2 if input_file is not None: num_updaters += 1 updaters = status_update_lib.split_progress_update(progress_update, num_updaters) if input_file is not None: simplified_patcher.unpack_iso(input_iso=input_file, options=options, progress_update=updaters[0]) # Apply Layout simplified_patcher.apply_layout(layout=layout, players_config=PlayersConfiguration( player_index=player_index, player_names=player_names, ), options=options, progress_update=updaters[-2]) # Pack ISO simplified_patcher.pack_iso(output_iso=output_file, options=options, progress_update=updaters[-1]) if has_spoiler and auto_save_spoiler: layout.save_to_file(output_file.with_suffix(f".{LayoutDescription.file_extension()}")) progress_update(f"Finished!", 1)
def test_multi_create_pickup_data_for_other(pickup_for_create_pickup_data): # Setup creator = patcher_file.PickupCreatorMulti( MagicMock(), patcher_file._SimplifiedMemo(), PlayersConfiguration(0, { 0: "You", 1: "Someone" })) # Run data = creator.create_pickup_data( PickupIndex(10), PickupTarget(pickup_for_create_pickup_data, 1), pickup_for_create_pickup_data, PickupModelStyle.ALL_VISIBLE, "Scan Text") # Assert assert data == { 'conditional_resources': [], 'convert': [], 'hud_text': ['Sent Cake to Someone!'], 'resources': [ { 'amount': 11, 'index': 74 }, ], 'scan': "Someone's Scan Text", }
def _create_patch_data(test_files_dir, mocker, in_file, out_file, cosmetic): # Setup f = test_files_dir.joinpath("log_files", "cave_story", f"{in_file}.rdvgame") description = LayoutDescription.from_file(f) players_config = PlayersConfiguration(0, {0: "Cave Story"}) mocker.patch( "randovania.layout.layout_description.LayoutDescription.shareable_hash_bytes", new_callable=PropertyMock, return_value=b'\x00\x00\x00\x00\x00') # Run data = CSPatchDataFactory(description, players_config, cosmetic).create_data() # Expected Result # strip mychar to just the filename rather than full path if data["mychar"] is not None: mychar = Path(data["mychar"]) data["mychar"] = mychar.name # Uncomment the following lines to update: # with test_files_dir.joinpath("caver_expected_data", f"{out_file}.json").open("w") as f: # json.dump(data, f) with test_files_dir.joinpath("caver_expected_data", f"{out_file}.json").open("r") as f: expected_data = json.load(f) assert data == expected_data
def test_create_string_patches( mock_stk_create_hints: MagicMock, mock_stk_hide_hints: MagicMock, mock_item_create_hints: MagicMock, mock_logbook_title_string_patches: MagicMock, stk_mode: SkyTempleKeyHintMode, mocker, ): # Setup game = MagicMock() all_patches = MagicMock() rng = MagicMock() mock_item_create_hints.return_value = ["item", "hints"] mock_stk_create_hints.return_value = ["show", "hints"] mock_stk_hide_hints.return_value = ["hide", "hints"] player_config = PlayersConfiguration(0, {0: "you"}) mock_logbook_title_string_patches.return_values = [] mock_area_namer: MagicMock = mocker.patch( "randovania.games.prime.patcher_file_lib.hint_lib.AreaNamer") # Run result = claris_patcher_file._create_string_patches( HintConfiguration(sky_temple_keys=stk_mode), game, all_patches, {0: RandovaniaGame.PRIME2}, player_config, rng, ) # Assert expected_result = ["item", "hints"] mock_item_create_hints.assert_called_once_with(all_patches, player_config, game.world_list, rng) mock_logbook_title_string_patches.assert_called_once_with() if stk_mode == SkyTempleKeyHintMode.DISABLED: mock_stk_hide_hints.assert_called_once_with() mock_stk_create_hints.assert_not_called() expected_result.extend(["hide", "hints"]) else: mock_stk_create_hints.assert_called_once_with( all_patches, player_config, game.resource_database, {0: mock_area_namer.return_value}, stk_mode == SkyTempleKeyHintMode.HIDE_AREA) mock_stk_hide_hints.assert_not_called() mock_area_namer.assert_called_once_with(ANY) expected_result.extend(["show", "hints"]) assert result == expected_result
def test_create_hints_item_location(echoes_game_patches, blank_pickup, item, location, owner, is_multiworld, echoes_game_description, monkeypatch): # Setup asset_id = 1000 pickup_index = PickupIndex(50) logbook_node, _, world_list = _create_world_list(asset_id, pickup_index) monkeypatch.setattr(echoes_game_description, "world_list", world_list) players_config = PlayersConfiguration( player_index=0, player_names={ i: f"Player {i + 1}" for i in range(int(is_multiworld) + 1) }, ) location_precision, determiner, item_name = item if owner and is_multiworld: determiner = "&push;&main-color=#d4cc33;Player 1&pop;'s" patches = dataclasses.replace( echoes_game_patches, pickup_assignment={ pickup_index: PickupTarget(blank_pickup, 0), }, hints={ world_list.identifier_for_node(logbook_node): Hint( HintType.LOCATION, PrecisionPair(location[0], location_precision, include_owner=owner), pickup_index, ) }) rng = MagicMock() namer = EchoesHintNamer({0: patches}, players_config) # Run result = hints.create_patches_hints({0: patches}, players_config, world_list, namer, rng) # Assert message = "{} {} can be found in {}.".format(determiner, item_name, location[1]) # message = "The Flying Ing Cache in {} contains {}.".format(location[1], item[1]) assert result[0]['strings'][0] == message assert result == [{ 'asset_id': asset_id, 'strings': [message, '', message] }]
def test_generate_patcher_data(test_files_dir): # Setup description = LayoutDescription.from_file( test_files_dir.joinpath("log_files", "seed_a.rdvgame")) player_index = 0 preset = description.get_preset(player_index) cosmetic_patches = EchoesCosmeticPatches() assert isinstance(preset.configuration, EchoesConfiguration) # Run result = patch_data_factory.generate_patcher_data( description, PlayersConfiguration(player_index, {0: "you"}), cosmetic_patches) # Assert assert isinstance(result["spawn_point"], dict) assert isinstance(result["pickups"], list) assert len(result["pickups"]) == 119 assert isinstance(result["elevators"], list) assert len(result["elevators"]) == 22 assert isinstance(result["translator_gates"], list) assert len(result["translator_gates"]) == 17 assert isinstance(result["string_patches"], list) assert len(result["string_patches"]) == 61 assert result["specific_patches"] == { "hive_chamber_b_post_state": True, "intro_in_post_state": True, "warp_to_start": preset.configuration.warp_to_start, "credits_length": 75 if cosmetic_patches.speed_up_credits else 259, "disable_hud_popup": cosmetic_patches.disable_hud_popup, "pickup_map_icons": cosmetic_patches.pickup_markers, "full_map_at_start": cosmetic_patches.open_map, "dark_world_varia_suit_damage": preset.configuration.varia_suit_damage, "dark_world_dark_suit_damage": preset.configuration.dark_suit_damage, "always_up_gfmc_compound": True, "always_up_torvus_temple": True, "always_up_great_temple": False, 'hud_color': None, } # TODO: check all fields? assert result["dol_patches"]["default_items"] == { "visor": "Combat Visor", "beam": "Power Beam", }
def test_hide_hints(empty_patches): # Setup expected = [ { "asset_id": 0xD97685FE, "strings": make_useless_stk_hint(1) }, { "asset_id": 0x32413EFD, "strings": make_useless_stk_hint(2) }, { "asset_id": 0xDD8355C3, "strings": make_useless_stk_hint(3) }, { "asset_id": 0x3F5F4EBA, "strings": make_useless_stk_hint(4) }, { "asset_id": 0xD09D2584, "strings": make_useless_stk_hint(5) }, { "asset_id": 0x3BAA9E87, "strings": make_useless_stk_hint(6) }, { "asset_id": 0xD468F5B9, "strings": make_useless_stk_hint(7) }, { "asset_id": 0x2563AE34, "strings": make_useless_stk_hint(8) }, { "asset_id": 0xCAA1C50A, "strings": make_useless_stk_hint(9) }, ] namer = EchoesHintNamer({0: empty_patches}, PlayersConfiguration(0, {})) # Run result = randovania.games.prime2.exporter.hints.hide_stk_hints(namer) # Assert assert result == expected
def test_create_patch_data(test_files_dir, mocker): # Setup file = test_files_dir.joinpath("log_files", "dread_1.rdvgame") description = LayoutDescription.from_file(file) players_config = PlayersConfiguration(0, {0: "Dread"}) cosmetic_patches = DreadCosmeticPatches() # Run data = DreadPatchDataFactory(description, players_config, cosmetic_patches).create_data() # Expected Result with test_files_dir.joinpath("dread_expected_data.json").open("r") as file: expected_data = json.load(file) assert data == expected_data
async def test_export_iso(skip_qtbot, mocker): # Setup mock_execute_dialog = mocker.patch("randovania.gui.lib.async_dialog.execute_dialog", new_callable=AsyncMock, return_value=QtWidgets.QDialog.Accepted) options = MagicMock() options.output_directory = None window_manager = MagicMock() window = GameDetailsWindow(window_manager, options) skip_qtbot.addWidget(window) window.layout_description = MagicMock() window._player_names = {} game = window.layout_description.get_preset.return_value.game game.exporter.is_busy = False window.layout_description.all_games = [game] patch_data = game.patch_data_factory.return_value.create_data.return_value players_config = PlayersConfiguration( player_index=window.current_player_index, player_names=window._player_names, ) # Run await window._export_iso() # Assert game.patch_data_factory.assert_called_once_with( window.layout_description, players_config, options.options_for_game.return_value.cosmetic_patches ) game.gui.export_dialog.assert_called_once_with( options, patch_data, window.layout_description.shareable_word_hash, window.layout_description.has_spoiler, [game] ) mock_execute_dialog.assert_awaited_once_with(game.gui.export_dialog.return_value) game.exporter.export_game.assert_called_once_with( patch_data, game.gui.export_dialog.return_value.get_game_export_params.return_value, progress_update=ANY, )
def test_multi_create_pickup_data_for_self(pickup_for_create_pickup_data): # Setup creator = patcher_file.PickupCreatorMulti( MagicMock(), patcher_file._SimplifiedMemo(), PlayersConfiguration(0, { 0: "You", 1: "Someone" })) # Run data = creator.create_pickup_data( PickupIndex(10), PickupTarget(pickup_for_create_pickup_data, 0), pickup_for_create_pickup_data, PickupModelStyle.ALL_VISIBLE, "Scan Text") # Assert assert data == { 'conditional_resources': [{ 'item': 1, 'resources': [ { 'amount': 1, 'index': 2 }, { 'amount': 11, 'index': 74 }, ] }], 'convert': [], 'hud_text': ['Sugar acquired!', 'Salt acquired!'], 'resources': [ { 'amount': 1, 'index': 1 }, { 'amount': 11, 'index': 74 }, ], 'scan': 'Your Scan Text', }
def test_create_hints_item_location(empty_patches, pickup, item, location, owner, is_multiworld): # Setup asset_id = 1000 pickup_index = PickupIndex(50) logbook_node, _, world_list = _create_world_list(asset_id, pickup_index) players_config = PlayersConfiguration( player_index=0, player_names={ i: f"Player {i + 1}" for i in range(int(is_multiworld) + 1) }, ) location_precision, determiner, item_name = item if owner and is_multiworld: determiner = "Player 1's" patches = dataclasses.replace(empty_patches, pickup_assignment={ pickup_index: PickupTarget(pickup, 0), }, hints={ logbook_node.resource(): Hint( HintType.LOCATION, PrecisionPair(location[0], location_precision, include_owner=owner), pickup_index) }) rng = MagicMock() # Run result = item_hints.create_hints({0: patches}, players_config, world_list, rng) # Assert message = "{} {} can be found in {}.".format(determiner, item_name, location[1]) # message = "The Flying Ing Cache in {} contains {}.".format(location[1], item[1]) assert result[0]['strings'][0] == message assert result == [{ 'asset_id': asset_id, 'strings': [message, '', message] }]
def test_create_string_patches( mock_stk_create_hints: MagicMock, mock_stk_hide_hints: MagicMock, mock_item_create_hints: MagicMock, mock_logbook_title_string_patches: MagicMock, stk_mode: SkyTempleKeyHintMode, ): # Setup game = MagicMock() all_patches = MagicMock() rng = MagicMock() mock_item_create_hints.return_value = ["item", "hints"] mock_stk_create_hints.return_value = ["show", "hints"] mock_stk_hide_hints.return_value = ["hide", "hints"] player_config = PlayersConfiguration(0, {0: "you"}) mock_logbook_title_string_patches.return_values = [] # Run result = patcher_file._create_string_patches( HintConfiguration(sky_temple_keys=stk_mode), game, all_patches, player_config, rng, ) # Assert expected_result = ["item", "hints"] mock_item_create_hints.assert_called_once_with(all_patches, player_config, game.world_list, rng) mock_logbook_title_string_patches.assert_called_once_with() if stk_mode == SkyTempleKeyHintMode.DISABLED: mock_stk_hide_hints.assert_called_once_with() mock_stk_create_hints.assert_not_called() expected_result.extend(["hide", "hints"]) else: mock_stk_create_hints.assert_called_once_with( all_patches, player_config, game.world_list, stk_mode == SkyTempleKeyHintMode.HIDE_AREA) mock_stk_hide_hints.assert_not_called() expected_result.extend(["show", "hints"]) assert result == expected_result
def test_patch_data_creation(test_files_dir): # Load the RDV game game_file = test_files_dir.joinpath("sdm_test_game.rdvgame").open() game_json = json.load(game_file) game_file.close() layout = LayoutDescription.from_json_dict(game_json) # Create patch_data from layout player_configuration = PlayersConfiguration(0, {0: "Player"}) cosmetic_patches = SuperMetroidCosmeticPatches() patch_data = SuperMetroidPatchDataFactory(layout, player_configuration, cosmetic_patches).create_data() # Load control patch_data and compare the two for differences json_file = test_files_dir.joinpath("sdm_expected_result.json").open() expected_json = json.load(json_file) json_file.close() assert expected_json == patch_data
def test_randomize_command_logic(mocker, with_permalink): mock_from_str = mocker.patch( "randovania.layout.permalink.Permalink.from_str") mock_from_file = mocker.patch( "randovania.layout.layout_description.LayoutDescription.from_file") mock_generate = mocker.patch( "randovania.generator.generator.generate_description") mock_apply = mocker.patch( "randovania.games.prime.claris_randomizer.apply_layout") args = MagicMock() if with_permalink: layout_description = mock_generate.return_value else: layout_description = mock_from_file.return_value args.permalink = None cosmetic_patches = CosmeticPatches( disable_hud_popup=args.disable_hud_popup, speed_up_credits=args.speed_up_credits) # Run randomize_command.randomize_command_logic(args) # Assert mock_apply.assert_called_once_with(description=layout_description, cosmetic_patches=cosmetic_patches, backup_files_path=args.backup_files, progress_update=ANY, game_root=args.game_files, players_config=PlayersConfiguration( 0, {0: "You"})) if with_permalink: mock_from_str.assert_called_once_with(args.permalink) mock_generate.assert_called_once_with( permalink=mock_from_str.return_value, status_update=ANY, validate_after_generation=True) mock_from_file.assert_not_called() else: mock_from_str.assert_not_called() mock_generate.assert_not_called() mock_from_file.assert_called_once_with(args.log_file)
def test_create_patcher_file(test_files_dir): # Setup description = LayoutDescription.from_file( test_files_dir.joinpath("log_files", "seed_a.rdvgame")) player_index = 0 preset = description.permalink.get_preset(player_index) cosmetic_patches = CosmeticPatches() # Run result = patcher_file.create_patcher_file( description, PlayersConfiguration(player_index, {0: "you"}), cosmetic_patches) # Assert assert isinstance(result["spawn_point"], dict) assert isinstance(result["pickups"], list) assert len(result["pickups"]) == 119 assert isinstance(result["elevators"], list) assert len(result["elevators"]) == 22 assert isinstance(result["translator_gates"], list) assert len(result["translator_gates"]) == 17 assert isinstance(result["string_patches"], list) assert len(result["string_patches"]) == 60 assert result["specific_patches"] == { "hive_chamber_b_post_state": True, "intro_in_post_state": True, "warp_to_start": preset.patcher_configuration.warp_to_start, "speed_up_credits": cosmetic_patches.speed_up_credits, "disable_hud_popup": cosmetic_patches.disable_hud_popup, "pickup_map_icons": cosmetic_patches.pickup_markers, "full_map_at_start": cosmetic_patches.open_map, "dark_world_varia_suit_damage": preset.patcher_configuration.varia_suit_damage, "dark_world_dark_suit_damage": preset.patcher_configuration.dark_suit_damage, "always_up_gfmc_compound": True, "always_up_torvus_temple": True, "always_up_great_temple": False, }
async def patcher_data_command_logic_async(args): from randovania.interface_common.players_configuration import PlayersConfiguration from randovania.layout.layout_description import LayoutDescription layout_description = LayoutDescription.from_file(args.log_file) players_config = PlayersConfiguration( args.player_index, {i: f"Player {i + 1}" for i in range(layout_description.player_count)}) preset = layout_description.get_preset(players_config.player_index) cosmetic_patches = preset.game.data.layout.cosmetic_patches.default() data_factory = preset.game.patch_data_factory(layout_description, players_config, cosmetic_patches) patch_data = data_factory.create_data() print(json.dumps( patch_data, indent=4, ))
async def test_export_iso(skip_qtbot, mocker): # Setup mock_input_dialog = mocker.patch( "randovania.gui.seed_details_window.GameInputDialog") mock_execute_dialog = mocker.patch( "randovania.gui.lib.async_dialog.execute_dialog", new_callable=AsyncMock, return_value=QtWidgets.QDialog.Accepted) options = MagicMock() options.output_directory = None window_manager = MagicMock() patcher_provider = window_manager.patcher_provider patcher = patcher_provider.patcher_for_game.return_value patcher.is_busy = False window = SeedDetailsWindow(window_manager, options) window.layout_description = MagicMock() window._player_names = {} players_config = PlayersConfiguration( player_index=window.current_player_index, player_names=window._player_names, ) # Run await window._export_iso() # Assert mock_execute_dialog.assert_awaited_once() patcher.create_patch_data.assert_called_once_with( window.layout_description, players_config, options.cosmetic_patches) patcher.patch_game.assert_called_once_with( mock_input_dialog.return_value.input_file, mock_input_dialog.return_value.output_file, patcher.create_patch_data.return_value, window._options.game_files_path, progress_update=ANY, )
async def randomize_command_logic_async(args): from randovania.games.patcher_provider import PatcherProvider from randovania.generator import generator from randovania.interface_common.cosmetic_patches import CosmeticPatches from randovania.interface_common.players_configuration import PlayersConfiguration from randovania.layout.layout_description import LayoutDescription from randovania.layout.permalink import Permalink from randovania.interface_common.options import Options def status_update(s): if args.verbose: print(s) if args.permalink is not None: permalink = Permalink.from_str(args.permalink) layout_description = await generator.generate_and_validate_description( permalink=permalink, status_update=status_update, validate_after_generation=True, ) else: layout_description = LayoutDescription.from_file(args.log_file) cosmetic_patches = CosmeticPatches( disable_hud_popup=args.disable_hud_popup, speed_up_credits=args.speed_up_credits) players_config = PlayersConfiguration(args.player_index, {i: f"Player {i + 1}" for i in range(layout_description.permalink.player_count)}) preset = layout_description.permalink.get_preset(players_config.player_index) game_files_path = Options.with_default_data_dir().game_files_path patcher_provider = PatcherProvider() patcher = patcher_provider.patcher_for_game(preset.game) patch_data = patcher.create_patch_data(layout_description, players_config, cosmetic_patches) patcher.patch_game(args.input_file, args.output_file, patch_data, game_files_path, lambda x, _: status_update(x))
def test_create_patch_data(test_files_dir, mocker): # Setup file = test_files_dir.joinpath("log_files", "dread_1.rdvgame") description = LayoutDescription.from_file(file) players_config = PlayersConfiguration(0, {0: "Dread"}) cosmetic_patches = DreadCosmeticPatches() mocker.patch( "randovania.layout.layout_description.LayoutDescription.shareable_word_hash", new_callable=PropertyMock, return_value="Words Hash") mocker.patch( "randovania.layout.layout_description.LayoutDescription.shareable_hash", new_callable=PropertyMock, return_value="$$$$$") # Run data = DreadPatchDataFactory(description, players_config, cosmetic_patches).create_data() # Expected Result with test_files_dir.joinpath("dread_expected_data.json").open("r") as file: expected_data = json.load(file) assert data == expected_data
def randomize_command_logic(args): def status_update(s): if args.verbose: print(s) if args.permalink is not None: layout_description = generator.generate_description( permalink=Permalink.from_str(args.permalink), status_update=status_update, validate_after_generation=True) else: layout_description = LayoutDescription.from_file(args.log_file) cosmetic_patches = CosmeticPatches( disable_hud_popup=args.disable_hud_popup, speed_up_credits=args.speed_up_credits) claris_randomizer.apply_layout( description=layout_description, cosmetic_patches=cosmetic_patches, backup_files_path=args.backup_files, progress_update=lambda x, _: status_update(x), game_root=args.game_files, players_config=PlayersConfiguration(0, {0: "You"}))