diff --git a/samples/model-builder/conftest.py b/samples/model-builder/conftest.py index 7b6cbdb6a9..5375b870d7 100644 --- a/samples/model-builder/conftest.py +++ b/samples/model-builder/conftest.py @@ -527,6 +527,12 @@ def mock_artifact(): yield mock +@pytest.fixture +def mock_context(): + mock = MagicMock(aiplatform.Context) + yield mock + + @pytest.fixture def mock_experiment(): mock = MagicMock(aiplatform.Experiment) @@ -613,6 +619,13 @@ def mock_artifact_get(mock_artifact): yield mock_artifact_get +@pytest.fixture +def mock_context_get(mock_context): + with patch.object(aiplatform.Context, "get") as mock_context_get: + mock_context_get.return_value = mock_context + yield mock_context_get + + @pytest.fixture def mock_pipeline_job_create(mock_pipeline_job): with patch.object(aiplatform, "PipelineJob") as mock_pipeline_job_create: @@ -620,6 +633,27 @@ def mock_pipeline_job_create(mock_pipeline_job): yield mock_pipeline_job_create +@pytest.fixture +def mock_artifact_delete(): + with patch.object(aiplatform.Artifact, "delete") as mock_artifact_delete: + mock_artifact_delete.return_value = None + yield mock_artifact_delete + + +@pytest.fixture +def mock_execution_delete(): + with patch.object(aiplatform.Execution, "delete") as mock_execution_delete: + mock_execution_delete.return_value = None + yield mock_execution_delete + + +@pytest.fixture +def mock_context_delete(): + with patch.object(aiplatform.Context, "delete") as mock_context_delete: + mock_context_delete.return_value = None + yield mock_context_delete + + @pytest.fixture def mock_pipeline_job_submit(mock_pipeline_job): with patch.object(mock_pipeline_job, "submit") as mock_pipeline_job_submit: diff --git a/samples/model-builder/experiment_tracking/delete_artifact_sample.py b/samples/model-builder/experiment_tracking/delete_artifact_sample.py new file mode 100644 index 0000000000..853c413c6c --- /dev/null +++ b/samples/model-builder/experiment_tracking/delete_artifact_sample.py @@ -0,0 +1,29 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_delete_artifact_sample] +def delete_artifact_sample( + artifact_id: str, + project: str, + location: str, +): + artifact = aiplatform.Artifact.get( + resource_id=artifact_id, project=project, location=location + ) + artifact.delete() + +# [END aiplatform_sdk_delete_artifact_sample] diff --git a/samples/model-builder/experiment_tracking/delete_artifact_sample_test.py b/samples/model-builder/experiment_tracking/delete_artifact_sample_test.py new file mode 100644 index 0000000000..555b6745ee --- /dev/null +++ b/samples/model-builder/experiment_tracking/delete_artifact_sample_test.py @@ -0,0 +1,31 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import delete_artifact_sample + +import test_constants + + +def test_delete_artifact_sample(mock_artifact, mock_artifact_get): + delete_artifact_sample.delete_artifact_sample( + artifact_id=test_constants.RESOURCE_ID, + project=test_constants.PROJECT, + location=test_constants.LOCATION, + ) + + mock_artifact_get.assert_called_with( + resource_id=test_constants.RESOURCE_ID, + project=test_constants.PROJECT, + location=test_constants.LOCATION, + ) diff --git a/samples/model-builder/experiment_tracking/delete_context_sample.py b/samples/model-builder/experiment_tracking/delete_context_sample.py new file mode 100644 index 0000000000..2753138f41 --- /dev/null +++ b/samples/model-builder/experiment_tracking/delete_context_sample.py @@ -0,0 +1,29 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_delete_context_sample] +def delete_context_sample( + context_id: str, + project: str, + location: str, +): + context = aiplatform.Context.get( + resource_id=context_id, project=project, location=location + ) + context.delete() + +# [END aiplatform_sdk_delete_context_sample] diff --git a/samples/model-builder/experiment_tracking/delete_context_sample_test.py b/samples/model-builder/experiment_tracking/delete_context_sample_test.py new file mode 100644 index 0000000000..49e2a08c72 --- /dev/null +++ b/samples/model-builder/experiment_tracking/delete_context_sample_test.py @@ -0,0 +1,31 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import delete_context_sample + +import test_constants + + +def test_delete_context_sample(mock_context_get): + delete_context_sample.delete_context_sample( + context_id=test_constants.RESOURCE_ID, + project=test_constants.PROJECT, + location=test_constants.LOCATION, + ) + + mock_context_get.assert_called_with( + resource_id=test_constants.RESOURCE_ID, + project=test_constants.PROJECT, + location=test_constants.LOCATION, + ) diff --git a/samples/model-builder/experiment_tracking/delete_execution_sample.py b/samples/model-builder/experiment_tracking/delete_execution_sample.py new file mode 100644 index 0000000000..77f6fe959f --- /dev/null +++ b/samples/model-builder/experiment_tracking/delete_execution_sample.py @@ -0,0 +1,29 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_delete_execution_sample] +def delete_execution_sample( + execution_id: str, + project: str, + location: str, +): + execution = aiplatform.Execution.get( + resource_id=execution_id, project=project, location=location + ) + execution.delete() + +# [END aiplatform_sdk_delete_execution_sample] diff --git a/samples/model-builder/experiment_tracking/delete_execution_sample_test.py b/samples/model-builder/experiment_tracking/delete_execution_sample_test.py new file mode 100644 index 0000000000..3e6cba5d8e --- /dev/null +++ b/samples/model-builder/experiment_tracking/delete_execution_sample_test.py @@ -0,0 +1,31 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import delete_execution_sample + +import test_constants + + +def test_delete_execution_sample(mock_execution, mock_execution_get): + delete_execution_sample.delete_execution_sample( + execution_id=test_constants.RESOURCE_ID, + project=test_constants.PROJECT, + location=test_constants.LOCATION, + ) + + mock_execution_get.assert_called_with( + resource_id=test_constants.RESOURCE_ID, + project=test_constants.PROJECT, + location=test_constants.LOCATION, + )