コード例 #1
0
def test_batch_distribute_helper(
    mock_perf_counter: MagicMock,
    mock_generate_description: MagicMock,
):
    # Setup
    base_permalink = MagicMock()
    seed_number = 5000
    validate = MagicMock()
    output_dir = MagicMock()

    expected_permalink = Permalink(
        seed_number=seed_number,
        spoiler=True,
        patcher_configuration=base_permalink.patcher_configuration,
        layout_configuration=base_permalink.layout_configuration,
    )

    mock_perf_counter.side_effect = [1000, 5000]

    # Run
    delta_time = batch_distribute.batch_distribute_helper(
        base_permalink, seed_number, validate, output_dir)

    # Assert
    mock_generate_description.assert_called_once_with(expected_permalink, None,
                                                      validate)
    assert delta_time == 4000
    output_dir.joinpath.assert_called_once_with("{}.json".format(seed_number))
    mock_generate_description.return_value.save_to_file.assert_called_once_with(
        output_dir.joinpath.return_value)
コード例 #2
0
def test_batch_distribute_helper(
    mock_perf_counter: MagicMock,
    mock_generate_description: MagicMock,
):
    # Setup
    base_permalink = MagicMock()
    seed_number = 5000
    validate = MagicMock()
    output_dir = MagicMock()
    timeout = 67

    expected_permalink = Permalink(
        seed_number=seed_number,
        spoiler=True,
        presets=base_permalink.presets,
    )

    mock_perf_counter.side_effect = [1000, 5000]

    # Run
    delta_time = batch_distribute.batch_distribute_helper(
        base_permalink, seed_number, timeout, validate, output_dir)

    # Assert
    mock_generate_description.assert_called_once_with(
        permalink=expected_permalink,
        status_update=None,
        validate_after_generation=validate,
        timeout=timeout)
    assert delta_time == 4000
    output_dir.joinpath.assert_called_once_with("{}.json".format(seed_number))
    mock_generate_description.return_value.save_to_file.assert_called_once_with(
        output_dir.joinpath.return_value)
コード例 #3
0
def test_batch_distribute_helper(mocker):
    # Setup
    description = MagicMock()
    mock_generate_description: AsyncMock = mocker.patch(
        "randovania.generator.generator.generate_and_validate_description",
        new_callable=AsyncMock,
        return_value=description)
    mock_perf_counter = mocker.patch("time.perf_counter",
                                     autospec=False)  # TODO: pytest-qt bug

    base_permalink = MagicMock(spec=GeneratorParameters)
    base_permalink.presets = [MagicMock()]
    seed_number = 5000
    validate = MagicMock()
    output_dir = MagicMock()
    timeout = 67
    description.file_extension.return_value = "rdvgame"

    expected_permalink = GeneratorParameters(
        seed_number=seed_number,
        spoiler=True,
        presets=base_permalink.presets,
    )

    mock_perf_counter.side_effect = [1000, 5000]

    # Run
    delta_time = batch_distribute.batch_distribute_helper(
        base_permalink, seed_number, timeout, validate, output_dir)

    # Assert
    mock_generate_description.assert_awaited_once_with(
        generator_params=expected_permalink,
        status_update=None,
        validate_after_generation=validate,
        timeout=timeout,
        attempts=0)

    assert delta_time == 4000
    output_dir.joinpath.assert_called_once_with(
        "{}.rdvgame".format(seed_number))
    description.save_to_file.assert_called_once_with(
        output_dir.joinpath.return_value)