Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/ansys/sherlock/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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}"
64 changes: 63 additions & 1 deletion src/ansys/sherlock/core/layer.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -21,6 +21,7 @@
SherlockAddPottingRegionError,
SherlockDeleteAllICTFixturesError,
SherlockDeleteAllMountPointsError,
SherlockDeleteAllTestPointsError,
SherlockUpdateMountPointsByFileError,
)
from ansys.sherlock.core.grpc_stub import GrpcStub
Expand Down Expand Up @@ -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
45 changes: 44 additions & 1 deletion tests/test_layer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2023 ANSYS, Inc. All rights reserved
# © 2023-2024 ANSYS, Inc. All rights reserved
import uuid

import grpc
Expand All @@ -8,6 +8,7 @@
SherlockAddPottingRegionError,
SherlockDeleteAllICTFixturesError,
SherlockDeleteAllMountPointsError,
SherlockDeleteAllTestPointsError,
SherlockUpdateMountPointsByFileError,
)
from ansys.sherlock.core.layer import Layer
Expand All @@ -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)


Expand Down Expand Up @@ -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()