def test_round_trip_generated_patches(echoes_game_data, default_preset):
    # Setup
    preset = dataclasses.replace(
        default_preset,
        base_preset_name=default_preset.name,
        configuration=dataclasses.replace(
            default_preset.configuration,
            trick_level=TrickLevelConfiguration(
                minimal_logic=True,
                specific_levels={},
                game=RandovaniaGame.PRIME2,
            )
        )
    )

    all_patches = generator._async_create_description(
        permalink=Permalink(
            seed_number=1000,
            spoiler=True,
            presets={0: preset},
        ),
        status_update=lambda x: None,
        attempts=0,
    ).all_patches

    # Run
    encoded = game_patches_serializer.serialize(all_patches, {0: echoes_game_data})
    decoded = game_patches_serializer.decode(encoded, {0: preset.configuration})

    # Assert
    assert all_patches == decoded
def test_round_trip_generated_patches(echoes_game_data, preset_manager):
    # Setup
    preset = dataclasses.replace(
        preset_manager.default_preset,
        layout_configuration=dataclasses.replace(
            preset_manager.default_preset.layout_configuration,
            trick_level_configuration=TrickLevelConfiguration(
                global_level=LayoutTrickLevel.MINIMAL_RESTRICTIONS,
                specific_levels={},
            )))

    all_patches = generator._async_create_description(
        permalink=Permalink(
            seed_number=1000,
            spoiler=True,
            presets={0: preset},
        ),
        status_update=lambda x: None,
    ).all_patches

    # Run
    encoded = game_patches_serializer.serialize(all_patches,
                                                {0: echoes_game_data})
    decoded = game_patches_serializer.decode(encoded,
                                             {0: preset.layout_configuration})

    # Assert
    assert all_patches == decoded
Example #3
0
def test_create_patches(
    mock_random: MagicMock,
    mock_run_filler: MagicMock,
    mock_distribute_remaining_items: MagicMock,
    mock_create_player_pool: MagicMock,
    mock_validate_item_pool_size: MagicMock,
):
    # Setup
    num_players = 1
    rng = mock_random.return_value
    status_update: Union[MagicMock, Callable[[str], None]] = MagicMock()
    player_pools = [MagicMock() for _ in range(num_players)]
    presets = [MagicMock() for _ in range(num_players)]

    mock_create_player_pool.side_effect = player_pools

    permalink = MagicMock()
    permalink.get_preset.side_effect = lambda i: presets[i]

    # Run
    result = generator._async_create_description(permalink, status_update)

    # Assert
    mock_random.assert_called_once_with(permalink.as_str)
    mock_create_player_pool.assert_has_calls([
        call(rng, presets[i].layout_configuration, i)
        for i in range(num_players)
    ])
    mock_validate_item_pool_size.assert_has_calls([
        call(player_pools[i].pickups, player_pools[i].game)
        for i in range(num_players)
    ])
    mock_run_filler.assert_called_once_with(
        rng, {i: player_pools[i]
              for i in range(num_players)}, status_update)
    mock_distribute_remaining_items.assert_called_once_with(
        rng, mock_run_filler.return_value.player_results)

    assert result == LayoutDescription(
        permalink=permalink,
        version=randovania.VERSION,
        all_patches=mock_distribute_remaining_items.return_value,
        item_order=mock_run_filler.return_value.action_log,
    )