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 @@ -1107,3 +1107,20 @@ def str_itr(self):

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


class SherlockExportAllTestPoints(Exception):
"""Contains the errors raised when test points cannot be exported."""

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"Export test points error: {error}" for error in self.error_array]

assert self.error_array is None
return [f"Export test points error: {self.message}"]
90 changes: 90 additions & 0 deletions src/ansys/sherlock/core/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
SherlockDeleteAllICTFixturesError,
SherlockDeleteAllMountPointsError,
SherlockDeleteAllTestPointsError,
SherlockExportAllTestPoints,
SherlockUpdateMountPointsByFileError,
SherlockUpdateTestFixturesByFileError,
SherlockUpdateTestPointsByFileError,
Expand Down Expand Up @@ -643,3 +644,92 @@ def update_test_fixtures_by_file(
for error in e.str_itr():
LOG.error(error)
raise e

def export_all_test_points(
self,
project,
cca_name,
export_file,
length_units="DEFAULT",
displacement_units="DEFAULT",
force_units="DEFAULT",
):
"""Export the test point properties for a CCA.

Parameters
----------
project : str
Name of the Sherlock project.
cca_name : str
Name of the CCA.
export_file : str
Full path for the CSV file to export the parts list to.
length_units : str, optional
Length units to use when exporting the test points.
The default is ``DEFAULT``.
displacement_units : str, optional
Displacement units to use when exporting the test points.
The default is ``DEFAULT``.
force_units : str, optional
Force units to use when exporting the test points.
The default is ``DEFAULT``.

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="Tutorial Project",
cca_name="Card",
)
>>> sherlock.layer.export_all_test_points(
"Tutorial Project",
"Card",
"TestPointsExport.csv",
"DEFAULT",
"DEFAULT",
"DEFAULT",
)
"""
try:
if project == "":
raise SherlockExportAllTestPoints(message="Project name is invalid.")
if cca_name == "":
raise SherlockExportAllTestPoints(message="CCA name is invalid.")
if export_file == "":
raise SherlockExportAllTestPoints(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.ExportAllTestPointsRequest(
project=project,
ccaName=cca_name,
filePath=export_file,
lengthUnits=length_units,
displacementUnits=displacement_units,
forceUnits=force_units,
)

return_code = self.stub.exportAllTestPoints(request)

if return_code.value != 0:
raise SherlockExportAllTestPoints(error_array=return_code.message)

return return_code.value

except SherlockExportAllTestPoints as e:
for error in e.str_itr():
LOG.error(error)
raise e
66 changes: 66 additions & 0 deletions tests/test_layer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# © 2023-2024 ANSYS, Inc. All rights reserved
import os
import platform
import uuid

import grpc
Expand All @@ -9,6 +11,7 @@
SherlockDeleteAllICTFixturesError,
SherlockDeleteAllMountPointsError,
SherlockDeleteAllTestPointsError,
SherlockExportAllTestPoints,
SherlockUpdateMountPointsByFileError,
SherlockUpdateTestFixturesByFileError,
SherlockUpdateTestPointsByFileError,
Expand All @@ -30,6 +33,7 @@ def test_all():
helper_test_add_potting_region(layer)
helper_test_update_test_fixtures_by_file(layer)
helper_test_update_test_points_by_file(layer)
helper_test_export_all_test_points(layer)


def helper_test_add_potting_region(layer):
Expand Down Expand Up @@ -524,5 +528,67 @@ def helper_test_update_test_fixtures_by_file(layer):
assert type(e) == SherlockUpdateTestFixturesByFileError


def helper_test_export_all_test_points(layer):
"""Tests export_all_test_points API."""
try:
layer.export_all_test_points(
"",
"Main Board",
"Test Points.csv",
)
pytest.fail("No exception raised when using an invalid parameter")
except SherlockExportAllTestPoints as e:
assert e.str_itr()[0] == "Export test points error: Project name is invalid."

try:
layer.export_all_test_points(
"Tutorial Project",
"",
"Test Points.csv",
)
pytest.fail("No exception raised when using an invalid parameter")
except SherlockExportAllTestPoints as e:
assert e.str_itr()[0] == "Export test points error: CCA name is invalid."

try:
layer.export_all_test_points(
"Tutorial Project",
"Main Board",
"",
)
pytest.fail("No exception raised when using an invalid parameter")
except SherlockExportAllTestPoints as e:
assert e.str_itr()[0] == "Export test points error: File path is required."

if layer._is_connection_up():
if platform.system() == "Windows":
temp_dir = os.environ.get("TEMP", "C:\\TEMP")
else:
temp_dir = os.environ.get("TEMP", "/tmp")
test_points_file = os.path.join(temp_dir, "test_points.csv")

try:
result = layer.export_all_test_points(
"Tutorial Project",
"Main Board",
test_points_file,
)

assert os.path.exists(test_points_file)
assert result == 0
except Exception as e:
pytest.fail(e.message)

try:
layer.export_all_test_points(
"Tutorial Project",
"Invalid CCA",
test_points_file,
)
pytest.fail("No exception raised when using an invalid parameter")
except Exception as e:
assert type(e) == SherlockExportAllTestPoints


if __name__ == "__main__":
test_all()