From 535ab35a6e74a25c8b5d313827e5cd9e6bd8c8de Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Tue, 7 Nov 2023 14:35:14 +0100 Subject: [PATCH 01/10] New listThermalMaps() API Create an API to list the thermal map files and their types --- src/ansys/sherlock/core/errors.py | 16 ++++++++ src/ansys/sherlock/core/project.py | 60 ++++++++++++++++++++++++++++++ tests/test_project.py | 38 +++++++++++++++++++ 3 files changed, 114 insertions(+) diff --git a/src/ansys/sherlock/core/errors.py b/src/ansys/sherlock/core/errors.py index 414690bfe..99f6636d5 100644 --- a/src/ansys/sherlock/core/errors.py +++ b/src/ansys/sherlock/core/errors.py @@ -909,3 +909,19 @@ def str_itr(self): assert self.error_array is None return [f"Update part from AVL error: {self.message}"] + +class SherlockListThermalMapsError(Exception): + """Contains the errors raised when thermal map files for a project cannot be listed.""" + + def __init__(self, message=None, error_array=None): + """Initialize error message.""" + self.message = message + self.error_array = error_array + + def str_itr(self): + """Format error message.""" + if self.message is None: + return [f"List thermal maps error: {error}" for error in self.error_array] + + assert self.error_array is None + return [f"List thermal maps error: {self.message}"] \ No newline at end of file diff --git a/src/ansys/sherlock/core/project.py b/src/ansys/sherlock/core/project.py index 9e640d3fc..e0d9e4cfb 100644 --- a/src/ansys/sherlock/core/project.py +++ b/src/ansys/sherlock/core/project.py @@ -21,6 +21,7 @@ SherlockImportODBError, SherlockListCCAsError, SherlockListStrainMapsError, + SherlockListThermalMapsError, ) from ansys.sherlock.core.grpc_stub import GrpcStub @@ -728,3 +729,62 @@ def add_project(self, project_name: str, project_category: str, project_descript raise SherlockAddProjectError(return_code.message) return return_code.value + + def list_thermal_maps(self, project, cca_names=None): + """List the thermal map files and their type assigned to each CCA of given CCAs + + Parameters + ---------- + project: str + Name of the Sherlock project. + cca_names : List of str, optional + List of CCA names to provide thermal maps for. The default is ``None``, + in which case all CCAs in the project are returned. + + Returns + ------- + list + All thermal map files or thermal map files and their type for the specified CCAs. + + Examples + -------- + >>> from ansys.sherlock.core.launcher import launch_sherlock + >>> sherlock = launch_sherlock() + >>> thermal_maps = sherlock.project.list_thermal_maps( + "AssemblyTutorial", + ["Main Board","Power Module"] + ) + """ + try: + if project == "": + raise SherlockListThermalMapsError(message="Project name is invalid.") + + if cca_names is not None and type(cca_names) is not list: + raise SherlockListThermalMapsError(message="cca_names is not a list.") + + if not self._is_connection_up(): + LOG.error("There is no connection to a gRPC service.") + return + + request = SherlockProjectService_pb2.ListThermalMapsRequest(project=project) + + """Add the CCA names to the request.""" + if cca_names is not None: + for cca_name in cca_names: + request.cca.append(cca_name) + + response = self.stub.listThermalMaps(request) + + return_code = response.returnCode + + if return_code.value == -1: + if return_code.message == "": + raise SherlockListThermalMapsError(error_array=response.errors) + + raise SherlockListThermalMapsError(message=return_code.message) + + except Exception as e: + LOG.error(str(e)) + raise e + + return response.ccaThermalMaps \ No newline at end of file diff --git a/tests/test_project.py b/tests/test_project.py index c8d0ccaef..4386d3a52 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -18,6 +18,7 @@ SherlockImportODBError, SherlockListCCAsError, SherlockListStrainMapsError, + SherlockListThermalMapsError, ) from ansys.sherlock.core.project import Project @@ -38,6 +39,7 @@ def test_all(): helper_test_list_ccas(project) helper_test_add_cca(project) helper_test_list_strain_maps(project) + helper_test_list_thermal_maps(project) project_name = None try: project_name = helper_test_add_project(project) @@ -597,6 +599,42 @@ def helper_test_add_project(project): except SherlockAddProjectError as e: pytest.fail(str(e)) +def helper_test_list_thermal_maps(project): + """Test list_thermal_maps API""" + + try: + project.list_thermal_maps("") + pytest.fail("No exception raised when using an invalid parameter") + except SherlockListThermalMapsError as e: + assert str(e.str_itr()) == "['List thermal maps error: Project name is invalid.']" + + try: + project.list_thermal_maps("Tutorial Project", "Not a list") + pytest.fail("No exception raised when using an invalid parameter") + except SherlockListThermalMapsError as e: + assert str(e.str_itr()) == "['List thermal maps error: cca_names is not a list.']" + + if project._is_connection_up(): + try: + project.list_thermal_maps("AssemblyTutorial", ["CCA name that doesn't exist"]) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockListThermalMapsError + + try: + thermal_maps = project.list_thermal_maps( + "Assembly Tutorial", ["Main Board"] + ) + assert len(thermal_maps) == 1 + thermal_map = thermal_maps[0] + assert thermal_map.ccaName == "Main Board" + assert len(thermal_map.thermalMaps) == 1 + thermal_map_info = thermal_map.thermalMaps[0] + assert "Thermal Map.csv" == thermal_map_info.fileName + assert "Thermal Map (CSV)" == thermal_map_info.fileType + except SherlockListThermalMapsError as e: + pytest.fail(str(e.str_itr())) + def clean_up_after_add(project, project_name): if project_name is not None: From f88cbaf515db95e23d1d030308d3b2967092c69c Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Tue, 7 Nov 2023 14:44:27 +0100 Subject: [PATCH 02/10] Fix code style --- src/ansys/sherlock/core/errors.py | 3 ++- src/ansys/sherlock/core/project.py | 4 ++-- tests/test_project.py | 5 ++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ansys/sherlock/core/errors.py b/src/ansys/sherlock/core/errors.py index 99f6636d5..2e58acf46 100644 --- a/src/ansys/sherlock/core/errors.py +++ b/src/ansys/sherlock/core/errors.py @@ -910,6 +910,7 @@ def str_itr(self): assert self.error_array is None return [f"Update part from AVL error: {self.message}"] + class SherlockListThermalMapsError(Exception): """Contains the errors raised when thermal map files for a project cannot be listed.""" @@ -924,4 +925,4 @@ def str_itr(self): return [f"List thermal maps error: {error}" for error in self.error_array] assert self.error_array is None - return [f"List thermal maps error: {self.message}"] \ No newline at end of file + return [f"List thermal maps error: {self.message}"] diff --git a/src/ansys/sherlock/core/project.py b/src/ansys/sherlock/core/project.py index e0d9e4cfb..e498795a7 100644 --- a/src/ansys/sherlock/core/project.py +++ b/src/ansys/sherlock/core/project.py @@ -731,7 +731,7 @@ def add_project(self, project_name: str, project_category: str, project_descript return return_code.value def list_thermal_maps(self, project, cca_names=None): - """List the thermal map files and their type assigned to each CCA of given CCAs + """List the thermal map files and their type assigned to each CCA of given CCAs. Parameters ---------- @@ -787,4 +787,4 @@ def list_thermal_maps(self, project, cca_names=None): LOG.error(str(e)) raise e - return response.ccaThermalMaps \ No newline at end of file + return response.ccaThermalMaps diff --git a/tests/test_project.py b/tests/test_project.py index 4386d3a52..6eefa512e 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -599,6 +599,7 @@ def helper_test_add_project(project): except SherlockAddProjectError as e: pytest.fail(str(e)) + def helper_test_list_thermal_maps(project): """Test list_thermal_maps API""" @@ -622,9 +623,7 @@ def helper_test_list_thermal_maps(project): assert type(e) == SherlockListThermalMapsError try: - thermal_maps = project.list_thermal_maps( - "Assembly Tutorial", ["Main Board"] - ) + thermal_maps = project.list_thermal_maps("Assembly Tutorial", ["Main Board"]) assert len(thermal_maps) == 1 thermal_map = thermal_maps[0] assert thermal_map.ccaName == "Main Board" From 76aef126c705f8f8168715cd6b8b07d069ceb437 Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:52:45 +0100 Subject: [PATCH 03/10] Updated test file --- src/ansys/sherlock/core/project.py | 3 +-- tests/test_project.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/ansys/sherlock/core/project.py b/src/ansys/sherlock/core/project.py index e498795a7..677a37d88 100644 --- a/src/ansys/sherlock/core/project.py +++ b/src/ansys/sherlock/core/project.py @@ -768,7 +768,6 @@ def list_thermal_maps(self, project, cca_names=None): request = SherlockProjectService_pb2.ListThermalMapsRequest(project=project) - """Add the CCA names to the request.""" if cca_names is not None: for cca_name in cca_names: request.cca.append(cca_name) @@ -783,7 +782,7 @@ def list_thermal_maps(self, project, cca_names=None): raise SherlockListThermalMapsError(message=return_code.message) - except Exception as e: + except SherlockListThermalMapsError as e: LOG.error(str(e)) raise e diff --git a/tests/test_project.py b/tests/test_project.py index 6eefa512e..b86c579f3 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -634,6 +634,33 @@ def helper_test_list_thermal_maps(project): except SherlockListThermalMapsError as e: pytest.fail(str(e.str_itr())) + try: + thermal_maps = project.list_thermal_maps("Assembly Tutorial") + assert len(thermal_maps) == 4 + for thermal_map in thermal_maps: + assert hasattr(thermal_map, "ccaName") # Check if ccaName attribute exists + assert hasattr(thermal_map, "thermalMaps") # Check if thermalMaps attribute exists + + # If thermalMaps is not None, check its elements + if thermal_map.thermalMaps: + for thermal_map_info in thermal_map.thermalMaps: + assert hasattr( + thermal_map_info, "fileName" + ) # Check if fileName attribute exists + assert hasattr( + thermal_map_info, "fileType" + ) # Check if fileType attribute exists + + # Perform specific checks for fileName and fileType + if thermal_map.ccaName == "Main Board": + assert thermal_map_info.fileName == "Thermal Map.csv" + assert thermal_map_info.fileType == "Thermal Map (CSV)" + elif thermal_map.ccaName == "TestAnalysisPropsUpdate": + assert thermal_map_info.fileName == "Thermal Map.csv" + assert thermal_map_info.fileType == "Thermal Map (CSV)" + except SherlockListThermalMapsError as e: + pytest.fail(str(e.str_itr())) + def clean_up_after_add(project, project_name): if project_name is not None: From 01d1938d20d401879b391d74a303ef5c01b218bd Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:31:05 +0100 Subject: [PATCH 04/10] Update test_project --- tests/test_project.py | 50 +++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index b86c579f3..fe607382d 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -603,6 +603,20 @@ def helper_test_add_project(project): def helper_test_list_thermal_maps(project): """Test list_thermal_maps API""" + expected_cca_name = "Main Board" + expected_file_names = [ + "Thermal Map.xlsx", + "Thermal Map.tmap", + "Thermal Image.jpg", + "Thermal Map.csv", + ] + expected_file_types = [ + "Thermal Map (Excel)", + "Icepak Thermal Map (TMAP)", + "Thermal Map (Image)", + "Thermal Map (CSV)", + ] + try: project.list_thermal_maps("") pytest.fail("No exception raised when using an invalid parameter") @@ -623,41 +637,39 @@ def helper_test_list_thermal_maps(project): assert type(e) == SherlockListThermalMapsError try: - thermal_maps = project.list_thermal_maps("Assembly Tutorial", ["Main Board"]) + thermal_maps = project.list_thermal_maps("Assembly Tutorial", [expected_cca_name]) assert len(thermal_maps) == 1 thermal_map = thermal_maps[0] - assert thermal_map.ccaName == "Main Board" - assert len(thermal_map.thermalMaps) == 1 - thermal_map_info = thermal_map.thermalMaps[0] - assert "Thermal Map.csv" == thermal_map_info.fileName - assert "Thermal Map (CSV)" == thermal_map_info.fileType + assert thermal_map.ccaName == expected_cca_name + assert len(thermal_map.thermalMaps) == len(expected_file_names) + + for i, thermal_map_info in enumerate(thermal_map.thermalMaps): + assert expected_file_names[i] == thermal_map_info.fileName + assert expected_file_types[i] == thermal_map_info.fileType except SherlockListThermalMapsError as e: pytest.fail(str(e.str_itr())) try: thermal_maps = project.list_thermal_maps("Assembly Tutorial") - assert len(thermal_maps) == 4 + assert len(thermal_maps) == len(expected_file_names) + for thermal_map in thermal_maps: - assert hasattr(thermal_map, "ccaName") # Check if ccaName attribute exists - assert hasattr(thermal_map, "thermalMaps") # Check if thermalMaps attribute exists + assert hasattr(thermal_map, "ccaName") and hasattr(thermal_map, "thermalMaps") - # If thermalMaps is not None, check its elements if thermal_map.thermalMaps: - for thermal_map_info in thermal_map.thermalMaps: - assert hasattr( - thermal_map_info, "fileName" - ) # Check if fileName attribute exists - assert hasattr( + for i, thermal_map_info in enumerate(thermal_map.thermalMaps): + assert hasattr(thermal_map_info, "fileName") and hasattr( thermal_map_info, "fileType" - ) # Check if fileType attribute exists + ) # Perform specific checks for fileName and fileType - if thermal_map.ccaName == "Main Board": - assert thermal_map_info.fileName == "Thermal Map.csv" - assert thermal_map_info.fileType == "Thermal Map (CSV)" + if thermal_map.ccaName == expected_cca_name: + assert expected_file_names[i] == thermal_map_info.fileName + assert expected_file_types[i] == thermal_map_info.fileType elif thermal_map.ccaName == "TestAnalysisPropsUpdate": assert thermal_map_info.fileName == "Thermal Map.csv" assert thermal_map_info.fileType == "Thermal Map (CSV)" + except SherlockListThermalMapsError as e: pytest.fail(str(e.str_itr())) From 113e815bba14fc551e604f5694f16d862b147779 Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Mon, 13 Nov 2023 18:40:47 +0100 Subject: [PATCH 05/10] Update test_project.py --- tests/test_project.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index fe607382d..5c7a09a7c 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -637,7 +637,7 @@ def helper_test_list_thermal_maps(project): assert type(e) == SherlockListThermalMapsError try: - thermal_maps = project.list_thermal_maps("Assembly Tutorial", [expected_cca_name]) + thermal_maps = project.list_thermal_maps("Tutorial Project", [expected_cca_name]) assert len(thermal_maps) == 1 thermal_map = thermal_maps[0] assert thermal_map.ccaName == expected_cca_name @@ -650,8 +650,7 @@ def helper_test_list_thermal_maps(project): pytest.fail(str(e.str_itr())) try: - thermal_maps = project.list_thermal_maps("Assembly Tutorial") - assert len(thermal_maps) == len(expected_file_names) + thermal_maps = project.list_thermal_maps("Tutorial Project") for thermal_map in thermal_maps: assert hasattr(thermal_map, "ccaName") and hasattr(thermal_map, "thermalMaps") @@ -662,13 +661,9 @@ def helper_test_list_thermal_maps(project): thermal_map_info, "fileType" ) - # Perform specific checks for fileName and fileType if thermal_map.ccaName == expected_cca_name: assert expected_file_names[i] == thermal_map_info.fileName assert expected_file_types[i] == thermal_map_info.fileType - elif thermal_map.ccaName == "TestAnalysisPropsUpdate": - assert thermal_map_info.fileName == "Thermal Map.csv" - assert thermal_map_info.fileType == "Thermal Map (CSV)" except SherlockListThermalMapsError as e: pytest.fail(str(e.str_itr())) From f2552a4a85100aad9d0cce42b055da0f3335c2c6 Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Tue, 7 Nov 2023 14:35:14 +0100 Subject: [PATCH 06/10] New listThermalMaps() API Create an API to list the thermal map files and their types --- src/ansys/sherlock/core/errors.py | 16 ++++++++ src/ansys/sherlock/core/project.py | 60 ++++++++++++++++++++++++++++++ tests/test_project.py | 38 +++++++++++++++++++ 3 files changed, 114 insertions(+) diff --git a/src/ansys/sherlock/core/errors.py b/src/ansys/sherlock/core/errors.py index 414690bfe..99f6636d5 100644 --- a/src/ansys/sherlock/core/errors.py +++ b/src/ansys/sherlock/core/errors.py @@ -909,3 +909,19 @@ def str_itr(self): assert self.error_array is None return [f"Update part from AVL error: {self.message}"] + +class SherlockListThermalMapsError(Exception): + """Contains the errors raised when thermal map files for a project cannot be listed.""" + + def __init__(self, message=None, error_array=None): + """Initialize error message.""" + self.message = message + self.error_array = error_array + + def str_itr(self): + """Format error message.""" + if self.message is None: + return [f"List thermal maps error: {error}" for error in self.error_array] + + assert self.error_array is None + return [f"List thermal maps error: {self.message}"] \ No newline at end of file diff --git a/src/ansys/sherlock/core/project.py b/src/ansys/sherlock/core/project.py index 9e640d3fc..e0d9e4cfb 100644 --- a/src/ansys/sherlock/core/project.py +++ b/src/ansys/sherlock/core/project.py @@ -21,6 +21,7 @@ SherlockImportODBError, SherlockListCCAsError, SherlockListStrainMapsError, + SherlockListThermalMapsError, ) from ansys.sherlock.core.grpc_stub import GrpcStub @@ -728,3 +729,62 @@ def add_project(self, project_name: str, project_category: str, project_descript raise SherlockAddProjectError(return_code.message) return return_code.value + + def list_thermal_maps(self, project, cca_names=None): + """List the thermal map files and their type assigned to each CCA of given CCAs + + Parameters + ---------- + project: str + Name of the Sherlock project. + cca_names : List of str, optional + List of CCA names to provide thermal maps for. The default is ``None``, + in which case all CCAs in the project are returned. + + Returns + ------- + list + All thermal map files or thermal map files and their type for the specified CCAs. + + Examples + -------- + >>> from ansys.sherlock.core.launcher import launch_sherlock + >>> sherlock = launch_sherlock() + >>> thermal_maps = sherlock.project.list_thermal_maps( + "AssemblyTutorial", + ["Main Board","Power Module"] + ) + """ + try: + if project == "": + raise SherlockListThermalMapsError(message="Project name is invalid.") + + if cca_names is not None and type(cca_names) is not list: + raise SherlockListThermalMapsError(message="cca_names is not a list.") + + if not self._is_connection_up(): + LOG.error("There is no connection to a gRPC service.") + return + + request = SherlockProjectService_pb2.ListThermalMapsRequest(project=project) + + """Add the CCA names to the request.""" + if cca_names is not None: + for cca_name in cca_names: + request.cca.append(cca_name) + + response = self.stub.listThermalMaps(request) + + return_code = response.returnCode + + if return_code.value == -1: + if return_code.message == "": + raise SherlockListThermalMapsError(error_array=response.errors) + + raise SherlockListThermalMapsError(message=return_code.message) + + except Exception as e: + LOG.error(str(e)) + raise e + + return response.ccaThermalMaps \ No newline at end of file diff --git a/tests/test_project.py b/tests/test_project.py index c8d0ccaef..4386d3a52 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -18,6 +18,7 @@ SherlockImportODBError, SherlockListCCAsError, SherlockListStrainMapsError, + SherlockListThermalMapsError, ) from ansys.sherlock.core.project import Project @@ -38,6 +39,7 @@ def test_all(): helper_test_list_ccas(project) helper_test_add_cca(project) helper_test_list_strain_maps(project) + helper_test_list_thermal_maps(project) project_name = None try: project_name = helper_test_add_project(project) @@ -597,6 +599,42 @@ def helper_test_add_project(project): except SherlockAddProjectError as e: pytest.fail(str(e)) +def helper_test_list_thermal_maps(project): + """Test list_thermal_maps API""" + + try: + project.list_thermal_maps("") + pytest.fail("No exception raised when using an invalid parameter") + except SherlockListThermalMapsError as e: + assert str(e.str_itr()) == "['List thermal maps error: Project name is invalid.']" + + try: + project.list_thermal_maps("Tutorial Project", "Not a list") + pytest.fail("No exception raised when using an invalid parameter") + except SherlockListThermalMapsError as e: + assert str(e.str_itr()) == "['List thermal maps error: cca_names is not a list.']" + + if project._is_connection_up(): + try: + project.list_thermal_maps("AssemblyTutorial", ["CCA name that doesn't exist"]) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockListThermalMapsError + + try: + thermal_maps = project.list_thermal_maps( + "Assembly Tutorial", ["Main Board"] + ) + assert len(thermal_maps) == 1 + thermal_map = thermal_maps[0] + assert thermal_map.ccaName == "Main Board" + assert len(thermal_map.thermalMaps) == 1 + thermal_map_info = thermal_map.thermalMaps[0] + assert "Thermal Map.csv" == thermal_map_info.fileName + assert "Thermal Map (CSV)" == thermal_map_info.fileType + except SherlockListThermalMapsError as e: + pytest.fail(str(e.str_itr())) + def clean_up_after_add(project, project_name): if project_name is not None: From 5e8b9650146a8a1fc48b8aacd12ad3512244fc6f Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Tue, 7 Nov 2023 14:44:27 +0100 Subject: [PATCH 07/10] Fix code style --- src/ansys/sherlock/core/errors.py | 3 ++- src/ansys/sherlock/core/project.py | 4 ++-- tests/test_project.py | 5 ++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ansys/sherlock/core/errors.py b/src/ansys/sherlock/core/errors.py index 99f6636d5..2e58acf46 100644 --- a/src/ansys/sherlock/core/errors.py +++ b/src/ansys/sherlock/core/errors.py @@ -910,6 +910,7 @@ def str_itr(self): assert self.error_array is None return [f"Update part from AVL error: {self.message}"] + class SherlockListThermalMapsError(Exception): """Contains the errors raised when thermal map files for a project cannot be listed.""" @@ -924,4 +925,4 @@ def str_itr(self): return [f"List thermal maps error: {error}" for error in self.error_array] assert self.error_array is None - return [f"List thermal maps error: {self.message}"] \ No newline at end of file + return [f"List thermal maps error: {self.message}"] diff --git a/src/ansys/sherlock/core/project.py b/src/ansys/sherlock/core/project.py index e0d9e4cfb..e498795a7 100644 --- a/src/ansys/sherlock/core/project.py +++ b/src/ansys/sherlock/core/project.py @@ -731,7 +731,7 @@ def add_project(self, project_name: str, project_category: str, project_descript return return_code.value def list_thermal_maps(self, project, cca_names=None): - """List the thermal map files and their type assigned to each CCA of given CCAs + """List the thermal map files and their type assigned to each CCA of given CCAs. Parameters ---------- @@ -787,4 +787,4 @@ def list_thermal_maps(self, project, cca_names=None): LOG.error(str(e)) raise e - return response.ccaThermalMaps \ No newline at end of file + return response.ccaThermalMaps diff --git a/tests/test_project.py b/tests/test_project.py index 4386d3a52..6eefa512e 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -599,6 +599,7 @@ def helper_test_add_project(project): except SherlockAddProjectError as e: pytest.fail(str(e)) + def helper_test_list_thermal_maps(project): """Test list_thermal_maps API""" @@ -622,9 +623,7 @@ def helper_test_list_thermal_maps(project): assert type(e) == SherlockListThermalMapsError try: - thermal_maps = project.list_thermal_maps( - "Assembly Tutorial", ["Main Board"] - ) + thermal_maps = project.list_thermal_maps("Assembly Tutorial", ["Main Board"]) assert len(thermal_maps) == 1 thermal_map = thermal_maps[0] assert thermal_map.ccaName == "Main Board" From b247f727cb8177acb262cf7efe475949bd4756fc Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:52:45 +0100 Subject: [PATCH 08/10] Updated test file --- src/ansys/sherlock/core/project.py | 3 +-- tests/test_project.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/ansys/sherlock/core/project.py b/src/ansys/sherlock/core/project.py index e498795a7..677a37d88 100644 --- a/src/ansys/sherlock/core/project.py +++ b/src/ansys/sherlock/core/project.py @@ -768,7 +768,6 @@ def list_thermal_maps(self, project, cca_names=None): request = SherlockProjectService_pb2.ListThermalMapsRequest(project=project) - """Add the CCA names to the request.""" if cca_names is not None: for cca_name in cca_names: request.cca.append(cca_name) @@ -783,7 +782,7 @@ def list_thermal_maps(self, project, cca_names=None): raise SherlockListThermalMapsError(message=return_code.message) - except Exception as e: + except SherlockListThermalMapsError as e: LOG.error(str(e)) raise e diff --git a/tests/test_project.py b/tests/test_project.py index 6eefa512e..b86c579f3 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -634,6 +634,33 @@ def helper_test_list_thermal_maps(project): except SherlockListThermalMapsError as e: pytest.fail(str(e.str_itr())) + try: + thermal_maps = project.list_thermal_maps("Assembly Tutorial") + assert len(thermal_maps) == 4 + for thermal_map in thermal_maps: + assert hasattr(thermal_map, "ccaName") # Check if ccaName attribute exists + assert hasattr(thermal_map, "thermalMaps") # Check if thermalMaps attribute exists + + # If thermalMaps is not None, check its elements + if thermal_map.thermalMaps: + for thermal_map_info in thermal_map.thermalMaps: + assert hasattr( + thermal_map_info, "fileName" + ) # Check if fileName attribute exists + assert hasattr( + thermal_map_info, "fileType" + ) # Check if fileType attribute exists + + # Perform specific checks for fileName and fileType + if thermal_map.ccaName == "Main Board": + assert thermal_map_info.fileName == "Thermal Map.csv" + assert thermal_map_info.fileType == "Thermal Map (CSV)" + elif thermal_map.ccaName == "TestAnalysisPropsUpdate": + assert thermal_map_info.fileName == "Thermal Map.csv" + assert thermal_map_info.fileType == "Thermal Map (CSV)" + except SherlockListThermalMapsError as e: + pytest.fail(str(e.str_itr())) + def clean_up_after_add(project, project_name): if project_name is not None: From 8e8ce2d9a416a346ecb7875848f16552b720fa3f Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:31:05 +0100 Subject: [PATCH 09/10] Update test_project --- tests/test_project.py | 50 +++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index b86c579f3..fe607382d 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -603,6 +603,20 @@ def helper_test_add_project(project): def helper_test_list_thermal_maps(project): """Test list_thermal_maps API""" + expected_cca_name = "Main Board" + expected_file_names = [ + "Thermal Map.xlsx", + "Thermal Map.tmap", + "Thermal Image.jpg", + "Thermal Map.csv", + ] + expected_file_types = [ + "Thermal Map (Excel)", + "Icepak Thermal Map (TMAP)", + "Thermal Map (Image)", + "Thermal Map (CSV)", + ] + try: project.list_thermal_maps("") pytest.fail("No exception raised when using an invalid parameter") @@ -623,41 +637,39 @@ def helper_test_list_thermal_maps(project): assert type(e) == SherlockListThermalMapsError try: - thermal_maps = project.list_thermal_maps("Assembly Tutorial", ["Main Board"]) + thermal_maps = project.list_thermal_maps("Assembly Tutorial", [expected_cca_name]) assert len(thermal_maps) == 1 thermal_map = thermal_maps[0] - assert thermal_map.ccaName == "Main Board" - assert len(thermal_map.thermalMaps) == 1 - thermal_map_info = thermal_map.thermalMaps[0] - assert "Thermal Map.csv" == thermal_map_info.fileName - assert "Thermal Map (CSV)" == thermal_map_info.fileType + assert thermal_map.ccaName == expected_cca_name + assert len(thermal_map.thermalMaps) == len(expected_file_names) + + for i, thermal_map_info in enumerate(thermal_map.thermalMaps): + assert expected_file_names[i] == thermal_map_info.fileName + assert expected_file_types[i] == thermal_map_info.fileType except SherlockListThermalMapsError as e: pytest.fail(str(e.str_itr())) try: thermal_maps = project.list_thermal_maps("Assembly Tutorial") - assert len(thermal_maps) == 4 + assert len(thermal_maps) == len(expected_file_names) + for thermal_map in thermal_maps: - assert hasattr(thermal_map, "ccaName") # Check if ccaName attribute exists - assert hasattr(thermal_map, "thermalMaps") # Check if thermalMaps attribute exists + assert hasattr(thermal_map, "ccaName") and hasattr(thermal_map, "thermalMaps") - # If thermalMaps is not None, check its elements if thermal_map.thermalMaps: - for thermal_map_info in thermal_map.thermalMaps: - assert hasattr( - thermal_map_info, "fileName" - ) # Check if fileName attribute exists - assert hasattr( + for i, thermal_map_info in enumerate(thermal_map.thermalMaps): + assert hasattr(thermal_map_info, "fileName") and hasattr( thermal_map_info, "fileType" - ) # Check if fileType attribute exists + ) # Perform specific checks for fileName and fileType - if thermal_map.ccaName == "Main Board": - assert thermal_map_info.fileName == "Thermal Map.csv" - assert thermal_map_info.fileType == "Thermal Map (CSV)" + if thermal_map.ccaName == expected_cca_name: + assert expected_file_names[i] == thermal_map_info.fileName + assert expected_file_types[i] == thermal_map_info.fileType elif thermal_map.ccaName == "TestAnalysisPropsUpdate": assert thermal_map_info.fileName == "Thermal Map.csv" assert thermal_map_info.fileType == "Thermal Map (CSV)" + except SherlockListThermalMapsError as e: pytest.fail(str(e.str_itr())) From b88b3bbc561982697fcc6b2b80bf033ba8f23ad0 Mon Sep 17 00:00:00 2001 From: Nayane Fernandes <143632290+ansnfernand@users.noreply.github.com> Date: Mon, 13 Nov 2023 18:40:47 +0100 Subject: [PATCH 10/10] Update test_project.py --- tests/test_project.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index fe607382d..5c7a09a7c 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -637,7 +637,7 @@ def helper_test_list_thermal_maps(project): assert type(e) == SherlockListThermalMapsError try: - thermal_maps = project.list_thermal_maps("Assembly Tutorial", [expected_cca_name]) + thermal_maps = project.list_thermal_maps("Tutorial Project", [expected_cca_name]) assert len(thermal_maps) == 1 thermal_map = thermal_maps[0] assert thermal_map.ccaName == expected_cca_name @@ -650,8 +650,7 @@ def helper_test_list_thermal_maps(project): pytest.fail(str(e.str_itr())) try: - thermal_maps = project.list_thermal_maps("Assembly Tutorial") - assert len(thermal_maps) == len(expected_file_names) + thermal_maps = project.list_thermal_maps("Tutorial Project") for thermal_map in thermal_maps: assert hasattr(thermal_map, "ccaName") and hasattr(thermal_map, "thermalMaps") @@ -662,13 +661,9 @@ def helper_test_list_thermal_maps(project): thermal_map_info, "fileType" ) - # Perform specific checks for fileName and fileType if thermal_map.ccaName == expected_cca_name: assert expected_file_names[i] == thermal_map_info.fileName assert expected_file_types[i] == thermal_map_info.fileType - elif thermal_map.ccaName == "TestAnalysisPropsUpdate": - assert thermal_map_info.fileName == "Thermal Map.csv" - assert thermal_map_info.fileType == "Thermal Map (CSV)" except SherlockListThermalMapsError as e: pytest.fail(str(e.str_itr()))