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
17 changes: 17 additions & 0 deletions src/ansys/sherlock/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,3 +1090,20 @@ def str_itr(self):

assert self.error_array is None
return [f"Update test points by file error: {self.message}"]


class SherlockUpdateTestFixturesByFileError(Exception):
"""Contains the errors raised when test fixtures cannot be updated."""

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

def str_itr(self):
"""Create list of error messages."""
if self.message is None:
return [f"Update test fixtures by file error: {error}" for error in self.error_array]

assert self.error_array is None
return [f"Update test fixtures by file error: {self.message}"]
79 changes: 79 additions & 0 deletions src/ansys/sherlock/core/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
SherlockDeleteAllMountPointsError,
SherlockDeleteAllTestPointsError,
SherlockUpdateMountPointsByFileError,
SherlockUpdateTestFixturesByFileError,
SherlockUpdateTestPointsByFileError,
)
from ansys.sherlock.core.grpc_stub import GrpcStub
Expand Down Expand Up @@ -564,3 +565,81 @@ def update_test_points_by_file(
for error in e.str_itr():
LOG.error(error)
raise e

def update_test_fixtures_by_file(
self,
project,
cca_name,
file_path,
):
"""Update test fixture properties of a CCA from a CSV file.

Parameters
----------
project : str
Name of the Sherlock project.
cca_name : str
Name of the CCA.
file_path : str
Path for the CSV file with the test fixture properties.

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_fixtures_by_file(
"Test",
"Card",
"TestFixturesImport.csv",
)
"""
try:
if project == "":
raise SherlockUpdateTestFixturesByFileError(message="Project name is invalid.")
if cca_name == "":
raise SherlockUpdateTestFixturesByFileError(message="CCA name is invalid.")
if file_path == "":
raise SherlockUpdateTestFixturesByFileError(message="File path is required.")

if not self._is_connection_up():
LOG.error("There is no connection to a gRPC service.")
return

request = SherlockLayerService_pb2.UpdateICTFixturesByFileRequest(
project=project,
ccaName=cca_name,
filePath=file_path,
)

response = self.stub.updateICTFixturesByFile(request)

return_code = response.returnCode

if return_code.value == -1:
if return_code.message == "":
raise SherlockUpdateTestFixturesByFileError(error_array=response.updateError)

raise SherlockUpdateTestFixturesByFileError(message=return_code.message)

else:
LOG.info(return_code.message)
return return_code.value

except SherlockUpdateTestFixturesByFileError as e:
for error in e.str_itr():
LOG.error(error)
raise e
46 changes: 46 additions & 0 deletions tests/test_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
SherlockDeleteAllMountPointsError,
SherlockDeleteAllTestPointsError,
SherlockUpdateMountPointsByFileError,
SherlockUpdateTestFixturesByFileError,
SherlockUpdateTestPointsByFileError,
)
from ansys.sherlock.core.layer import Layer
Expand All @@ -27,6 +28,7 @@ def test_all():
helper_test_delete_all_mount_points(layer)
helper_test_delete_all_test_points(layer)
helper_test_add_potting_region(layer)
helper_test_update_test_fixtures_by_file(layer)
helper_test_update_test_points_by_file(layer)


Expand Down Expand Up @@ -478,5 +480,49 @@ def helper_test_update_test_points_by_file(layer):
assert type(e) == SherlockUpdateTestPointsByFileError


def helper_test_update_test_fixtures_by_file(layer):
"""Test update_test_fixtures_by_file API."""
try:
layer.update_test_fixtures_by_file(
"",
"CCA",
"TestFixtureImport.csv",
)
pytest.fail("No exception thrown when using an invalid parameter")
except SherlockUpdateTestFixturesByFileError as e:
assert e.str_itr()[0] == "Update test fixtures by file error: Project name is invalid."

try:
layer.update_test_fixtures_by_file(
"Tutorial Project",
"",
"TestFixtureImport.csv",
)
pytest.fail("No exception thrown when using an invalid parameter")
except SherlockUpdateTestFixturesByFileError as e:
assert e.str_itr()[0] == "Update test fixtures by file error: CCA name is invalid."

try:
layer.update_test_fixtures_by_file(
"Tutorial Project",
"CCA",
"",
)
pytest.fail("No exception thrown when using an invalid parameter")
except SherlockUpdateTestFixturesByFileError as e:
assert e.str_itr()[0] == "Update test fixtures by file error: File path is required."

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


if __name__ == "__main__":
test_all()