-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add metadata SDK sample for delete method. (#1530)
* feat: Add metadata SDK sample for delete method. * add test fixtures. * fix lint errors
- Loading branch information
1 parent
34bbd0a
commit 46aa9b5
Showing
7 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
samples/model-builder/experiment_tracking/delete_artifact_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
31 changes: 31 additions & 0 deletions
31
samples/model-builder/experiment_tracking/delete_artifact_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) |
29 changes: 29 additions & 0 deletions
29
samples/model-builder/experiment_tracking/delete_context_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
31 changes: 31 additions & 0 deletions
31
samples/model-builder/experiment_tracking/delete_context_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) |
29 changes: 29 additions & 0 deletions
29
samples/model-builder/experiment_tracking/delete_execution_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
31 changes: 31 additions & 0 deletions
31
samples/model-builder/experiment_tracking/delete_execution_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) |