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
12 changes: 12 additions & 0 deletions src/ansys/sherlock/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,3 +1049,15 @@ def __init__(self, message):
def __str__(self):
"""Format error message."""
return f"Delete mount points error: {self.message}"


class SherlockDeleteAllICTFixturesError(Exception):
"""Contains the error raised when the ict fixtures cannot be deleted."""

def __init__(self, message):
"""Initialize error message."""
self.message = message

def __str__(self):
"""Format error message."""
return f"Delete ict fixtures error: {self.message}"
62 changes: 62 additions & 0 deletions src/ansys/sherlock/core/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ansys.sherlock.core import LOG
from ansys.sherlock.core.errors import (
SherlockAddPottingRegionError,
SherlockDeleteAllICTFixturesError,
SherlockDeleteAllMountPointsError,
SherlockUpdateMountPointsByFileError,
)
Expand Down Expand Up @@ -361,3 +362,64 @@ def delete_all_mount_points(self, project, cca_name):
raise e

return response.value

def delete_all_ict_fixtures(self, project, cca_name):
"""Delete all ICT fixtures 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_ict_fixtures_by_file(
"Test",
"Card",
"ICTFixturesImport.csv",
)
>>> sherlock.layer.delete_all_ict_fixtures("Test", "Card")
"""
try:
if project == "":
raise SherlockDeleteAllICTFixturesError(message="Project name is invalid.")
if cca_name == "":
raise SherlockDeleteAllICTFixturesError(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.DeleteAllICTFixturesRequest(
project=project,
ccaName=cca_name,
)

response = self.stub.deleteAllICTFixtures(request)

if response.value == -1:
raise SherlockDeleteAllICTFixturesError(message=response.message)

except SherlockDeleteAllICTFixturesError as e:
LOG.error(str(e))
raise e

return response.value
43 changes: 43 additions & 0 deletions tests/test_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from ansys.sherlock.core.errors import (
SherlockAddPottingRegionError,
SherlockDeleteAllICTFixturesError,
SherlockDeleteAllMountPointsError,
SherlockUpdateMountPointsByFileError,
)
Expand All @@ -20,6 +21,7 @@ def test_all():
layer = Layer(channel)

helper_test_update_mount_points_by_file(layer)
helper_test_delete_all_ict_fixtures(layer)
helper_test_delete_all_mount_points(layer)
helper_test_add_potting_region(layer)

Expand Down Expand Up @@ -346,5 +348,46 @@ def helper_test_delete_all_mount_points(layer):
pytest.fail(e.message)


def helper_test_delete_all_ict_fixtures(layer):
"""Test delete_all_ict_fixtures API."""
try:
layer.delete_all_ict_fixtures(
"",
"CCA",
)
pytest.fail("No exception thrown when using an invalid parameter")
except SherlockDeleteAllICTFixturesError as e:
assert str(e) == "Delete ict fixtures error: Project name is invalid."

try:
layer.delete_all_ict_fixtures(
"Tutorial Project",
"",
)
pytest.fail("No exception thrown when using an invalid parameter")
except SherlockDeleteAllICTFixturesError as e:
assert str(e) == "Delete ict fixtures error: CCA name is invalid."

if layer._is_connection_up():
try:
layer.delete_all_ict_fixtures(
"Tutorial Project",
"Invalid CCA",
)
pytest.fail("No exception thrown when using an invalid parameter")
except Exception as e:
assert type(e) == SherlockDeleteAllICTFixturesError

try:
result = layer.delete_all_ict_fixtures(
"Tutorial Project",
"Main Board",
)
assert result == 0

except Exception as e:
pytest.fail(e.message)


if __name__ == "__main__":
test_all()