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 @@ -1073,3 +1073,20 @@ def __init__(self, message):
def __str__(self):
"""Format error message."""
return f"Delete test points error: {self.message}"


class SherlockUpdateTestPointsByFileError(Exception):
"""Contains the errors raised when test points 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 points by file error: {error}" for error in self.error_array]

assert self.error_array is None
return [f"Update test points 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,
SherlockUpdateTestPointsByFileError,
)
from ansys.sherlock.core.grpc_stub import GrpcStub

Expand Down Expand Up @@ -485,3 +486,81 @@ def delete_all_test_points(self, project, cca_name):
raise e

return response.value

def update_test_points_by_file(
self,
project,
cca_name,
file_path,
):
"""Update test point 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 point 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_points_by_file(
"Test",
"Card",
"TestPointsImport.csv",
)
"""
try:
if project == "":
raise SherlockUpdateTestPointsByFileError(message="Project name is invalid.")
if cca_name == "":
raise SherlockUpdateTestPointsByFileError(message="CCA name is invalid.")
if file_path == "":
raise SherlockUpdateTestPointsByFileError(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.UpdateTestPointsByFileRequest(
project=project,
ccaName=cca_name,
filePath=file_path,
)

response = self.stub.updateTestPointsByFile(request)

return_code = response.returnCode

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

raise SherlockUpdateTestPointsByFileError(message=return_code.message)

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

except SherlockUpdateTestPointsByFileError 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,
SherlockUpdateTestPointsByFileError,
)
from ansys.sherlock.core.layer import Layer
from ansys.sherlock.core.types.layer_types import PCBShape, PolygonalShape
Expand All @@ -26,6 +27,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_points_by_file(layer)


def helper_test_add_potting_region(layer):
Expand Down Expand Up @@ -432,5 +434,49 @@ def helper_test_delete_all_test_points(layer):
pytest.fail(e.message)


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

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

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

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


if __name__ == "__main__":
test_all()