async def _create_description(generator_params: GeneratorParameters, status_update: Callable[[str], None], attempts: int, ) -> LayoutDescription: """ :param generator_params: :param status_update: :return: """ rng = Random(generator_params.as_bytes) presets = [ generator_params.get_preset(i) for i in range(generator_params.player_count) ] retrying = tenacity.AsyncRetrying( stop=tenacity.stop_after_attempt(attempts), retry=tenacity.retry_if_exception_type(UnableToGenerate), reraise=True ) filler_results = await retrying(_create_pools_and_fill, rng, presets, status_update) all_patches = _distribute_remaining_items(rng, filler_results.player_results) return LayoutDescription.create_new( generator_parameters=generator_params, all_patches=all_patches, item_order=filler_results.action_log, )
async def test_create_patches( mock_random: MagicMock, mock_distribute_remaining_items: MagicMock, mock_create_player_pool: MagicMock, mock_validate_item_pool_size: MagicMock, mocker, ): # Setup filler_result = MagicMock() mock_run_filler: AsyncMock = mocker.patch( "randovania.generator.generator.run_filler", new_callable=AsyncMock, return_value=filler_result) mock_dock_weakness_distributor: AsyncMock = mocker.patch( "randovania.generator.dock_weakness_distributor.distribute_post_fill_weaknesses", new_callable=AsyncMock, return_value=filler_result) mock_distribute_remaining_items.return_value = filler_result 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 generator_parameters = MagicMock() generator_parameters.get_preset.side_effect = lambda i: presets[i] # Run result = await generator._create_description(generator_parameters, status_update, 0) # Assert mock_random.assert_called_once_with(generator_parameters.as_bytes) mock_create_player_pool.assert_has_calls([ call(rng, presets[i].configuration, i, num_players) for i in range(num_players) ]) mock_validate_item_pool_size.assert_has_calls([ call(player_pools[i].pickups, player_pools[i].game, player_pools[i].configuration) for i in range(num_players) ]) mock_run_filler.assert_awaited_once_with( rng, [player_pools[i] for i in range(num_players)], status_update) mock_distribute_remaining_items.assert_called_once_with(rng, filler_result) mock_dock_weakness_distributor.assert_called_once_with( rng, filler_result, status_update) assert result == LayoutDescription.create_new( generator_parameters=generator_parameters, all_patches={}, item_order=filler_result.action_log, )