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 @@ -1136,3 +1136,15 @@ def __init__(self, message):
def __str__(self):
"""Format error message."""
return f"Export test fixtures error: {self.message}"


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

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

def __str__(self):
"""Format error message."""
return f"Export mount points error: {self.message}"
78 changes: 78 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,
SherlockExportAllMountPoints,
SherlockExportAllTestFixtures,
SherlockExportAllTestPoints,
SherlockUpdateMountPointsByFileError,
Expand Down Expand Up @@ -811,3 +812,80 @@ def export_all_test_fixtures(
raise e

return response.value

def export_all_mount_points(
self,
project,
cca_name,
export_file,
units="DEFAULT",
):
"""Export the mount 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 mount points list to.
units : str, optional
Units to use when exporting the mount 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_mount_points(
"Tutorial Project",
"Card",
"MountPointsExport.csv",
"DEFAULT",
)
"""
try:
if project == "":
raise SherlockExportAllMountPoints(message="Project name is invalid.")
if cca_name == "":
raise SherlockExportAllMountPoints(message="CCA name is invalid.")
if export_file == "":
raise SherlockExportAllMountPoints(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.ExportAllMountPointsRequest(
project=project,
ccaName=cca_name,
filePath=export_file,
units=units,
)

response = self.stub.exportAllMountPoints(request)

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

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

return response.value
64 changes: 64 additions & 0 deletions tests/test_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
SherlockDeleteAllICTFixturesError,
SherlockDeleteAllMountPointsError,
SherlockDeleteAllTestPointsError,
SherlockExportAllMountPoints,
SherlockExportAllTestFixtures,
SherlockExportAllTestPoints,
SherlockUpdateMountPointsByFileError,
Expand All @@ -34,6 +35,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_mount_points(layer)
helper_test_export_all_test_fixtures(layer)
helper_test_export_all_test_points(layer)

Expand Down Expand Up @@ -654,5 +656,67 @@ def helper_test_export_all_test_fixtures(layer):
assert type(e) == SherlockExportAllTestFixtures


def helper_test_export_all_mount_points(layer):
"""Tests export_all_mount_points API."""
try:
layer.export_all_mount_points(
"",
"Main Board",
"Mount Points.csv",
)
pytest.fail("No exception raised when using an invalid parameter")
except SherlockExportAllMountPoints as e:
assert str(e) == "Export mount points error: Project name is invalid."

try:
layer.export_all_mount_points(
"Tutorial Project",
"",
"Mount Points.csv",
)
pytest.fail("No exception raised when using an invalid parameter")
except SherlockExportAllMountPoints as e:
assert str(e) == "Export mount points error: CCA name is invalid."

try:
layer.export_all_mount_points(
"Tutorial Project",
"Main Board",
"",
)
pytest.fail("No exception raised when using an invalid parameter")
except SherlockExportAllMountPoints as e:
assert str(e) == "Export mount 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")
mount_points_file = os.path.join(temp_dir, "mount_points.csv")

try:
result = layer.export_all_mount_points(
"Tutorial Project",
"Main Board",
mount_points_file,
)

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

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


if __name__ == "__main__":
test_all()