def test_delete_dataframe(asyn_repo_w_mock_filesystem): project, dataframe = _create_dataframe_domain() dataframe_dir = ( f"{asyn_repo_w_mock_filesystem.root_dir}/{slugify(project.name)}/dataframes/{dataframe.id}" ) asyncio.run(asyn_repo_w_mock_filesystem.delete_dataframe(project.name, dataframe.id)) filesystem_expected = [call.rm(dataframe_dir, recursive=True), call.invalidate_cache()] assert asyn_repo_w_mock_filesystem.filesystem.mock_calls == filesystem_expected
def test_delete_artifact(asyn_repo_w_mock_filesystem): project, artifact = _create_artifact_domain() artifact_dir = ( f"{asyn_repo_w_mock_filesystem.root_dir}/{slugify(project.name)}/artifacts/{artifact.id}" ) asyncio.run(asyn_repo_w_mock_filesystem.delete_artifact(project.name, artifact.id)) filesystem_expected = [call.rm(artifact_dir, recursive=True), call.invalidate_cache()] assert asyn_repo_w_mock_filesystem.filesystem.mock_calls == filesystem_expected
def test_remove_tags(asyn_repo_w_mock_filesystem): experiment = _create_experiment_domain() tags = ["x"] asyncio.run( asyn_repo_w_mock_filesystem.remove_tags( experiment.project_name, tags, experiment_id=experiment.id ) ) filesystem_expected = [call.invalidate_cache()] repo_expected = [call({"removed_tags": tags}, ANY)] assert asyn_repo_w_mock_filesystem.filesystem.mock_calls == filesystem_expected assert asyn_repo_w_mock_filesystem._persist_domain.mock_calls == repo_expected
def test_create_project(asyn_repo_w_mock_filesystem): asyn_repo_w_mock_filesystem.filesystem._exists.return_value = False project = domain.Project(f"Test Project {uuid.uuid4()}") project_dir = slugify(project.name) project_metadata_path = f"{asyn_repo_w_mock_filesystem.root_dir}/{project_dir}/metadata.json" asyncio.run(asyn_repo_w_mock_filesystem.create_project(project)) filesystem_expected = [call._exists(project_metadata_path), call.invalidate_cache()] repo_expected = [call._persist_domain(project, project_metadata_path)] assert asyn_repo_w_mock_filesystem.filesystem.mock_calls == filesystem_expected assert asyn_repo_w_mock_filesystem._persist_domain.mock_calls == repo_expected
def test_create_experiment(asyn_repo_w_mock_filesystem): experiment = _create_experiment_domain() experiment_dir = f"{slugify(experiment.project_name)}/experiments/{experiment.id}" experiment_metadata_path = ( f"{asyn_repo_w_mock_filesystem.root_dir}/{experiment_dir}/metadata.json" ) asyncio.run(asyn_repo_w_mock_filesystem.create_experiment(experiment)) filesystem_expected = [call.invalidate_cache()] repo_expected = [call._persist_domain(experiment, experiment_metadata_path)] assert asyn_repo_w_mock_filesystem.filesystem.mock_calls == filesystem_expected assert asyn_repo_w_mock_filesystem._persist_domain.mock_calls == repo_expected
def test_create_artifact(asyn_repo_w_mock_filesystem): project, artifact = _create_artifact_domain() artifact_dir = f"{slugify(project.name)}/artifacts/{artifact.id}" artifact_metadata_path = f"{asyn_repo_w_mock_filesystem.root_dir}/{artifact_dir}/metadata.json" artifact_data_path = f"{asyn_repo_w_mock_filesystem.root_dir}/{artifact_dir}/data" data = b"test artifact data" asyncio.run(asyn_repo_w_mock_filesystem.create_artifact(artifact, data, project.name)) filesystem_expected = [call.invalidate_cache()] persist_domain_expected = [call._persist_domain(artifact, artifact_metadata_path)] persist_bytes_expected = [call._persist_bytes(data, artifact_data_path)] assert asyn_repo_w_mock_filesystem.filesystem.mock_calls == filesystem_expected assert asyn_repo_w_mock_filesystem._persist_domain.mock_calls == persist_domain_expected assert asyn_repo_w_mock_filesystem._persist_bytes.mock_calls == persist_bytes_expected
def test_create_metric(asyn_repo_w_mock_filesystem): asyn_repo_w_mock_filesystem.filesystem._exists.return_value = False experiment, metric = _create_metric_domain() metric_dir = f"{slugify(experiment.project_name)}/experiments/{experiment.id}/metrics/{slugify(metric.name)}" metric_metadata_path = f"{asyn_repo_w_mock_filesystem.root_dir}/{metric_dir}/metadata.json" asyncio.run( asyn_repo_w_mock_filesystem.create_metric(metric, experiment.project_name, experiment.id) ) filesystem_expected = [call._exists(metric_metadata_path), call.invalidate_cache()] repo_expected = [call._persist_domain(metric, metric_metadata_path)] assert asyn_repo_w_mock_filesystem.filesystem.mock_calls == filesystem_expected assert asyn_repo_w_mock_filesystem._persist_domain.mock_calls == repo_expected
def test_create_dataframe(asyn_repo_w_mock_filesystem): project, dataframe = _create_dataframe_domain() dataframe_dir = f"{slugify(project.name)}/dataframes/{dataframe.id}" dataframe_metadata_path = ( f"{asyn_repo_w_mock_filesystem.root_dir}/{dataframe_dir}/metadata.json" ) mock_dataframe = MagicMock(spec=dd.DataFrame) asyncio.run( asyn_repo_w_mock_filesystem.create_dataframe(dataframe, mock_dataframe, project.name) ) filesystem_expected = [call.invalidate_cache()] repo_expected = [call._persist_domain(dataframe, dataframe_metadata_path)] assert asyn_repo_w_mock_filesystem.filesystem.mock_calls == filesystem_expected assert asyn_repo_w_mock_filesystem._persist_domain.mock_calls == repo_expected
def test_create_parameter(asyn_repo_w_mock_filesystem): asyn_repo_w_mock_filesystem.filesystem._exists.return_value = False experiment, parameter = _create_parameter_domain() parameter_dir = f"{slugify(experiment.project_name)}/experiments/{experiment.id}/parameters/{slugify(parameter.name)}" parameter_metadata_path = ( f"{asyn_repo_w_mock_filesystem.root_dir}/{parameter_dir}/metadata.json" ) asyncio.run( asyn_repo_w_mock_filesystem.create_parameter( parameter, experiment.project_name, experiment.id ) ) filesystem_expected = [call._exists(parameter_metadata_path), call.invalidate_cache()] repo_expected = [call._persist_domain(parameter, parameter_metadata_path)] assert asyn_repo_w_mock_filesystem.filesystem.mock_calls == filesystem_expected assert asyn_repo_w_mock_filesystem._persist_domain.mock_calls == repo_expected