From c4b65a3456dd4bec9b2b50f5792dc681b7858b45 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Fri, 5 Jul 2024 12:13:12 -0400 Subject: [PATCH 01/23] Create CCA from modeling region API + tests added --- src/ansys/sherlock/core/errors.py | 14 +- src/ansys/sherlock/core/project.py | 149 +++++++++++++++++ tests/test_project.py | 252 +++++++++++++++++++++++------ 3 files changed, 367 insertions(+), 48 deletions(-) diff --git a/src/ansys/sherlock/core/errors.py b/src/ansys/sherlock/core/errors.py index a0ae5be06..08a54319a 100644 --- a/src/ansys/sherlock/core/errors.py +++ b/src/ansys/sherlock/core/errors.py @@ -1121,7 +1121,6 @@ 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}"] @@ -1148,3 +1147,16 @@ def __init__(self, message): def __str__(self): """Format error message.""" return f"Export mount points error: {self.message}" + + +class SherlockCreateCCAFromModelingRegionError(Exception): + """Contains the error raised when a CCA cannot be created from a modeling region.""" + + def __init__(self, message): + """Initialize error message.""" + self.message = message + + def __str__(self): + """Format error message.""" + return f"Create CCA from modeling region error: {self.message}" + diff --git a/src/ansys/sherlock/core/project.py b/src/ansys/sherlock/core/project.py index f0c85320f..96accc582 100644 --- a/src/ansys/sherlock/core/project.py +++ b/src/ansys/sherlock/core/project.py @@ -27,6 +27,7 @@ SherlockListStrainMapsError, SherlockListThermalMapsError, SherlockUpdateThermalMapsError, + SherlockCreateCCAFromModelingRegionError, ) from ansys.sherlock.core.grpc_stub import GrpcStub from ansys.sherlock.core.types.project_types import ( @@ -1793,3 +1794,151 @@ def export_project( raise e return response.value + + def create_cca_from_modeling_region(self, project, cca_from_mr_properties): + """Create one or more CCAs from modeling regions in a given project. + + Parameters + ---------- + project : str + Name of the Sherlock project. + cca_from_mr_properties : list + List of CCAs to be to be created from modeling regions + consisting of these properties: + + - cca_name : str + Name of the CCA. + - modeling_region_id : str + Name of the modeling region. + - description : str + Description of the CCA. + - default_solder_type: str + The default solder type. The default is ``None``. + - default_stencil_thickness: float + The default stencil thickness. The default is ``None``. + - default_stencil_thickness_units: str + Units for default stencil thickness. The default is ``None``. + - default_part_temp_rise: float + Default part temp rise. The default is ``None``. + - default_part_temp_rise_units: str + Units for default part temp rise. The default is ``None``. + Options are ``"C"``, ``"F"``, and ``"K"``. + - guess_part_properties: bool + Whether to enable guess part properties. The default is ``None``. + - generate_image_layers: bool + Whether to generate image layers or not. The default is ``None``. + + 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.project.create_cca_from_modeling_region() + "Test", + [{ + 'cca_name': 'Card', + 'modeling_region_id': 'MR1' + 'description': 'Test', + 'default_solder_type': 'SAC305', + 'default_stencil_thickness': 10, + 'default_stencil_thickness_units': 'mm', + 'default_part_temp_rise': 20, + 'default_part_temp_rise_units': 'C', + 'guess_part_properties': False, + 'generate_image_layers': False, + }, + ] + )""" + + try: + if project == "": + raise SherlockCreateCCAFromModelingRegionError(message="Project name is invalid.") + + if not isinstance(cca_from_mr_properties, list): + raise SherlockCreateCCAFromModelingRegionError(message="CCA properties argument is invalid.") + + if len(cca_from_mr_properties) == 0: + raise SherlockCreateCCAFromModelingRegionError(message="One or more CCAs are required.") + + request = SherlockProjectService_pb2.CreateCcaFromModelingRegionRequest(project=project) + + for i, cca in enumerate(cca_from_mr_properties): + + cca_request = request.cCAsFromModelingRegions.add() + + if not isinstance(cca, dict): + raise SherlockCreateCCAFromModelingRegionError(message=f"CCA properties are invalid for CCA {i}.") + + if "cca_name" not in cca.keys(): + raise SherlockCreateCCAFromModelingRegionError(message=f"CCA name is missing for CCA {i}.") + + if "modeling_region_id" not in cca.keys(): + raise SherlockCreateCCAFromModelingRegionError(message=f"Modeling Region ID is missing for CCA {i}.") + + cca_request.ccaName = cca["cca_name"] + cca_request.modelingRegionID = cca["modeling_region_id"] + + if cca_request.ccaName == "": + raise SherlockCreateCCAFromModelingRegionError(message=f"CCA name is invalid for CCA {i}.") + + if cca_request.modelingRegionID == "": + raise SherlockCreateCCAFromModelingRegionError(message=f"Modeling Region ID is invalid for CCA {i}.") + + if "description" in cca.keys(): + cca_request.description = cca["description"] + + if "default_solder_type" in cca.keys(): + cca_request.defaultSolderType = cca["default_solder_type"] + + if "default_stencil_thickness" in cca.keys(): + cca_request.defaultStencilThickness = cca["default_stencil_thickness"] + + if "default_stencil_thickness_units" in cca.keys(): + cca_request.defaultStencilThicknessUnits = cca[ + "default_stencil_thickness_units" + ] + + if "default_part_temp_rise" in cca.keys(): + cca_request.defaultPartTempRise = cca["default_part_temp_rise"] + + if "default_part_temp_rise_units" in cca.keys(): + cca_request.defaultPartTempRiseUnits = cca["default_part_temp_rise_units"] + + if "guess_part_properties" in cca.keys(): + cca_request.guessPartProperties = cca["guess_part_properties"] + + if "generate_image_layers" in cca.keys(): + cca_request.generateImageLayers = cca["generate_image_layers"] + + except SherlockCreateCCAFromModelingRegionError as e: + LOG.error(str(e)) + raise e + + if not self._is_connection_up(): + LOG.error("There is no connection to a gRPC service.") + return + + response = self.stub.createCCAFromModelingRegion(request) + + try: + if response.value == -1: + raise SherlockCreateCCAFromModelingRegionError(response.message) + else: + LOG.info(response.message) + return response.value + except SherlockCreateCCAFromModelingRegionError as e: + LOG.error(str(e)) + raise e diff --git a/tests/test_project.py b/tests/test_project.py index 14085fadb..327e87af1 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -24,6 +24,7 @@ SherlockListStrainMapsError, SherlockListThermalMapsError, SherlockUpdateThermalMapsError, + SherlockCreateCCAFromModelingRegionError, ) from ansys.sherlock.core.project import Project from ansys.sherlock.core.types.project_types import ( @@ -61,6 +62,7 @@ def test_all(): helper_test_add_thermal_maps(project) helper_test_update_thermal_maps(project) helper_test_list_thermal_maps(project) + helper_test_create_cca_from_modeling_region(project) project_name = None try: project_name = helper_test_add_project(project) @@ -394,8 +396,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count is required for strain map 0.']" ) try: @@ -417,8 +419,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count must be greater than or equal to 0 for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count must be greater than or equal to 0 for strain map 0.']" ) try: @@ -440,8 +442,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Reference ID column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Reference ID column is required for strain map 0.']" ) try: @@ -463,8 +465,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain column is required for strain map 0.']" ) try: @@ -486,8 +488,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain units are required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain units are required for strain map 0.']" ) try: @@ -509,8 +511,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' - "are invalid for strain map 0.']" + str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' + "are invalid for strain map 0.']" ) try: @@ -533,8 +535,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "cca_names is not a list for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "cca_names is not a list for strain map 0.']" ) try: @@ -596,8 +598,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count is required for strain map 0.']" ) try: @@ -619,8 +621,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count must be greater than or equal to 0 for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count must be greater than or equal to 0 for strain map 0.']" ) try: @@ -642,8 +644,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Reference ID column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Reference ID column is required for strain map 0.']" ) try: @@ -665,8 +667,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain column is required for strain map 0.']" ) try: @@ -688,8 +690,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain units are required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain units are required for strain map 0.']" ) try: @@ -711,8 +713,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' - "are invalid for strain map 0.']" + str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' + "are invalid for strain map 0.']" ) try: @@ -735,8 +737,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "cca_names is not a list for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "cca_names is not a list for strain map 0.']" ) try: @@ -765,7 +767,7 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " "Path is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " "Path is required for strain map 0.']" ) try: @@ -785,8 +787,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "image_file is not a list for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "image_file is not a list for strain map 0.']" ) try: @@ -815,8 +817,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid board bounds for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid board bounds for strain map 0.']" ) try: @@ -846,8 +848,8 @@ def helper_test_add_strain_maps(project): except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid coordinate units for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid coordinate units for strain map 0.']" ) try: @@ -877,8 +879,8 @@ def helper_test_add_strain_maps(project): except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid image bounds for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid image bounds for strain map 0.']" ) try: @@ -907,8 +909,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid legend bounds for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid legend bounds for strain map 0.']" ) try: @@ -937,8 +939,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid legend orientation for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid legend orientation for strain map 0.']" ) try: @@ -967,8 +969,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid minimum strain for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid minimum strain for strain map 0.']" ) try: @@ -997,8 +999,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid maximum strain for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid maximum strain for strain map 0.']" ) try: @@ -1027,8 +1029,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid strain units for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid strain units for strain map 0.']" ) if project._is_connection_up(): @@ -3066,5 +3068,161 @@ def helper_test_export_project(project): pytest.fail(str(e)) +def helper_test_create_cca_from_modeling_region(project): + """Test create_cca_from_modeling_region API""" + try: + project.create_cca_from_modeling_region( + "", + [ + { + "cca_name": "Main Board", + "modeling_region_id": "MR1", + "description": "test MR1", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "mm", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties_enabled": False, + "generate_image_layers": False, + }, + ], + ) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: Project " \ + "name is invalid." + + try: + project.create_cca_from_modeling_region("Test", "") + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: CCA " \ + "properties argument is invalid." + + try: + project.create_cca_from_modeling_region("Test", []) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: One or more CCAs are required." + + try: + project.create_cca_from_modeling_region("Test", [""]) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: CCA properties " \ + "are invalid for CCA 0." + + try: + project.create_cca_from_modeling_region( + "Test", + [ + { + "modeling_region_id": "MR1", + "description": "tests MR1", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "mm", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: CCA name is missing for CCA 0." + + try: + project.create_cca_from_modeling_region( + "Test", + [ + { + "cca_name": "", + "modeling_region_id": "MR1", + "description": "Test", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "mm", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: CCA name is invalid for CCA 0." + + try: + project.create_cca_from_modeling_region( + "Test", + [ + { + "cca_name": "Main Board", + "description": "Test", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "mm", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: Modeling Region ID" \ + " is missing for CCA 0." + + try: + project.create_cca_from_modeling_region( + "Test", + [ + { + "cca_name": "Card", + "modeling_region_id": "", + "description": "Test", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "mm", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: Modeling Region ID" \ + " is invalid for CCA 0." + + try: + project.create_cca_from_modeling_region( + "Tutorial Project", + [ + { + "cca_name": "Main Board", + "modeling_region_id": "MR1", + "description": "Test", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "INVALID", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockCreateCCAFromModelingRegionError + + if __name__ == "__main__": test_all() From 4036ead9639d160ec448ed1ce90d585f29d6b5c1 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Tue, 9 Jul 2024 09:35:32 -0400 Subject: [PATCH 02/23] Fixed syntax errors in errors.py and project.py --- src/ansys/sherlock/core/project.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/sherlock/core/project.py b/src/ansys/sherlock/core/project.py index 96accc582..efb93c673 100644 --- a/src/ansys/sherlock/core/project.py +++ b/src/ansys/sherlock/core/project.py @@ -1861,8 +1861,8 @@ def create_cca_from_modeling_region(self, project, cca_from_mr_properties): 'generate_image_layers': False, }, ] - )""" - + ) + """ try: if project == "": raise SherlockCreateCCAFromModelingRegionError(message="Project name is invalid.") From 9208df00ed72374b2c73ab982d99cf623b7def7a Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:03:41 -0400 Subject: [PATCH 03/23] test empty From e6b5bc41b07f2336e4ac07e12d04592a194d0f1c Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:28:41 -0400 Subject: [PATCH 04/23] test --- src/ansys/sherlock/core/errors.py | 1 - src/ansys/sherlock/core/project.py | 161 ++++++++++++++++------------- tests/test_project.py | 123 +++++++++++----------- 3 files changed, 152 insertions(+), 133 deletions(-) diff --git a/src/ansys/sherlock/core/errors.py b/src/ansys/sherlock/core/errors.py index 08a54319a..b4894c91b 100644 --- a/src/ansys/sherlock/core/errors.py +++ b/src/ansys/sherlock/core/errors.py @@ -1159,4 +1159,3 @@ def __init__(self, message): def __str__(self): """Format error message.""" return f"Create CCA from modeling region error: {self.message}" - diff --git a/src/ansys/sherlock/core/project.py b/src/ansys/sherlock/core/project.py index efb93c673..82561530e 100644 --- a/src/ansys/sherlock/core/project.py +++ b/src/ansys/sherlock/core/project.py @@ -16,6 +16,7 @@ SherlockAddProjectError, SherlockAddStrainMapsError, SherlockAddThermalMapsError, + SherlockCreateCCAFromModelingRegionError, SherlockDeleteProjectError, SherlockExportProjectError, SherlockGenerateProjectReportError, @@ -27,7 +28,6 @@ SherlockListStrainMapsError, SherlockListThermalMapsError, SherlockUpdateThermalMapsError, - SherlockCreateCCAFromModelingRegionError, ) from ansys.sherlock.core.grpc_stub import GrpcStub from ansys.sherlock.core.types.project_types import ( @@ -1798,104 +1798,117 @@ def export_project( def create_cca_from_modeling_region(self, project, cca_from_mr_properties): """Create one or more CCAs from modeling regions in a given project. - Parameters - ---------- - project : str - Name of the Sherlock project. - cca_from_mr_properties : list - List of CCAs to be to be created from modeling regions - consisting of these properties: - - - cca_name : str - Name of the CCA. - - modeling_region_id : str - Name of the modeling region. - - description : str - Description of the CCA. - - default_solder_type: str - The default solder type. The default is ``None``. - - default_stencil_thickness: float - The default stencil thickness. The default is ``None``. - - default_stencil_thickness_units: str - Units for default stencil thickness. The default is ``None``. - - default_part_temp_rise: float - Default part temp rise. The default is ``None``. - - default_part_temp_rise_units: str - Units for default part temp rise. The default is ``None``. - Options are ``"C"``, ``"F"``, and ``"K"``. - - guess_part_properties: bool - Whether to enable guess part properties. The default is ``None``. - - generate_image_layers: bool - Whether to generate image layers or not. The default is ``None``. - - 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.project.create_cca_from_modeling_region() - "Test", - [{ - 'cca_name': 'Card', - 'modeling_region_id': 'MR1' - 'description': 'Test', - 'default_solder_type': 'SAC305', - 'default_stencil_thickness': 10, - 'default_stencil_thickness_units': 'mm', - 'default_part_temp_rise': 20, - 'default_part_temp_rise_units': 'C', - 'guess_part_properties': False, - 'generate_image_layers': False, - }, - ] - ) - """ + Parameters + ---------- + project : str + Name of the Sherlock project. + cca_from_mr_properties : list + List of CCAs to be to be created from modeling regions + consisting of these properties: + + - cca_name : str + Name of the CCA. + - modeling_region_id : str + Name of the modeling region. + - description : str + Description of the CCA. + - default_solder_type: str + The default solder type. The default is ``None``. + - default_stencil_thickness: float + The default stencil thickness. The default is ``None``. + - default_stencil_thickness_units: str + Units for default stencil thickness. The default is ``None``. + - default_part_temp_rise: float + Default part temp rise. The default is ``None``. + - default_part_temp_rise_units: str + Units for default part temp rise. The default is ``None``. + Options are ``"C"``, ``"F"``, and ``"K"``. + - guess_part_properties: bool + Whether to enable guess part properties. The default is ``None``. + - generate_image_layers: bool + Whether to generate image layers or not. The default is ``None``. + + 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.project.create_cca_from_modeling_region() + "Test", + [{ + 'cca_name': 'Card', + 'modeling_region_id': 'MR1' + 'description': 'Test', + 'default_solder_type': 'SAC305', + 'default_stencil_thickness': 10, + 'default_stencil_thickness_units': 'mm', + 'default_part_temp_rise': 20, + 'default_part_temp_rise_units': 'C', + 'guess_part_properties': False, + 'generate_image_layers': False, + }, + ] + ) + """ try: if project == "": raise SherlockCreateCCAFromModelingRegionError(message="Project name is invalid.") if not isinstance(cca_from_mr_properties, list): - raise SherlockCreateCCAFromModelingRegionError(message="CCA properties argument is invalid.") + raise SherlockCreateCCAFromModelingRegionError( + message="CCA properties argument is invalid." + ) if len(cca_from_mr_properties) == 0: - raise SherlockCreateCCAFromModelingRegionError(message="One or more CCAs are required.") + raise SherlockCreateCCAFromModelingRegionError( + message="One or more CCAs are required." + ) request = SherlockProjectService_pb2.CreateCcaFromModelingRegionRequest(project=project) for i, cca in enumerate(cca_from_mr_properties): - cca_request = request.cCAsFromModelingRegions.add() if not isinstance(cca, dict): - raise SherlockCreateCCAFromModelingRegionError(message=f"CCA properties are invalid for CCA {i}.") + raise SherlockCreateCCAFromModelingRegionError( + message=f"CCA properties are invalid for CCA {i}." + ) if "cca_name" not in cca.keys(): - raise SherlockCreateCCAFromModelingRegionError(message=f"CCA name is missing for CCA {i}.") + raise SherlockCreateCCAFromModelingRegionError( + message=f"CCA name is missing for CCA {i}." + ) if "modeling_region_id" not in cca.keys(): - raise SherlockCreateCCAFromModelingRegionError(message=f"Modeling Region ID is missing for CCA {i}.") + raise SherlockCreateCCAFromModelingRegionError( + message=f"Modeling Region ID is missing for CCA {i}." + ) cca_request.ccaName = cca["cca_name"] cca_request.modelingRegionID = cca["modeling_region_id"] if cca_request.ccaName == "": - raise SherlockCreateCCAFromModelingRegionError(message=f"CCA name is invalid for CCA {i}.") + raise SherlockCreateCCAFromModelingRegionError( + message=f"CCA name is invalid for CCA {i}." + ) if cca_request.modelingRegionID == "": - raise SherlockCreateCCAFromModelingRegionError(message=f"Modeling Region ID is invalid for CCA {i}.") + raise SherlockCreateCCAFromModelingRegionError( + message=f"Modeling Region ID is invalid for CCA {i}." + ) if "description" in cca.keys(): cca_request.description = cca["description"] diff --git a/tests/test_project.py b/tests/test_project.py index 327e87af1..059d661ca 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -13,6 +13,7 @@ SherlockAddProjectError, SherlockAddStrainMapsError, SherlockAddThermalMapsError, + SherlockCreateCCAFromModelingRegionError, SherlockDeleteProjectError, SherlockExportProjectError, SherlockGenerateProjectReportError, @@ -24,7 +25,6 @@ SherlockListStrainMapsError, SherlockListThermalMapsError, SherlockUpdateThermalMapsError, - SherlockCreateCCAFromModelingRegionError, ) from ansys.sherlock.core.project import Project from ansys.sherlock.core.types.project_types import ( @@ -396,8 +396,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count is required for strain map 0.']" ) try: @@ -419,8 +419,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count must be greater than or equal to 0 for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count must be greater than or equal to 0 for strain map 0.']" ) try: @@ -442,8 +442,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Reference ID column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Reference ID column is required for strain map 0.']" ) try: @@ -465,8 +465,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain column is required for strain map 0.']" ) try: @@ -488,8 +488,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain units are required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain units are required for strain map 0.']" ) try: @@ -511,8 +511,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' - "are invalid for strain map 0.']" + str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' + "are invalid for strain map 0.']" ) try: @@ -535,8 +535,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "cca_names is not a list for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "cca_names is not a list for strain map 0.']" ) try: @@ -598,8 +598,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count is required for strain map 0.']" ) try: @@ -621,8 +621,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count must be greater than or equal to 0 for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count must be greater than or equal to 0 for strain map 0.']" ) try: @@ -644,8 +644,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Reference ID column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Reference ID column is required for strain map 0.']" ) try: @@ -667,8 +667,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain column is required for strain map 0.']" ) try: @@ -690,8 +690,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain units are required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain units are required for strain map 0.']" ) try: @@ -713,8 +713,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' - "are invalid for strain map 0.']" + str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' + "are invalid for strain map 0.']" ) try: @@ -737,8 +737,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "cca_names is not a list for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "cca_names is not a list for strain map 0.']" ) try: @@ -767,7 +767,7 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " "Path is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " "Path is required for strain map 0.']" ) try: @@ -787,8 +787,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "image_file is not a list for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "image_file is not a list for strain map 0.']" ) try: @@ -817,8 +817,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid board bounds for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid board bounds for strain map 0.']" ) try: @@ -848,8 +848,8 @@ def helper_test_add_strain_maps(project): except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid coordinate units for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid coordinate units for strain map 0.']" ) try: @@ -879,8 +879,8 @@ def helper_test_add_strain_maps(project): except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid image bounds for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid image bounds for strain map 0.']" ) try: @@ -909,8 +909,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid legend bounds for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid legend bounds for strain map 0.']" ) try: @@ -939,8 +939,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid legend orientation for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid legend orientation for strain map 0.']" ) try: @@ -969,8 +969,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid minimum strain for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid minimum strain for strain map 0.']" ) try: @@ -999,8 +999,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid maximum strain for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid maximum strain for strain map 0.']" ) try: @@ -1029,8 +1029,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid strain units for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid strain units for strain map 0.']" ) if project._is_connection_up(): @@ -3090,15 +3090,16 @@ def helper_test_create_cca_from_modeling_region(project): ) assert False except SherlockCreateCCAFromModelingRegionError as e: - assert str(e) == "Create CCA from modeling region error: Project " \ - "name is invalid." + assert str(e) == "Create CCA from modeling region error: Project " "name is invalid." try: project.create_cca_from_modeling_region("Test", "") assert False except SherlockCreateCCAFromModelingRegionError as e: - assert str(e) == "Create CCA from modeling region error: CCA " \ - "properties argument is invalid." + assert ( + str(e) == "Create CCA from modeling region error: CCA " + "properties argument is invalid." + ) try: project.create_cca_from_modeling_region("Test", []) @@ -3110,8 +3111,10 @@ def helper_test_create_cca_from_modeling_region(project): project.create_cca_from_modeling_region("Test", [""]) assert False except SherlockCreateCCAFromModelingRegionError as e: - assert str(e) == "Create CCA from modeling region error: CCA properties " \ - "are invalid for CCA 0." + assert ( + str(e) == "Create CCA from modeling region error: CCA properties " + "are invalid for CCA 0." + ) try: project.create_cca_from_modeling_region( @@ -3175,8 +3178,10 @@ def helper_test_create_cca_from_modeling_region(project): ) assert False except SherlockCreateCCAFromModelingRegionError as e: - assert str(e) == "Create CCA from modeling region error: Modeling Region ID" \ - " is missing for CCA 0." + assert ( + str(e) == "Create CCA from modeling region error: Modeling Region ID" + " is missing for CCA 0." + ) try: project.create_cca_from_modeling_region( @@ -3198,8 +3203,10 @@ def helper_test_create_cca_from_modeling_region(project): ) assert False except SherlockCreateCCAFromModelingRegionError as e: - assert str(e) == "Create CCA from modeling region error: Modeling Region ID" \ - " is invalid for CCA 0." + assert ( + str(e) == "Create CCA from modeling region error: Modeling Region ID" + " is invalid for CCA 0." + ) try: project.create_cca_from_modeling_region( From 4a90dc10f39a9f4070daebc53bf74af45770048e Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:22:35 -0400 Subject: [PATCH 05/23] Test cases depending on connection now in conditional --- tests/test_project.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index 059d661ca..5951519c9 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3208,27 +3208,28 @@ def helper_test_create_cca_from_modeling_region(project): " is invalid for CCA 0." ) - try: - project.create_cca_from_modeling_region( - "Tutorial Project", - [ - { - "cca_name": "Main Board", - "modeling_region_id": "MR1", - "description": "Test", - "default_solder_type": "SAC305", - "default_stencil_thickness": 10, - "default_stencil_thickness_units": "INVALID", - "default_part_temp_rise": 20, - "default_part_temp_rise_units": "C", - "guess_part_properties": False, - "generate_image_layers": False, - }, - ], - ) - pytest.fail("No exception raised when using an invalid parameter") - except Exception as e: - assert type(e) == SherlockCreateCCAFromModelingRegionError + if project._is_connection_up(): + try: + project.create_cca_from_modeling_region( + "Tutorial Project", + [ + { + "cca_name": "Main Board", + "modeling_region_id": "MR1", + "description": "Test", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "INVALID", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockCreateCCAFromModelingRegionError if __name__ == "__main__": From 8606eed2c0d66a62854d4e2ee141af95dc0b7211 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:21:39 -0400 Subject: [PATCH 06/23] documentation updates --- tests/test_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_project.py b/tests/test_project.py index 5951519c9..83a149b93 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3216,7 +3216,7 @@ def helper_test_create_cca_from_modeling_region(project): { "cca_name": "Main Board", "modeling_region_id": "MR1", - "description": "Test", + "description": "Test invalid parameter", "default_solder_type": "SAC305", "default_stencil_thickness": 10, "default_stencil_thickness_units": "INVALID", From bcdfc137cf1352460fefdf72f230102b33da7dd0 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:39:09 -0400 Subject: [PATCH 07/23] Added successful run test --- tests/test_project.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_project.py b/tests/test_project.py index 83a149b93..af2e8bf35 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3231,6 +3231,28 @@ def helper_test_create_cca_from_modeling_region(project): except Exception as e: assert type(e) == SherlockCreateCCAFromModelingRegionError + try: + result = project.create_cca_from_modeling_region( + "ModelingRegion", + [ + { + "cca_name": "Main Board", + "modeling_region_id": "MR1", + "description": "Test", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "mm", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + assert result == 0 + except SherlockCreateCCAFromModelingRegionError as e: + pytest.fail(str(e)) + if __name__ == "__main__": test_all() From 2aec399ae4383ddcbbf79438425e6850e5478952 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:24:03 -0400 Subject: [PATCH 08/23] Changed the connection statement and took out successful run test --- tests/test_project.py | 102 ++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 43 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index af2e8bf35..a0c93cf6a 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3208,50 +3208,66 @@ def helper_test_create_cca_from_modeling_region(project): " is invalid for CCA 0." ) - if project._is_connection_up(): - try: - project.create_cca_from_modeling_region( - "Tutorial Project", - [ - { - "cca_name": "Main Board", - "modeling_region_id": "MR1", - "description": "Test invalid parameter", - "default_solder_type": "SAC305", - "default_stencil_thickness": 10, - "default_stencil_thickness_units": "INVALID", - "default_part_temp_rise": 20, - "default_part_temp_rise_units": "C", - "guess_part_properties": False, - "generate_image_layers": False, - }, - ], - ) - pytest.fail("No exception raised when using an invalid parameter") - except Exception as e: - assert type(e) == SherlockCreateCCAFromModelingRegionError + if not project._is_connection_up(): + return - try: - result = project.create_cca_from_modeling_region( - "ModelingRegion", - [ - { - "cca_name": "Main Board", - "modeling_region_id": "MR1", - "description": "Test", - "default_solder_type": "SAC305", - "default_stencil_thickness": 10, - "default_stencil_thickness_units": "mm", - "default_part_temp_rise": 20, - "default_part_temp_rise_units": "C", - "guess_part_properties": False, - "generate_image_layers": False, - }, - ], - ) - assert result == 0 - except SherlockCreateCCAFromModelingRegionError as e: - pytest.fail(str(e)) + try: + project.create_cca_from_modeling_region( + "Test", + [ + { + "cca_name": "Main Board", + "modeling_region_id": "MR1", + "description": "Test invalid parameter", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "INVALID", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockCreateCCAFromModelingRegionError + + # try: + # result = project.create_cca_from_modeling_region( + # "ModelingRegion", + # [ + # { + # "cca_name": "Main Board", + # "modeling_region_id": "MR1", + # }, + # ], + # ) + # assert result == 0 + # except SherlockCreateCCAFromModelingRegionError as e: + # pytest.fai(str(e)) + + # try: + # result = project.create_cca_from_modeling_region( + # "ModelingRegion", + # [ + # { + # "cca_name": "Main Board", + # "modeling_region_id": "MR1", + # "description": "Test", + # "default_solder_type": "SAC305", + # "default_stencil_thickness": 10, + # "default_stencil_thickness_units": "mm", + # "default_part_temp_rise": 20, + # "default_part_temp_rise_units": "C", + # "guess_part_properties": False, + # "generate_image_layers": False, + # }, + # ], + # ) + # assert result == 0 + # except SherlockCreateCCAFromModelingRegionError as e: + # pytest.fail(str(e)) if __name__ == "__main__": From e448e911680f1bcdd55fc7eaed37668ce51d0cef Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:43:21 -0400 Subject: [PATCH 09/23] added test for missing parameters --- tests/test_project.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index a0c93cf6a..e31030c05 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3233,19 +3233,19 @@ def helper_test_create_cca_from_modeling_region(project): except Exception as e: assert type(e) == SherlockCreateCCAFromModelingRegionError - # try: - # result = project.create_cca_from_modeling_region( - # "ModelingRegion", - # [ - # { - # "cca_name": "Main Board", - # "modeling_region_id": "MR1", - # }, - # ], - # ) - # assert result == 0 - # except SherlockCreateCCAFromModelingRegionError as e: - # pytest.fai(str(e)) + try: + project.create_cca_from_modeling_region( + "ModelingRegion", + [ + { + "cca_name": "Main Board", + "modeling_region_id": "MR1", + }, + ], + ) + pytest.fail("No exception raised when missing parameters") + except Exception as e: + assert type(e) == SherlockCreateCCAFromModelingRegionError # try: # result = project.create_cca_from_modeling_region( From ceab93ea60d6300b2f15ae26a83084c95868c265 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Mon, 15 Jul 2024 11:25:48 -0400 Subject: [PATCH 10/23] took out commented out section --- tests/test_project.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index e31030c05..dc777d3b7 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3247,28 +3247,6 @@ def helper_test_create_cca_from_modeling_region(project): except Exception as e: assert type(e) == SherlockCreateCCAFromModelingRegionError - # try: - # result = project.create_cca_from_modeling_region( - # "ModelingRegion", - # [ - # { - # "cca_name": "Main Board", - # "modeling_region_id": "MR1", - # "description": "Test", - # "default_solder_type": "SAC305", - # "default_stencil_thickness": 10, - # "default_stencil_thickness_units": "mm", - # "default_part_temp_rise": 20, - # "default_part_temp_rise_units": "C", - # "guess_part_properties": False, - # "generate_image_layers": False, - # }, - # ], - # ) - # assert result == 0 - # except SherlockCreateCCAFromModelingRegionError as e: - # pytest.fail(str(e)) - if __name__ == "__main__": test_all() From 93b632c5e6843a4b9b597260bc04eaa23367607f Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Fri, 5 Jul 2024 12:13:12 -0400 Subject: [PATCH 11/23] Create CCA from modeling region API + tests added --- src/ansys/sherlock/core/errors.py | 14 +- src/ansys/sherlock/core/project.py | 149 +++++++++++++++++ tests/test_project.py | 252 +++++++++++++++++++++++------ 3 files changed, 367 insertions(+), 48 deletions(-) diff --git a/src/ansys/sherlock/core/errors.py b/src/ansys/sherlock/core/errors.py index 34fb1ec13..373944d64 100644 --- a/src/ansys/sherlock/core/errors.py +++ b/src/ansys/sherlock/core/errors.py @@ -1133,7 +1133,6 @@ 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}"] @@ -1160,3 +1159,16 @@ def __init__(self, message): def __str__(self): """Format error message.""" return f"Export mount points error: {self.message}" + + +class SherlockCreateCCAFromModelingRegionError(Exception): + """Contains the error raised when a CCA cannot be created from a modeling region.""" + + def __init__(self, message): + """Initialize error message.""" + self.message = message + + def __str__(self): + """Format error message.""" + return f"Create CCA from modeling region error: {self.message}" + diff --git a/src/ansys/sherlock/core/project.py b/src/ansys/sherlock/core/project.py index f0c85320f..96accc582 100644 --- a/src/ansys/sherlock/core/project.py +++ b/src/ansys/sherlock/core/project.py @@ -27,6 +27,7 @@ SherlockListStrainMapsError, SherlockListThermalMapsError, SherlockUpdateThermalMapsError, + SherlockCreateCCAFromModelingRegionError, ) from ansys.sherlock.core.grpc_stub import GrpcStub from ansys.sherlock.core.types.project_types import ( @@ -1793,3 +1794,151 @@ def export_project( raise e return response.value + + def create_cca_from_modeling_region(self, project, cca_from_mr_properties): + """Create one or more CCAs from modeling regions in a given project. + + Parameters + ---------- + project : str + Name of the Sherlock project. + cca_from_mr_properties : list + List of CCAs to be to be created from modeling regions + consisting of these properties: + + - cca_name : str + Name of the CCA. + - modeling_region_id : str + Name of the modeling region. + - description : str + Description of the CCA. + - default_solder_type: str + The default solder type. The default is ``None``. + - default_stencil_thickness: float + The default stencil thickness. The default is ``None``. + - default_stencil_thickness_units: str + Units for default stencil thickness. The default is ``None``. + - default_part_temp_rise: float + Default part temp rise. The default is ``None``. + - default_part_temp_rise_units: str + Units for default part temp rise. The default is ``None``. + Options are ``"C"``, ``"F"``, and ``"K"``. + - guess_part_properties: bool + Whether to enable guess part properties. The default is ``None``. + - generate_image_layers: bool + Whether to generate image layers or not. The default is ``None``. + + 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.project.create_cca_from_modeling_region() + "Test", + [{ + 'cca_name': 'Card', + 'modeling_region_id': 'MR1' + 'description': 'Test', + 'default_solder_type': 'SAC305', + 'default_stencil_thickness': 10, + 'default_stencil_thickness_units': 'mm', + 'default_part_temp_rise': 20, + 'default_part_temp_rise_units': 'C', + 'guess_part_properties': False, + 'generate_image_layers': False, + }, + ] + )""" + + try: + if project == "": + raise SherlockCreateCCAFromModelingRegionError(message="Project name is invalid.") + + if not isinstance(cca_from_mr_properties, list): + raise SherlockCreateCCAFromModelingRegionError(message="CCA properties argument is invalid.") + + if len(cca_from_mr_properties) == 0: + raise SherlockCreateCCAFromModelingRegionError(message="One or more CCAs are required.") + + request = SherlockProjectService_pb2.CreateCcaFromModelingRegionRequest(project=project) + + for i, cca in enumerate(cca_from_mr_properties): + + cca_request = request.cCAsFromModelingRegions.add() + + if not isinstance(cca, dict): + raise SherlockCreateCCAFromModelingRegionError(message=f"CCA properties are invalid for CCA {i}.") + + if "cca_name" not in cca.keys(): + raise SherlockCreateCCAFromModelingRegionError(message=f"CCA name is missing for CCA {i}.") + + if "modeling_region_id" not in cca.keys(): + raise SherlockCreateCCAFromModelingRegionError(message=f"Modeling Region ID is missing for CCA {i}.") + + cca_request.ccaName = cca["cca_name"] + cca_request.modelingRegionID = cca["modeling_region_id"] + + if cca_request.ccaName == "": + raise SherlockCreateCCAFromModelingRegionError(message=f"CCA name is invalid for CCA {i}.") + + if cca_request.modelingRegionID == "": + raise SherlockCreateCCAFromModelingRegionError(message=f"Modeling Region ID is invalid for CCA {i}.") + + if "description" in cca.keys(): + cca_request.description = cca["description"] + + if "default_solder_type" in cca.keys(): + cca_request.defaultSolderType = cca["default_solder_type"] + + if "default_stencil_thickness" in cca.keys(): + cca_request.defaultStencilThickness = cca["default_stencil_thickness"] + + if "default_stencil_thickness_units" in cca.keys(): + cca_request.defaultStencilThicknessUnits = cca[ + "default_stencil_thickness_units" + ] + + if "default_part_temp_rise" in cca.keys(): + cca_request.defaultPartTempRise = cca["default_part_temp_rise"] + + if "default_part_temp_rise_units" in cca.keys(): + cca_request.defaultPartTempRiseUnits = cca["default_part_temp_rise_units"] + + if "guess_part_properties" in cca.keys(): + cca_request.guessPartProperties = cca["guess_part_properties"] + + if "generate_image_layers" in cca.keys(): + cca_request.generateImageLayers = cca["generate_image_layers"] + + except SherlockCreateCCAFromModelingRegionError as e: + LOG.error(str(e)) + raise e + + if not self._is_connection_up(): + LOG.error("There is no connection to a gRPC service.") + return + + response = self.stub.createCCAFromModelingRegion(request) + + try: + if response.value == -1: + raise SherlockCreateCCAFromModelingRegionError(response.message) + else: + LOG.info(response.message) + return response.value + except SherlockCreateCCAFromModelingRegionError as e: + LOG.error(str(e)) + raise e diff --git a/tests/test_project.py b/tests/test_project.py index 8a1c7baa5..16479a806 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -24,6 +24,7 @@ SherlockListStrainMapsError, SherlockListThermalMapsError, SherlockUpdateThermalMapsError, + SherlockCreateCCAFromModelingRegionError, ) from ansys.sherlock.core.project import Project from ansys.sherlock.core.types.project_types import ( @@ -61,6 +62,7 @@ def test_all(): helper_test_add_thermal_maps(project) helper_test_update_thermal_maps(project) helper_test_list_thermal_maps(project) + helper_test_create_cca_from_modeling_region(project) project_name = None try: project_name = helper_test_add_project(project) @@ -394,8 +396,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count is required for strain map 0.']" ) try: @@ -417,8 +419,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count must be greater than or equal to 0 for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count must be greater than or equal to 0 for strain map 0.']" ) try: @@ -440,8 +442,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Reference ID column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Reference ID column is required for strain map 0.']" ) try: @@ -463,8 +465,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain column is required for strain map 0.']" ) try: @@ -486,8 +488,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain units are required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain units are required for strain map 0.']" ) try: @@ -509,8 +511,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' - "are invalid for strain map 0.']" + str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' + "are invalid for strain map 0.']" ) try: @@ -533,8 +535,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "cca_names is not a list for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "cca_names is not a list for strain map 0.']" ) try: @@ -596,8 +598,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count is required for strain map 0.']" ) try: @@ -619,8 +621,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count must be greater than or equal to 0 for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count must be greater than or equal to 0 for strain map 0.']" ) try: @@ -642,8 +644,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Reference ID column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Reference ID column is required for strain map 0.']" ) try: @@ -665,8 +667,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain column is required for strain map 0.']" ) try: @@ -688,8 +690,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain units are required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain units are required for strain map 0.']" ) try: @@ -711,8 +713,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' - "are invalid for strain map 0.']" + str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' + "are invalid for strain map 0.']" ) try: @@ -735,8 +737,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "cca_names is not a list for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "cca_names is not a list for strain map 0.']" ) try: @@ -765,7 +767,7 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " "Path is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " "Path is required for strain map 0.']" ) try: @@ -785,8 +787,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "image_file is not a list for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "image_file is not a list for strain map 0.']" ) try: @@ -815,8 +817,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid board bounds for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid board bounds for strain map 0.']" ) try: @@ -846,8 +848,8 @@ def helper_test_add_strain_maps(project): except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid coordinate units for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid coordinate units for strain map 0.']" ) try: @@ -877,8 +879,8 @@ def helper_test_add_strain_maps(project): except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid image bounds for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid image bounds for strain map 0.']" ) try: @@ -907,8 +909,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid legend bounds for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid legend bounds for strain map 0.']" ) try: @@ -937,8 +939,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid legend orientation for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid legend orientation for strain map 0.']" ) try: @@ -967,8 +969,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid minimum strain for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid minimum strain for strain map 0.']" ) try: @@ -997,8 +999,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid maximum strain for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid maximum strain for strain map 0.']" ) try: @@ -1027,8 +1029,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid strain units for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid strain units for strain map 0.']" ) if project._is_connection_up(): @@ -3066,5 +3068,161 @@ def helper_test_export_project(project): pytest.fail(str(e)) +def helper_test_create_cca_from_modeling_region(project): + """Test create_cca_from_modeling_region API""" + try: + project.create_cca_from_modeling_region( + "", + [ + { + "cca_name": "Main Board", + "modeling_region_id": "MR1", + "description": "test MR1", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "mm", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties_enabled": False, + "generate_image_layers": False, + }, + ], + ) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: Project " \ + "name is invalid." + + try: + project.create_cca_from_modeling_region("Test", "") + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: CCA " \ + "properties argument is invalid." + + try: + project.create_cca_from_modeling_region("Test", []) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: One or more CCAs are required." + + try: + project.create_cca_from_modeling_region("Test", [""]) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: CCA properties " \ + "are invalid for CCA 0." + + try: + project.create_cca_from_modeling_region( + "Test", + [ + { + "modeling_region_id": "MR1", + "description": "tests MR1", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "mm", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: CCA name is missing for CCA 0." + + try: + project.create_cca_from_modeling_region( + "Test", + [ + { + "cca_name": "", + "modeling_region_id": "MR1", + "description": "Test", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "mm", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: CCA name is invalid for CCA 0." + + try: + project.create_cca_from_modeling_region( + "Test", + [ + { + "cca_name": "Main Board", + "description": "Test", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "mm", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: Modeling Region ID" \ + " is missing for CCA 0." + + try: + project.create_cca_from_modeling_region( + "Test", + [ + { + "cca_name": "Card", + "modeling_region_id": "", + "description": "Test", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "mm", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + assert False + except SherlockCreateCCAFromModelingRegionError as e: + assert str(e) == "Create CCA from modeling region error: Modeling Region ID" \ + " is invalid for CCA 0." + + try: + project.create_cca_from_modeling_region( + "Tutorial Project", + [ + { + "cca_name": "Main Board", + "modeling_region_id": "MR1", + "description": "Test", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "INVALID", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockCreateCCAFromModelingRegionError + + if __name__ == "__main__": test_all() From 3a9f296b8ca1ce53c55ac2c777c4706bed076321 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Tue, 9 Jul 2024 09:35:32 -0400 Subject: [PATCH 12/23] Fixed syntax errors in errors.py and project.py --- src/ansys/sherlock/core/project.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/sherlock/core/project.py b/src/ansys/sherlock/core/project.py index 96accc582..efb93c673 100644 --- a/src/ansys/sherlock/core/project.py +++ b/src/ansys/sherlock/core/project.py @@ -1861,8 +1861,8 @@ def create_cca_from_modeling_region(self, project, cca_from_mr_properties): 'generate_image_layers': False, }, ] - )""" - + ) + """ try: if project == "": raise SherlockCreateCCAFromModelingRegionError(message="Project name is invalid.") From 6af0d19dcf7f5df16515ff7981d90e308a29d7bc Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:03:41 -0400 Subject: [PATCH 13/23] test empty From 950df67f95b37919ec52bdf44ea7f0260d878fdd Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:28:41 -0400 Subject: [PATCH 14/23] test --- src/ansys/sherlock/core/errors.py | 1 - src/ansys/sherlock/core/project.py | 161 ++++++++++++++++------------- tests/test_project.py | 123 +++++++++++----------- 3 files changed, 152 insertions(+), 133 deletions(-) diff --git a/src/ansys/sherlock/core/errors.py b/src/ansys/sherlock/core/errors.py index 373944d64..289e20370 100644 --- a/src/ansys/sherlock/core/errors.py +++ b/src/ansys/sherlock/core/errors.py @@ -1171,4 +1171,3 @@ def __init__(self, message): def __str__(self): """Format error message.""" return f"Create CCA from modeling region error: {self.message}" - diff --git a/src/ansys/sherlock/core/project.py b/src/ansys/sherlock/core/project.py index efb93c673..82561530e 100644 --- a/src/ansys/sherlock/core/project.py +++ b/src/ansys/sherlock/core/project.py @@ -16,6 +16,7 @@ SherlockAddProjectError, SherlockAddStrainMapsError, SherlockAddThermalMapsError, + SherlockCreateCCAFromModelingRegionError, SherlockDeleteProjectError, SherlockExportProjectError, SherlockGenerateProjectReportError, @@ -27,7 +28,6 @@ SherlockListStrainMapsError, SherlockListThermalMapsError, SherlockUpdateThermalMapsError, - SherlockCreateCCAFromModelingRegionError, ) from ansys.sherlock.core.grpc_stub import GrpcStub from ansys.sherlock.core.types.project_types import ( @@ -1798,104 +1798,117 @@ def export_project( def create_cca_from_modeling_region(self, project, cca_from_mr_properties): """Create one or more CCAs from modeling regions in a given project. - Parameters - ---------- - project : str - Name of the Sherlock project. - cca_from_mr_properties : list - List of CCAs to be to be created from modeling regions - consisting of these properties: - - - cca_name : str - Name of the CCA. - - modeling_region_id : str - Name of the modeling region. - - description : str - Description of the CCA. - - default_solder_type: str - The default solder type. The default is ``None``. - - default_stencil_thickness: float - The default stencil thickness. The default is ``None``. - - default_stencil_thickness_units: str - Units for default stencil thickness. The default is ``None``. - - default_part_temp_rise: float - Default part temp rise. The default is ``None``. - - default_part_temp_rise_units: str - Units for default part temp rise. The default is ``None``. - Options are ``"C"``, ``"F"``, and ``"K"``. - - guess_part_properties: bool - Whether to enable guess part properties. The default is ``None``. - - generate_image_layers: bool - Whether to generate image layers or not. The default is ``None``. - - 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.project.create_cca_from_modeling_region() - "Test", - [{ - 'cca_name': 'Card', - 'modeling_region_id': 'MR1' - 'description': 'Test', - 'default_solder_type': 'SAC305', - 'default_stencil_thickness': 10, - 'default_stencil_thickness_units': 'mm', - 'default_part_temp_rise': 20, - 'default_part_temp_rise_units': 'C', - 'guess_part_properties': False, - 'generate_image_layers': False, - }, - ] - ) - """ + Parameters + ---------- + project : str + Name of the Sherlock project. + cca_from_mr_properties : list + List of CCAs to be to be created from modeling regions + consisting of these properties: + + - cca_name : str + Name of the CCA. + - modeling_region_id : str + Name of the modeling region. + - description : str + Description of the CCA. + - default_solder_type: str + The default solder type. The default is ``None``. + - default_stencil_thickness: float + The default stencil thickness. The default is ``None``. + - default_stencil_thickness_units: str + Units for default stencil thickness. The default is ``None``. + - default_part_temp_rise: float + Default part temp rise. The default is ``None``. + - default_part_temp_rise_units: str + Units for default part temp rise. The default is ``None``. + Options are ``"C"``, ``"F"``, and ``"K"``. + - guess_part_properties: bool + Whether to enable guess part properties. The default is ``None``. + - generate_image_layers: bool + Whether to generate image layers or not. The default is ``None``. + + 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.project.create_cca_from_modeling_region() + "Test", + [{ + 'cca_name': 'Card', + 'modeling_region_id': 'MR1' + 'description': 'Test', + 'default_solder_type': 'SAC305', + 'default_stencil_thickness': 10, + 'default_stencil_thickness_units': 'mm', + 'default_part_temp_rise': 20, + 'default_part_temp_rise_units': 'C', + 'guess_part_properties': False, + 'generate_image_layers': False, + }, + ] + ) + """ try: if project == "": raise SherlockCreateCCAFromModelingRegionError(message="Project name is invalid.") if not isinstance(cca_from_mr_properties, list): - raise SherlockCreateCCAFromModelingRegionError(message="CCA properties argument is invalid.") + raise SherlockCreateCCAFromModelingRegionError( + message="CCA properties argument is invalid." + ) if len(cca_from_mr_properties) == 0: - raise SherlockCreateCCAFromModelingRegionError(message="One or more CCAs are required.") + raise SherlockCreateCCAFromModelingRegionError( + message="One or more CCAs are required." + ) request = SherlockProjectService_pb2.CreateCcaFromModelingRegionRequest(project=project) for i, cca in enumerate(cca_from_mr_properties): - cca_request = request.cCAsFromModelingRegions.add() if not isinstance(cca, dict): - raise SherlockCreateCCAFromModelingRegionError(message=f"CCA properties are invalid for CCA {i}.") + raise SherlockCreateCCAFromModelingRegionError( + message=f"CCA properties are invalid for CCA {i}." + ) if "cca_name" not in cca.keys(): - raise SherlockCreateCCAFromModelingRegionError(message=f"CCA name is missing for CCA {i}.") + raise SherlockCreateCCAFromModelingRegionError( + message=f"CCA name is missing for CCA {i}." + ) if "modeling_region_id" not in cca.keys(): - raise SherlockCreateCCAFromModelingRegionError(message=f"Modeling Region ID is missing for CCA {i}.") + raise SherlockCreateCCAFromModelingRegionError( + message=f"Modeling Region ID is missing for CCA {i}." + ) cca_request.ccaName = cca["cca_name"] cca_request.modelingRegionID = cca["modeling_region_id"] if cca_request.ccaName == "": - raise SherlockCreateCCAFromModelingRegionError(message=f"CCA name is invalid for CCA {i}.") + raise SherlockCreateCCAFromModelingRegionError( + message=f"CCA name is invalid for CCA {i}." + ) if cca_request.modelingRegionID == "": - raise SherlockCreateCCAFromModelingRegionError(message=f"Modeling Region ID is invalid for CCA {i}.") + raise SherlockCreateCCAFromModelingRegionError( + message=f"Modeling Region ID is invalid for CCA {i}." + ) if "description" in cca.keys(): cca_request.description = cca["description"] diff --git a/tests/test_project.py b/tests/test_project.py index 16479a806..365144253 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -13,6 +13,7 @@ SherlockAddProjectError, SherlockAddStrainMapsError, SherlockAddThermalMapsError, + SherlockCreateCCAFromModelingRegionError, SherlockDeleteProjectError, SherlockExportProjectError, SherlockGenerateProjectReportError, @@ -24,7 +25,6 @@ SherlockListStrainMapsError, SherlockListThermalMapsError, SherlockUpdateThermalMapsError, - SherlockCreateCCAFromModelingRegionError, ) from ansys.sherlock.core.project import Project from ansys.sherlock.core.types.project_types import ( @@ -396,8 +396,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count is required for strain map 0.']" ) try: @@ -419,8 +419,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count must be greater than or equal to 0 for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count must be greater than or equal to 0 for strain map 0.']" ) try: @@ -442,8 +442,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Reference ID column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Reference ID column is required for strain map 0.']" ) try: @@ -465,8 +465,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain column is required for strain map 0.']" ) try: @@ -488,8 +488,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain units are required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain units are required for strain map 0.']" ) try: @@ -511,8 +511,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' - "are invalid for strain map 0.']" + str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' + "are invalid for strain map 0.']" ) try: @@ -535,8 +535,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "cca_names is not a list for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "cca_names is not a list for strain map 0.']" ) try: @@ -598,8 +598,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count is required for strain map 0.']" ) try: @@ -621,8 +621,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Header row count must be greater than or equal to 0 for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Header row count must be greater than or equal to 0 for strain map 0.']" ) try: @@ -644,8 +644,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Reference ID column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Reference ID column is required for strain map 0.']" ) try: @@ -667,8 +667,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain column is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain column is required for strain map 0.']" ) try: @@ -690,8 +690,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Strain units are required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Strain units are required for strain map 0.']" ) try: @@ -713,8 +713,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' - "are invalid for strain map 0.']" + str(e.str_itr()) == '[\'Add strain maps error: Strain units "BAD" ' + "are invalid for strain map 0.']" ) try: @@ -737,8 +737,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "cca_names is not a list for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "cca_names is not a list for strain map 0.']" ) try: @@ -767,7 +767,7 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " "Path is required for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " "Path is required for strain map 0.']" ) try: @@ -787,8 +787,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "image_file is not a list for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "image_file is not a list for strain map 0.']" ) try: @@ -817,8 +817,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid board bounds for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid board bounds for strain map 0.']" ) try: @@ -848,8 +848,8 @@ def helper_test_add_strain_maps(project): except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid coordinate units for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid coordinate units for strain map 0.']" ) try: @@ -879,8 +879,8 @@ def helper_test_add_strain_maps(project): except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid image bounds for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid image bounds for strain map 0.']" ) try: @@ -909,8 +909,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid legend bounds for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid legend bounds for strain map 0.']" ) try: @@ -939,8 +939,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid legend orientation for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid legend orientation for strain map 0.']" ) try: @@ -969,8 +969,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid minimum strain for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid minimum strain for strain map 0.']" ) try: @@ -999,8 +999,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid maximum strain for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid maximum strain for strain map 0.']" ) try: @@ -1029,8 +1029,8 @@ def helper_test_add_strain_maps(project): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - str(e.str_itr()) == "['Add strain maps error: " - "Invalid strain units for strain map 0.']" + str(e.str_itr()) == "['Add strain maps error: " + "Invalid strain units for strain map 0.']" ) if project._is_connection_up(): @@ -3090,15 +3090,16 @@ def helper_test_create_cca_from_modeling_region(project): ) assert False except SherlockCreateCCAFromModelingRegionError as e: - assert str(e) == "Create CCA from modeling region error: Project " \ - "name is invalid." + assert str(e) == "Create CCA from modeling region error: Project " "name is invalid." try: project.create_cca_from_modeling_region("Test", "") assert False except SherlockCreateCCAFromModelingRegionError as e: - assert str(e) == "Create CCA from modeling region error: CCA " \ - "properties argument is invalid." + assert ( + str(e) == "Create CCA from modeling region error: CCA " + "properties argument is invalid." + ) try: project.create_cca_from_modeling_region("Test", []) @@ -3110,8 +3111,10 @@ def helper_test_create_cca_from_modeling_region(project): project.create_cca_from_modeling_region("Test", [""]) assert False except SherlockCreateCCAFromModelingRegionError as e: - assert str(e) == "Create CCA from modeling region error: CCA properties " \ - "are invalid for CCA 0." + assert ( + str(e) == "Create CCA from modeling region error: CCA properties " + "are invalid for CCA 0." + ) try: project.create_cca_from_modeling_region( @@ -3175,8 +3178,10 @@ def helper_test_create_cca_from_modeling_region(project): ) assert False except SherlockCreateCCAFromModelingRegionError as e: - assert str(e) == "Create CCA from modeling region error: Modeling Region ID" \ - " is missing for CCA 0." + assert ( + str(e) == "Create CCA from modeling region error: Modeling Region ID" + " is missing for CCA 0." + ) try: project.create_cca_from_modeling_region( @@ -3198,8 +3203,10 @@ def helper_test_create_cca_from_modeling_region(project): ) assert False except SherlockCreateCCAFromModelingRegionError as e: - assert str(e) == "Create CCA from modeling region error: Modeling Region ID" \ - " is invalid for CCA 0." + assert ( + str(e) == "Create CCA from modeling region error: Modeling Region ID" + " is invalid for CCA 0." + ) try: project.create_cca_from_modeling_region( From 9abf3476e5032c28670e6700089087d259b19a59 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:22:35 -0400 Subject: [PATCH 15/23] Test cases depending on connection now in conditional --- tests/test_project.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index 365144253..24515d5e6 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3208,27 +3208,28 @@ def helper_test_create_cca_from_modeling_region(project): " is invalid for CCA 0." ) - try: - project.create_cca_from_modeling_region( - "Tutorial Project", - [ - { - "cca_name": "Main Board", - "modeling_region_id": "MR1", - "description": "Test", - "default_solder_type": "SAC305", - "default_stencil_thickness": 10, - "default_stencil_thickness_units": "INVALID", - "default_part_temp_rise": 20, - "default_part_temp_rise_units": "C", - "guess_part_properties": False, - "generate_image_layers": False, - }, - ], - ) - pytest.fail("No exception raised when using an invalid parameter") - except Exception as e: - assert type(e) == SherlockCreateCCAFromModelingRegionError + if project._is_connection_up(): + try: + project.create_cca_from_modeling_region( + "Tutorial Project", + [ + { + "cca_name": "Main Board", + "modeling_region_id": "MR1", + "description": "Test", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "INVALID", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockCreateCCAFromModelingRegionError if __name__ == "__main__": From 06e8af82002d582c7e489082edc488d094ed37a5 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:21:39 -0400 Subject: [PATCH 16/23] documentation updates --- tests/test_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_project.py b/tests/test_project.py index 24515d5e6..fccd67736 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3216,7 +3216,7 @@ def helper_test_create_cca_from_modeling_region(project): { "cca_name": "Main Board", "modeling_region_id": "MR1", - "description": "Test", + "description": "Test invalid parameter", "default_solder_type": "SAC305", "default_stencil_thickness": 10, "default_stencil_thickness_units": "INVALID", From 73b6582c176a31ad836bc2aed2c36670b76c0d2c Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:39:09 -0400 Subject: [PATCH 17/23] Added successful run test --- tests/test_project.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_project.py b/tests/test_project.py index fccd67736..22508fe1d 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3231,6 +3231,28 @@ def helper_test_create_cca_from_modeling_region(project): except Exception as e: assert type(e) == SherlockCreateCCAFromModelingRegionError + try: + result = project.create_cca_from_modeling_region( + "ModelingRegion", + [ + { + "cca_name": "Main Board", + "modeling_region_id": "MR1", + "description": "Test", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "mm", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + assert result == 0 + except SherlockCreateCCAFromModelingRegionError as e: + pytest.fail(str(e)) + if __name__ == "__main__": test_all() From 2695de18ae6d1f0c7096d6d4e96c3a43755a3407 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:24:03 -0400 Subject: [PATCH 18/23] Changed the connection statement and took out successful run test --- tests/test_project.py | 102 ++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 43 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index 22508fe1d..21b057735 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3208,50 +3208,66 @@ def helper_test_create_cca_from_modeling_region(project): " is invalid for CCA 0." ) - if project._is_connection_up(): - try: - project.create_cca_from_modeling_region( - "Tutorial Project", - [ - { - "cca_name": "Main Board", - "modeling_region_id": "MR1", - "description": "Test invalid parameter", - "default_solder_type": "SAC305", - "default_stencil_thickness": 10, - "default_stencil_thickness_units": "INVALID", - "default_part_temp_rise": 20, - "default_part_temp_rise_units": "C", - "guess_part_properties": False, - "generate_image_layers": False, - }, - ], - ) - pytest.fail("No exception raised when using an invalid parameter") - except Exception as e: - assert type(e) == SherlockCreateCCAFromModelingRegionError + if not project._is_connection_up(): + return - try: - result = project.create_cca_from_modeling_region( - "ModelingRegion", - [ - { - "cca_name": "Main Board", - "modeling_region_id": "MR1", - "description": "Test", - "default_solder_type": "SAC305", - "default_stencil_thickness": 10, - "default_stencil_thickness_units": "mm", - "default_part_temp_rise": 20, - "default_part_temp_rise_units": "C", - "guess_part_properties": False, - "generate_image_layers": False, - }, - ], - ) - assert result == 0 - except SherlockCreateCCAFromModelingRegionError as e: - pytest.fail(str(e)) + try: + project.create_cca_from_modeling_region( + "Test", + [ + { + "cca_name": "Main Board", + "modeling_region_id": "MR1", + "description": "Test invalid parameter", + "default_solder_type": "SAC305", + "default_stencil_thickness": 10, + "default_stencil_thickness_units": "INVALID", + "default_part_temp_rise": 20, + "default_part_temp_rise_units": "C", + "guess_part_properties": False, + "generate_image_layers": False, + }, + ], + ) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockCreateCCAFromModelingRegionError + + # try: + # result = project.create_cca_from_modeling_region( + # "ModelingRegion", + # [ + # { + # "cca_name": "Main Board", + # "modeling_region_id": "MR1", + # }, + # ], + # ) + # assert result == 0 + # except SherlockCreateCCAFromModelingRegionError as e: + # pytest.fai(str(e)) + + # try: + # result = project.create_cca_from_modeling_region( + # "ModelingRegion", + # [ + # { + # "cca_name": "Main Board", + # "modeling_region_id": "MR1", + # "description": "Test", + # "default_solder_type": "SAC305", + # "default_stencil_thickness": 10, + # "default_stencil_thickness_units": "mm", + # "default_part_temp_rise": 20, + # "default_part_temp_rise_units": "C", + # "guess_part_properties": False, + # "generate_image_layers": False, + # }, + # ], + # ) + # assert result == 0 + # except SherlockCreateCCAFromModelingRegionError as e: + # pytest.fail(str(e)) if __name__ == "__main__": From be08a615968cad11bff24b265746d4f51cd7129f Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Mon, 15 Jul 2024 09:43:21 -0400 Subject: [PATCH 19/23] added test for missing parameters --- tests/test_project.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index 21b057735..6d39edf8f 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3233,19 +3233,19 @@ def helper_test_create_cca_from_modeling_region(project): except Exception as e: assert type(e) == SherlockCreateCCAFromModelingRegionError - # try: - # result = project.create_cca_from_modeling_region( - # "ModelingRegion", - # [ - # { - # "cca_name": "Main Board", - # "modeling_region_id": "MR1", - # }, - # ], - # ) - # assert result == 0 - # except SherlockCreateCCAFromModelingRegionError as e: - # pytest.fai(str(e)) + try: + project.create_cca_from_modeling_region( + "ModelingRegion", + [ + { + "cca_name": "Main Board", + "modeling_region_id": "MR1", + }, + ], + ) + pytest.fail("No exception raised when missing parameters") + except Exception as e: + assert type(e) == SherlockCreateCCAFromModelingRegionError # try: # result = project.create_cca_from_modeling_region( From 1b146c26acf252618daf426a414ab4d5f26fef57 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Mon, 15 Jul 2024 11:25:48 -0400 Subject: [PATCH 20/23] took out commented out section --- tests/test_project.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index 6d39edf8f..5356fecf1 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3247,28 +3247,6 @@ def helper_test_create_cca_from_modeling_region(project): except Exception as e: assert type(e) == SherlockCreateCCAFromModelingRegionError - # try: - # result = project.create_cca_from_modeling_region( - # "ModelingRegion", - # [ - # { - # "cca_name": "Main Board", - # "modeling_region_id": "MR1", - # "description": "Test", - # "default_solder_type": "SAC305", - # "default_stencil_thickness": 10, - # "default_stencil_thickness_units": "mm", - # "default_part_temp_rise": 20, - # "default_part_temp_rise_units": "C", - # "guess_part_properties": False, - # "generate_image_layers": False, - # }, - # ], - # ) - # assert result == 0 - # except SherlockCreateCCAFromModelingRegionError as e: - # pytest.fail(str(e)) - if __name__ == "__main__": test_all() From 3ed9eb0596cdeee22c9e2db7dad27342ed112624 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Mon, 15 Jul 2024 12:47:40 -0400 Subject: [PATCH 21/23] Fix documentation error --- tests/test_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_project.py b/tests/test_project.py index 5356fecf1..0978fcb43 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3243,7 +3243,7 @@ def helper_test_create_cca_from_modeling_region(project): }, ], ) - pytest.fail("No exception raised when missing parameters") + pytest.fail("No exception raised when parameters are missing") except Exception as e: assert type(e) == SherlockCreateCCAFromModelingRegionError From 86d92e398df83dc602713108b5d68ad99ae98109 Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:18:26 -0400 Subject: [PATCH 22/23] test --- tests/test_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_project.py b/tests/test_project.py index 0978fcb43..58f97d103 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3218,7 +3218,7 @@ def helper_test_create_cca_from_modeling_region(project): { "cca_name": "Main Board", "modeling_region_id": "MR1", - "description": "Test invalid parameter", + "description": "Test", "default_solder_type": "SAC305", "default_stencil_thickness": 10, "default_stencil_thickness_units": "INVALID", From 9e31009a5bafc01333a098c7e0c1e9d92fdb003b Mon Sep 17 00:00:00 2001 From: Joe Dudkowski <173175544+ansjdudkows@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:08:42 -0400 Subject: [PATCH 23/23] fixed project name --- tests/test_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_project.py b/tests/test_project.py index 58f97d103..f7cd6a463 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -3213,7 +3213,7 @@ def helper_test_create_cca_from_modeling_region(project): try: project.create_cca_from_modeling_region( - "Test", + "Tutorial Project", [ { "cca_name": "Main Board",