示例#1
0
def test_restore_runs_no_run_ids(mocker):
    mocker.patch.object(ExperimentClient, "_post")
    schema_mock = mocker.patch(
        "faculty.clients.experiment._RestoreExperimentRunsResponseSchema")

    client = ExperimentClient(mocker.Mock(), mocker.Mock())
    client.restore_runs(PROJECT_ID)

    ExperimentClient._post.assert_called_once_with(
        "/project/{}/run/restore/query".format(PROJECT_ID),
        schema_mock.return_value,
        json={},
    )
示例#2
0
def test_restore_runs(mocker):
    restore_runs_response = mocker.Mock()
    mocker.patch.object(ExperimentClient,
                        "_post",
                        return_value=restore_runs_response)
    response_schema_mock = mocker.patch(
        "faculty.clients.experiment._RestoreExperimentRunsResponseSchema")
    filter_schema_mock = mocker.patch(
        "faculty.clients.experiment._FilterSchema")
    filter_dump_mock = filter_schema_mock.return_value.dump

    run_ids = [uuid4(), uuid4()]

    client = ExperimentClient(mocker.Mock(), mocker.Mock())
    response = client.restore_runs(PROJECT_ID, run_ids)

    assert response == restore_runs_response

    expected_filter = CompoundFilter(
        LogicalOperator.OR,
        [
            RunIdFilter(ComparisonOperator.EQUAL_TO, run_ids[0]),
            RunIdFilter(ComparisonOperator.EQUAL_TO, run_ids[1]),
        ],
    )
    filter_dump_mock.assert_called_once_with(expected_filter)
    ExperimentClient._post.assert_called_once_with(
        "/project/{}/run/restore/query".format(PROJECT_ID),
        response_schema_mock.return_value,
        json={"filter": filter_dump_mock.return_value},
    )
示例#3
0
def test_restore_runs_empty_list(mocker):
    mocker.patch.object(ExperimentClient, "_post")

    client = ExperimentClient(mocker.Mock(), mocker.Mock())
    response = client.restore_runs(PROJECT_ID, run_ids=[])

    ExperimentClient._post.assert_not_called()
    assert len(response.restored_run_ids) == 0
    assert len(response.conflicted_run_ids) == 0