Esempio n. 1
0
def test_faculty_repo_list_artifacts(mocker, prefix, suffix):
    objects = [mocker.Mock() for _ in range(10)]
    list_response_0 = mocker.Mock(objects=objects[:5], next_page_token="token")
    list_response_1 = mocker.Mock(objects=objects[5:], next_page_token=None)

    client = mocker.Mock()
    client.list.side_effect = [list_response_0, list_response_1]

    mocker.patch("faculty.client", return_value=client)

    mock_file_infos = [mocker.Mock() for _ in objects]
    mock_file_infos[-1].path = "/"
    converter_mock = mocker.patch(
        "mlflow_faculty.artifacts.faculty_object_to_mlflow_file_info",
        side_effect=mock_file_infos,
    )

    repo = FacultyDatasetsArtifactRepository(ARTIFACT_URI)
    assert (repo.list_artifacts(prefix + "a/dir" +
                                suffix) == mock_file_infos[:-1])

    faculty.client.assert_called_once_with("object")
    client.list.assert_has_calls([
        mocker.call(PROJECT_ID, ARTIFACT_ROOT + "a/dir/"),
        mocker.call(PROJECT_ID, ARTIFACT_ROOT + "a/dir/", "token"),
    ])
    converter_mock.assert_has_calls(
        [mocker.call(obj, ARTIFACT_ROOT) for obj in objects])
Esempio n. 2
0
def test_faculty_repo_list_artifacts_default_path(mocker):
    list_response = mocker.Mock(objects=[], next_page_token=None)

    client = mocker.Mock()
    client.list.side_effect = [list_response]

    mocker.patch("faculty.client", return_value=client)

    repo = FacultyDatasetsArtifactRepository(ARTIFACT_URI)
    assert repo.list_artifacts() == []

    faculty.client.assert_called_once_with("object")
    client.list.assert_called_once_with(PROJECT_ID, ARTIFACT_ROOT)