From febdc841d7c6b9dffbb994e0699c697ba491b2ed Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:34:01 +0200 Subject: [PATCH 1/3] New API: delete_all_test_points() --- src/ansys/sherlock/core/errors.py | 12 ++++++ src/ansys/sherlock/core/layer.py | 62 +++++++++++++++++++++++++++++++ tests/test_layer.py | 43 +++++++++++++++++++++ 3 files changed, 117 insertions(+) diff --git a/src/ansys/sherlock/core/errors.py b/src/ansys/sherlock/core/errors.py index 85611932d..672cd345f 100644 --- a/src/ansys/sherlock/core/errors.py +++ b/src/ansys/sherlock/core/errors.py @@ -1061,3 +1061,15 @@ def __init__(self, message): def __str__(self): """Format error message.""" return f"Delete ict fixtures error: {self.message}" + + +class SherlockDeleteAllTestPointsError(Exception): + """Contains the error raised when the test points cannot be deleted.""" + + def __init__(self, message): + """Initialize error message.""" + self.message = message + + def __str__(self): + """Format error message.""" + return f"Delete test points error: {self.message}" diff --git a/src/ansys/sherlock/core/layer.py b/src/ansys/sherlock/core/layer.py index 48cf2f913..27e12004b 100644 --- a/src/ansys/sherlock/core/layer.py +++ b/src/ansys/sherlock/core/layer.py @@ -21,6 +21,7 @@ SherlockAddPottingRegionError, SherlockDeleteAllICTFixturesError, SherlockDeleteAllMountPointsError, + SherlockDeleteAllTestPointsError, SherlockUpdateMountPointsByFileError, ) from ansys.sherlock.core.grpc_stub import GrpcStub @@ -423,3 +424,64 @@ def delete_all_ict_fixtures(self, project, cca_name): raise e return response.value + + def delete_all_test_points(self, project, cca_name): + """Delete all test points for a CCA. + + Parameters + ---------- + project : str + Name of the Sherlock project. + cca_name : str + Name of the CCA. + + Returns + ------- + int + Status code of the response. 0 for success. + + Examples + -------- + >>> from ansys.sherlock.core.launcher import launch_sherlock + >>> sherlock = launch_sherlock() + >>> sherlock.project.import_odb_archive( + "ODB++ Tutorial.tgz", + True, + True, + True, + True, + project="Test", + cca_name="Card", + ) + >>> sherlock.layer.update_test_points_by_file( + "Test", + "Card", + "TestPointsImport.csv", + ) + >>> sherlock.layer.delete_all_test_points("Test", "Card") + """ + try: + if project == "": + raise SherlockDeleteAllTestPointsError(message="Project name is invalid.") + if cca_name == "": + raise SherlockDeleteAllTestPointsError(message="CCA name is invalid.") + + if not self._is_connection_up(): + LOG.error("There is no connection to a gRPC service.") + return + + request = SherlockLayerService_pb2.DeleteAllTestPointsRequest( + project=project, + ccaName=cca_name, + ) + + response = self.stub.deleteAllTestPoints(request) + + if response.value == -1: + raise SherlockDeleteAllTestPointsError(message=response.message) + + except SherlockDeleteAllTestPointsError as e: + LOG.error(str(e)) + raise e + + return response.value diff --git a/tests/test_layer.py b/tests/test_layer.py index d5fba74dd..3394c7ad5 100644 --- a/tests/test_layer.py +++ b/tests/test_layer.py @@ -8,6 +8,7 @@ SherlockAddPottingRegionError, SherlockDeleteAllICTFixturesError, SherlockDeleteAllMountPointsError, + SherlockDeleteAllTestPointsError, SherlockUpdateMountPointsByFileError, ) from ansys.sherlock.core.layer import Layer @@ -23,6 +24,7 @@ def test_all(): helper_test_update_mount_points_by_file(layer) helper_test_delete_all_ict_fixtures(layer) helper_test_delete_all_mount_points(layer) + helper_test_delete_all_test_points(layer) helper_test_add_potting_region(layer) @@ -389,5 +391,46 @@ def helper_test_delete_all_ict_fixtures(layer): pytest.fail(e.message) +def helper_test_delete_all_test_points(layer): + """Test delete_all_test_points API.""" + try: + layer.delete_all_test_points( + "", + "CCA", + ) + pytest.fail("No exception thrown when using an invalid parameter") + except SherlockDeleteAllTestPointsError as e: + assert str(e) == "Delete test points error: Project name is invalid." + + try: + layer.delete_all_test_points( + "Tutorial Project", + "", + ) + pytest.fail("No exception thrown when using an invalid parameter") + except SherlockDeleteAllTestPointsError as e: + assert str(e) == "Delete test points error: CCA name is invalid." + + if layer._is_connection_up(): + try: + layer.delete_all_test_points( + "Tutorial Project", + "Invalid CCA", + ) + pytest.fail("No exception thrown when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockDeleteAllTestPointsError + + try: + result = layer.delete_all_test_points( + "Tutorial Project", + "Main Board", + ) + assert result == 0 + + except Exception as e: + pytest.fail(e.message) + + if __name__ == "__main__": test_all() From 0d8c0bbd51018ac5c61b1bfc31a6c21342e13943 Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:40:13 +0200 Subject: [PATCH 2/3] Update after feedback --- src/ansys/sherlock/core/errors.py | 2 +- src/ansys/sherlock/core/layer.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/sherlock/core/errors.py b/src/ansys/sherlock/core/errors.py index 672cd345f..c741f53ee 100644 --- a/src/ansys/sherlock/core/errors.py +++ b/src/ansys/sherlock/core/errors.py @@ -1052,7 +1052,7 @@ def __str__(self): class SherlockDeleteAllICTFixturesError(Exception): - """Contains the error raised when the ict fixtures cannot be deleted.""" + """Contains the error raised when the ICT fixtures cannot be deleted.""" def __init__(self, message): """Initialize error message.""" diff --git a/src/ansys/sherlock/core/layer.py b/src/ansys/sherlock/core/layer.py index 27e12004b..e496ddbac 100644 --- a/src/ansys/sherlock/core/layer.py +++ b/src/ansys/sherlock/core/layer.py @@ -1,4 +1,4 @@ -# © 2023 ANSYS, Inc. All rights reserved +# © 2023-2024 ANSYS, Inc. All rights reserved """Module containing all layer management capabilities.""" from ansys.sherlock.core.types.layer_types import ( From 53ddda6b6810cd196d8719d52a37716ee573456f Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Fri, 14 Jun 2024 13:01:42 +0200 Subject: [PATCH 3/3] Update copyright --- tests/test_layer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_layer.py b/tests/test_layer.py index 3394c7ad5..1dec33427 100644 --- a/tests/test_layer.py +++ b/tests/test_layer.py @@ -1,4 +1,4 @@ -# © 2023 ANSYS, Inc. All rights reserved +# © 2023-2024 ANSYS, Inc. All rights reserved import uuid import grpc