diff --git a/src/ansys/sherlock/core/analysis.py b/src/ansys/sherlock/core/analysis.py index 2e4da0c75..c3a8b8810 100644 --- a/src/ansys/sherlock/core/analysis.py +++ b/src/ansys/sherlock/core/analysis.py @@ -83,7 +83,7 @@ def run_analysis( - elements: list List of tuples (``type``, ``event``) - - analysis_type : RunAnalysisRequest.Analysis.AnalysisType + - analysis_type : RunAnalysisRequestAnalysisType Type of analysis to run. - event : list @@ -116,7 +116,7 @@ def run_analysis( "Test", "Card", [ - (SherlockAnalysisService_pb2.RunAnalysisRequest.Analysis.AnalysisType.NaturalFreq, + (RunAnalysisRequestAnalysisType.NATURAL_FREQ, [ ("Phase 1", ["Harmonic Event"]) ] @@ -280,10 +280,6 @@ def update_harmonic_vibe_props( ) """ - if self.FREQ_UNIT_LIST is None: - self._init_freq_units() - if self.TEMP_UNIT_LIST is None: - self._init_temp_units() try: if project == "": raise SherlockUpdateHarmonicVibePropsError(message="Project name is invalid.") @@ -355,15 +351,6 @@ def update_harmonic_vibe_props( if "analysis_temp_units" in harmonic_vibe_props.keys(): analysis_temp_units = harmonic_vibe_props["analysis_temp_units"] - if ( - (self.TEMP_UNIT_LIST is not None) - and (analysis_temp_units is not None) - and (analysis_temp_units not in self.TEMP_UNIT_LIST) - ): - raise SherlockUpdateHarmonicVibePropsError( - message=f"Analysis temperature units are invalid for " - f"harmonic vibe properties {i}: " + analysis_temp_units - ) else: analysis_temp_units = None @@ -384,15 +371,6 @@ def update_harmonic_vibe_props( if "natural_freq_min_units" in harmonic_vibe_props.keys(): natural_freq_min_units = harmonic_vibe_props["natural_freq_min_units"] - if ( - (self.FREQ_UNIT_LIST is not None) - and (natural_freq_min_units is not None) - and (natural_freq_min_units not in self.FREQ_UNIT_LIST) - ): - raise SherlockUpdateHarmonicVibePropsError( - message=f"Minimum natural frequency units are invalid for " - f"harmonic vibe properties {i}: " + natural_freq_min_units - ) else: natural_freq_min_units = None @@ -403,15 +381,6 @@ def update_harmonic_vibe_props( if "natural_freq_max_units" in harmonic_vibe_props.keys(): natural_freq_max_units = harmonic_vibe_props["natural_freq_max_units"] - if ( - (self.FREQ_UNIT_LIST is not None) - and (natural_freq_max_units is not None) - and (natural_freq_max_units not in self.FREQ_UNIT_LIST) - ): - raise SherlockUpdateHarmonicVibePropsError( - message=f"Maximum natural frequency units are invalid for " - f"harmonic vibe properties {i}: " + natural_freq_max_units - ) else: natural_freq_max_units = None @@ -512,7 +481,7 @@ def get_random_vibe_input_fields(self, model_source=None): cca_name="Card", ) >>> sherlock.analysis.get_random_vibe_input_fields( - model_source=SherlockAnalysisService_pb2.ModelSource.STRAIN_MAP + model_source=ModelSource.STRAIN_MAP ) """ if not self._is_connection_up(): @@ -629,7 +598,7 @@ def update_random_vibe_props( random_vibe_damping="0.01, 0.05", analysis_temp=20, analysis_temp_units="C", - model_source=SherlockAnalysisService_pb2.ModelSource.STRAIN_MAP, + model_source=ModelSource.STRAIN_MAP, ) """ @@ -1004,13 +973,13 @@ def update_pcb_modeling_props(self, project, cca_names, analyses): analyses : list List of elements consisting of the following properties: - - analysis_type : UpdatePcbModelingPropsRequest.Analysis.AnalysisType + - analysis_type : UpdatePcbModelingPropsRequestAnalysisType Type of analysis applied. - - pcb_model_type : UpdatePcbModelingPropsRequest.Analysis.PcbModelType + - pcb_model_type : UpdatePcbModelingPropsRequestPcbModelType The PCB modeling mesh type. - modeling_region_enabled : bool Indicates if modeling regions are enabled. - - pcb_material_model : UpdatePcbModelingPropsRequest.Analysis.PcbMaterialModel + - pcb_material_model : UpdatePcbModelingPropsRequestPcbMaterialModel The PCB modeling PCB model type. - pcb_max_materials : int The number of PCB materials for Uniform Elements and Layered Elements PCB model @@ -1044,11 +1013,11 @@ def update_pcb_modeling_props(self, project, cca_names, analyses): ["Main Board"], [ ( - update_request.Analysis.AnalysisType.NaturalFreq, - update_request.Analysis.PcbModelType.Bonded, + UpdatePcbModelingPropsRequestAnalysisType.HARMONIC_VIBE, + UpdatePcbModelingPropsRequestPcbModelType.BONDED, True, - update_request.Analysis.PcbMaterialModel.Uniform, - SherlockAnalysisService_pb2.ElementOrder.SolidShell, + UpdatePcbModelingPropsRequestPcbMaterialModel.UNIFORM, + ElementOrder.SOLID_SHELL, 6, "mm", 3, diff --git a/src/ansys/sherlock/core/common.py b/src/ansys/sherlock/core/common.py index cef9f8bc4..8c50e9fdf 100644 --- a/src/ansys/sherlock/core/common.py +++ b/src/ansys/sherlock/core/common.py @@ -18,7 +18,7 @@ class Common(GrpcStub): def __init__(self, channel): """Initialize a gRPC stub for the Sherlock Common service.""" - self.channel = channel + super().__init__(channel) self.stub = SherlockCommonService_pb2_grpc.SherlockCommonServiceStub(channel) def check(self): @@ -73,99 +73,16 @@ def list_units(self, unitType): Parameters ---------- - unitType : string - Unit type. Options are: - - - ``"ACCEL_DENSITY"`` - - ``"ACCELERATION"`` - - ``"AREA"`` - - ``""BANDWIDTH"`` - - ``"CAPACITANCE"`` - - ``"CTE"`` - - ``"CURRENT"`` - - ``"DENSITY"`` - - ``"DISP_DENSITY"`` - - ``"FORCE"`` - - ``"FREQUENCY"`` - - ``"INDUCTANCE"`` - - ``"LENGTH"`` - - ``"POWER"`` - - ``"RESISTANCE"`` - - ``"SIZE"`` - - ``"SPECIFIC_HEAT"`` - - ``"STRAIN"`` - - ``"STRESS"`` - - ``"TEMPERATURE"`` - - ``"THERMAL_CONDUCTIVITY"`` - - ``"THERMAL_RESISTANCE"`` - - ``"TIME"`` - - ``"VELOCITY"`` - - ``"VELOCITY_DENSITY"`` - - ``"VOLTAGE"`` - - ``"VOLUME"`` - - ``"WEIGHT"`` + unitType : ListUnitsRequestUnitType + Unit type. + Returns + ------- + str + Units for the unit type. """ if unitType == "": raise SherlockCommonServiceError(message="Unit type is missing.") - elif unitType == "ACCEL_DENSITY": - unitType = SherlockCommonService_pb2.ListUnitsRequest.ACCEL_DENSITY - elif unitType == "ACCELERATION": - unitType = SherlockCommonService_pb2.ListUnitsRequest.ACCELERATION - elif unitType == "AREA": - unitType = SherlockCommonService_pb2.ListUnitsRequest.AREA - elif unitType == "BANDWIDTH": - unitType = SherlockCommonService_pb2.ListUnitsRequest.BANDWIDTH - elif unitType == "CAPACITANCE": - unitType = SherlockCommonService_pb2.ListUnitsRequest.CAPACITANCE - elif unitType == "CTE": - unitType = SherlockCommonService_pb2.ListUnitsRequest.CTE - elif unitType == "CURRENT": - unitType = SherlockCommonService_pb2.ListUnitsRequest.CURRENT - elif unitType == "DENSITY": - unitType = SherlockCommonService_pb2.ListUnitsRequest.DENSITY - elif unitType == "DISP_DENSITY": - unitType = SherlockCommonService_pb2.ListUnitsRequest.DISP_DENSITY - elif unitType == "FORCE": - unitType = SherlockCommonService_pb2.ListUnitsRequest.FORCE - elif unitType == "FREQUENCY": - unitType = SherlockCommonService_pb2.ListUnitsRequest.FREQUENCY - elif unitType == "INDUCTANCE": - unitType = SherlockCommonService_pb2.ListUnitsRequest.INDUCTANCE - elif unitType == "LENGTH": - unitType = SherlockCommonService_pb2.ListUnitsRequest.LENGTH - elif unitType == "POWER": - unitType = SherlockCommonService_pb2.ListUnitsRequest.POWER - elif unitType == "RESISTANCE": - unitType = SherlockCommonService_pb2.ListUnitsRequest.RESISTANCE - elif unitType == "SIZE": - unitType = SherlockCommonService_pb2.ListUnitsRequest.SIZE - elif unitType == "SPECIFIC_HEAT": - unitType = SherlockCommonService_pb2.ListUnitsRequest.SPECIFIC_HEAT - elif unitType == "STRAIN": - unitType = SherlockCommonService_pb2.ListUnitsRequest.STRAIN - elif unitType == "STRESS": - unitType = SherlockCommonService_pb2.ListUnitsRequest.STRESS - elif unitType == "TEMPERATURE": - unitType = SherlockCommonService_pb2.ListUnitsRequest.TEMPERATURE - elif unitType == "THERMAL_CONDUCTIVITY": - unitType = SherlockCommonService_pb2.ListUnitsRequest.THERMAL_CONDUCTIVITY - elif unitType == "THERMAL_RESISTANCE": - unitType = SherlockCommonService_pb2.ListUnitsRequest.THERMAL_RESISTANCE - elif unitType == "TIME": - unitType = SherlockCommonService_pb2.ListUnitsRequest.TIME - elif unitType == "VELOCITY": - unitType = SherlockCommonService_pb2.ListUnitsRequest.VELOCITY - elif unitType == "VELOCITY_DENSITY": - unitType = SherlockCommonService_pb2.ListUnitsRequest.VELOCITY_DENSITY - elif unitType == "VOLTAGE": - unitType = SherlockCommonService_pb2.ListUnitsRequest.VOLTAGE - elif unitType == "VOLUME": - unitType = SherlockCommonService_pb2.ListUnitsRequest.VOLUME - elif unitType == "WEIGHT": - unitType = SherlockCommonService_pb2.ListUnitsRequest.WEIGHT - else: - raise SherlockCommonServiceError(message=f"Unit type '{unitType}' is invalid.") if not self._is_connection_up(): LOG.error("Not connected to a gRPC service.") @@ -175,18 +92,10 @@ def list_units(self, unitType): try: response = self.stub.listUnits(request) - return_code = response.returnCode - if return_code.value == -1: - if return_code.message == "": - raise SherlockCommonServiceError(error_array=response.errors) - raise SherlockCommonServiceError(message=return_code.message) - except SherlockCommonServiceError as e: - for error in e.str_itr(): - LOG.error(error) raise e return response.units diff --git a/src/ansys/sherlock/core/model.py b/src/ansys/sherlock/core/model.py index 895406667..8b1fb2057 100644 --- a/src/ansys/sherlock/core/model.py +++ b/src/ansys/sherlock/core/model.py @@ -289,62 +289,3 @@ def generate_trace_model( except Exception as e: LOG.error(str(e)) raise - - -# def set_trace_parameter( -# trace_param=None, -# trace_param_diameter_threshold_val=2, -# trace_param_diameter_threshold_unit="mm", -# trace_param_min_hole_diameter_val=0.25, -# trace_param_min_hole_diameter_unit="mm", -# ): -# """Set the Trace Properties for the Export Trace Reinforcement Model operation.""" -# if trace_param is None: -# trace_param = SherlockModelService_pb2.ExportTraceReinforcementModelRequest().TraceParam() -# else: -# if not isinstance( -# trace_param, SherlockModelService_pb2.ExportTraceReinforcementModelRequest.TraceParam -# ): -# raise SherlockModelServiceError( -# "trace_param object is not of type " -# "SherlockModelService_pb2.ExportTraceReinforcementModelRequest.TraceParam." -# ) - -# trace_param.diameterThreshold.value = trace_param_diameter_threshold_val -# trace_param.diameterThreshold.unit = trace_param_diameter_threshold_unit -# trace_param.minHoleDiameterForShellOrBeam.value = trace_param_min_hole_diameter_val -# trace_param.minHoleDiameterForShellOrBeam.unit = trace_param_min_hole_diameter_unit - -# return trace_param - - -# def set_trace_drill_hole_parameter( -# trace_drill_hole_param=None, -# trace_drill_hole_modeling="DISABLED", -# trace_drill_hole_min_diameter_val=2, -# trace_drill_hole_min_diameter_unit="mm", -# trace_drill_hole_max_edge_val=1, -# trace_drill_hole_max_edge_unit="mm", -# ): -# """Set the drill hole properties for exporting the trace reinforcement model.""" -# if trace_drill_hole_param is None: -# trace_drill_hole_param = ( -# SherlockModelService_pb2.ExportTraceReinforcementModelRequest().TraceDrillHoleParam() -# ) -# else: -# if not isinstance( -# trace_drill_hole_param, -# SherlockModelService_pb2.ExportTraceReinforcementModelRequest.TraceDrillHoleParam, -# ): -# raise SherlockModelServiceError( -# "trace_drill_hole_param object is not of type " -# "SherlockModelService_pb2.ExportTraceReinforcementModelRequest.TraceDrillHoleParam." -# ) - -# trace_drill_hole_param.drillHoleModeling = trace_drill_hole_modeling -# trace_drill_hole_param.minHoleDiameter.value = trace_drill_hole_min_diameter_val -# trace_drill_hole_param.minHoleDiameter.unit = trace_drill_hole_min_diameter_unit -# trace_drill_hole_param.maxEdgeLength.value = trace_drill_hole_max_edge_val -# trace_drill_hole_param.maxEdgeLength.unit = trace_drill_hole_max_edge_unit - -# return trace_drill_hole_param diff --git a/src/ansys/sherlock/core/parts.py b/src/ansys/sherlock/core/parts.py index be7b40b78..c6b665432 100644 --- a/src/ansys/sherlock/core/parts.py +++ b/src/ansys/sherlock/core/parts.py @@ -142,7 +142,7 @@ def _init_location_units(self): self.PART_LOCATION_UNITS = part_location_response.units def _init_board_sides(self): - """Initialize boad sides.""" + """Initialize board sides.""" if self._is_connection_up(): board_sides_request = SherlockPartsService_pb2.GetBoardSidesRequest() board_sides_response = self.stub.getBoardSides(board_sides_request) @@ -167,11 +167,10 @@ def update_parts_list( Name of the CCA. part_library : str Name of the parts library. - matching : str - Matching mode for updates. Options are ``"Both"`` and ``"Part"``. - duplication : str + matching : UpdatesPartsListRequestMatchingMode + Matching mode for updates. + duplication : UpdatesPartsListRequestDuplicationMode How to handle duplication during the update. - Options are ``"First"``, ``"Error"``, and ``"Ignore"``. Examples -------- @@ -190,8 +189,8 @@ def update_parts_list( "Test", "Card", "Sherlock Part Library", - "Both", - "Error", + UpdatesPartsListRequestMatchingMode.BOTH, + UpdatesPartsListRequestDuplicationMode.ERROR, ) """ try: @@ -201,10 +200,6 @@ def update_parts_list( raise SherlockUpdatePartsListError(message="CCA name is invalid.") if part_library == "": raise SherlockUpdatePartsListError(message="Parts library is invalid.") - if matching not in self.MATCHING_ARGS: - raise SherlockUpdatePartsListError(message="Matching argument is invalid.") - if duplication not in self.DUPLICATION_ARGS: - raise SherlockUpdatePartsListError(message="Duplication argument is invalid.") except SherlockUpdatePartsListError as e: for error in e.str_itr(): LOG.error(error) @@ -226,9 +221,6 @@ def update_parts_list( try: if return_code.value == -1: - if return_code.message == "": - raise SherlockUpdatePartsListError(error_array=response.updateError) - raise SherlockUpdatePartsListError(message=return_code.message) else: LOG.info(return_code.message) diff --git a/src/ansys/sherlock/core/types/__init__.py b/src/ansys/sherlock/core/types/__init__.py new file mode 100644 index 000000000..0780a6fb3 --- /dev/null +++ b/src/ansys/sherlock/core/types/__init__.py @@ -0,0 +1,3 @@ +# Copyright (c) 2023 ANSYS, Inc. and/or its affiliates. + +"""PySherlock client library constants for enumerated types.""" diff --git a/src/ansys/sherlock/core/types/analysis_types.py b/src/ansys/sherlock/core/types/analysis_types.py new file mode 100644 index 000000000..8bd2e5b7f --- /dev/null +++ b/src/ansys/sherlock/core/types/analysis_types.py @@ -0,0 +1,80 @@ +# Copyright (c) 2023 ANSYS, Inc. and/or its affiliates. + +"""Module containing types for the Analysis Service.""" + +try: + import SherlockAnalysisService_pb2 +except ModuleNotFoundError: + from ansys.api.sherlock.v0 import SherlockAnalysisService_pb2 + +analysis_service = SherlockAnalysisService_pb2 + + +class ElementOrder: + """Values for Element Order.""" + + LINEAR = analysis_service.ElementOrder.Linear + QUADRATIC = analysis_service.ElementOrder.Quadratic + SOLID_SHELL = analysis_service.ElementOrder.SolidShell + + +class ModelSource: + """Values for Model Source.""" + + GENERATED = analysis_service.ModelSource.GENERATED + STRAIN_MAP = analysis_service.ModelSource.STRAIN_MAP + + +class RunAnalysisRequestAnalysisType: + """Values for type of analysis in the Run Analysis request.""" + + __analysis_type = analysis_service.RunAnalysisRequest.Analysis.AnalysisType + NATURAL_FREQ = __analysis_type.NaturalFreq + HARMONIC_VIBE = __analysis_type.HarmonicVibe + ICT = __analysis_type.ICTAnalysis + MECHANICAL_SHOCK = __analysis_type.MechanicalShock + RANDOM_VIBE = __analysis_type.RandomVibe + COMPONENT_FAILURE_MODE = __analysis_type.ComponentFailureMode + DFMEA = __analysis_type.DFMEAModule + PTH_FATIQUE = __analysis_type.PTHFatigue + PART_VALIDATION = __analysis_type.PartValidation + SEMICINDUCTOR_WEAROUT = __analysis_type.SemiconductorWearout + SOLDER_JOINT_FATIGUE = __analysis_type.SolderJointFatigue + THERMAL_DERATING = __analysis_type.ThermalDerating + THERMAL_MECH = __analysis_type.ThermalMech + + +class RunStrainMapAnalysisRequestAnalysisType: + """Values for type of analysis in the Run Strain Map Analysis request.""" + + __analysis_type = analysis_service.RunStrainMapAnalysisRequest.StrainMapAnalysis.AnalysisType + RANDOM_VIBE = __analysis_type.RandomVibe + + +class UpdatePcbModelingPropsRequestAnalysisType: + """Values for type of analysis in the Update PCB Modeling Properties Analysis request.""" + + __analysis_type = analysis_service.UpdatePcbModelingPropsRequest.Analysis.AnalysisType + HARMONIC_VIBE = __analysis_type.HarmonicVibe + ICT = __analysis_type.ICTAnalysis + MECHANICAL_SHOCK = __analysis_type.MechanicalShock + NATURAL_FREQUENCY = __analysis_type.NaturalFreq + RANDOM_VIBE = __analysis_type.RandomVibe + THERMAL_MECH = __analysis_type.ThermalMech + + +class UpdatePcbModelingPropsRequestPcbMaterialModel: + """Values for PCB Material Model in the Update PCB Modeling Properties Analysis request.""" + + __material_model = analysis_service.UpdatePcbModelingPropsRequest.Analysis.PcbMaterialModel + UNIFORM = __material_model.Uniform + LAYERED = __material_model.Layered + UNIFORM_ELEMENTS = __material_model.UniformElements + LAYERED_ELEMENTS = __material_model.LayeredElements + + +class UpdatePcbModelingPropsRequestPcbModelType: + """Values for PCB Model Type in the Update PCB Modeling Properties Analysis request.""" + + __model_type = analysis_service.UpdatePcbModelingPropsRequest.Analysis.PcbModelType + BONDED = __model_type.Bonded diff --git a/src/ansys/sherlock/core/types/common_types.py b/src/ansys/sherlock/core/types/common_types.py new file mode 100644 index 000000000..9ca36535d --- /dev/null +++ b/src/ansys/sherlock/core/types/common_types.py @@ -0,0 +1,41 @@ +# Copyright (c) 2023 ANSYS, Inc. and/or its affiliates. + +"""Module containing types for the Common Service.""" + +try: + import SherlockCommonService_pb2 +except ModuleNotFoundError: + from ansys.api.sherlock.v0 import SherlockCommonService_pb2 + + +class ListUnitsRequestUnitType: + """Values for Unit Type in the List Units request.""" + + ACCEL_DENSITY = SherlockCommonService_pb2.ListUnitsRequest.UnitType.ACCEL_DENSITY + ACCELERATION = SherlockCommonService_pb2.ListUnitsRequest.UnitType.ACCELERATION + AREA = SherlockCommonService_pb2.ListUnitsRequest.UnitType.AREA + BANDWIDTH = SherlockCommonService_pb2.ListUnitsRequest.UnitType.BANDWIDTH + CAPACITANCE = SherlockCommonService_pb2.ListUnitsRequest.UnitType.CAPACITANCE + CTE = SherlockCommonService_pb2.ListUnitsRequest.UnitType.CTE + CURRENT = SherlockCommonService_pb2.ListUnitsRequest.UnitType.CURRENT + DENSITY = SherlockCommonService_pb2.ListUnitsRequest.UnitType.DENSITY + DISP_DENSITY = SherlockCommonService_pb2.ListUnitsRequest.UnitType.DISP_DENSITY + FORCE = SherlockCommonService_pb2.ListUnitsRequest.UnitType.FORCE + FREQUENCY = SherlockCommonService_pb2.ListUnitsRequest.UnitType.FREQUENCY + INDUCTANCE = SherlockCommonService_pb2.ListUnitsRequest.UnitType.INDUCTANCE + LENGTH = SherlockCommonService_pb2.ListUnitsRequest.UnitType.LENGTH + POWER = SherlockCommonService_pb2.ListUnitsRequest.UnitType.POWER + RESISTANCE = SherlockCommonService_pb2.ListUnitsRequest.UnitType.RESISTANCE + SIZE = SherlockCommonService_pb2.ListUnitsRequest.UnitType.SIZE + SPECIFIC_HEAT = SherlockCommonService_pb2.ListUnitsRequest.UnitType.SPECIFIC_HEAT + STRAIN = SherlockCommonService_pb2.ListUnitsRequest.UnitType.STRAIN + STRESS = SherlockCommonService_pb2.ListUnitsRequest.UnitType.STRESS + TEMPERATURE = SherlockCommonService_pb2.ListUnitsRequest.UnitType.TEMPERATURE + THERMAL_CONDUCTIVITY = SherlockCommonService_pb2.ListUnitsRequest.UnitType.THERMAL_CONDUCTIVITY + THERMAL_RESISTANCE = SherlockCommonService_pb2.ListUnitsRequest.UnitType.THERMAL_RESISTANCE + TIME = SherlockCommonService_pb2.ListUnitsRequest.UnitType.TIME + VELOCITY = SherlockCommonService_pb2.ListUnitsRequest.UnitType.VELOCITY + VELOCITY_DENSITY = SherlockCommonService_pb2.ListUnitsRequest.UnitType.VELOCITY_DENSITY + VOLTAGE = SherlockCommonService_pb2.ListUnitsRequest.UnitType.VOLTAGE + VOLUME = SherlockCommonService_pb2.ListUnitsRequest.UnitType.VOLUME + WEIGHT = SherlockCommonService_pb2.ListUnitsRequest.UnitType.WEIGHT diff --git a/src/ansys/sherlock/core/types/parts_types.py b/src/ansys/sherlock/core/types/parts_types.py new file mode 100644 index 000000000..0499b28dc --- /dev/null +++ b/src/ansys/sherlock/core/types/parts_types.py @@ -0,0 +1,23 @@ +# Copyright (c) 2023 ANSYS, Inc. and/or its affiliates. + +"""Module containing types for the Parts Service.""" + +try: + import SherlockPartsService_pb2 +except ModuleNotFoundError: + from ansys.api.sherlock.v0 import SherlockPartsService_pb2 + + +class UpdatesPartsListRequestMatchingMode: + """Values for Matching Mode in the Update Parts List request.""" + + BOTH = SherlockPartsService_pb2.UpdatePartsListRequest.MatchingMode.Both + PART = SherlockPartsService_pb2.UpdatePartsListRequest.MatchingMode.Part + + +class UpdatesPartsListRequestDuplicationMode: + """Values for Duplication Mode in the Update Parts List request.""" + + FIRST = SherlockPartsService_pb2.UpdatePartsListRequest.DuplicationMode.First + ERROR = SherlockPartsService_pb2.UpdatePartsListRequest.DuplicationMode.Error + IGNORE = SherlockPartsService_pb2.UpdatePartsListRequest.DuplicationMode.Ignore diff --git a/tests/test_analysis.py b/tests/test_analysis.py index 649c4cfd6..78876caff 100644 --- a/tests/test_analysis.py +++ b/tests/test_analysis.py @@ -1,11 +1,6 @@ # Copyright (c) 2023 ANSYS, Inc. and/or its affiliates. import time -try: - import SherlockAnalysisService_pb2 -except ModuleNotFoundError: - from ansys.api.sherlock.v0 import SherlockAnalysisService_pb2 - import grpc import pytest @@ -18,6 +13,15 @@ SherlockUpdatePcbModelingPropsError, SherlockUpdateRandomVibePropsError, ) +from ansys.sherlock.core.types.analysis_types import ( + ElementOrder, + ModelSource, + RunAnalysisRequestAnalysisType, + RunStrainMapAnalysisRequestAnalysisType, + UpdatePcbModelingPropsRequestAnalysisType, + UpdatePcbModelingPropsRequestPcbMaterialModel, + UpdatePcbModelingPropsRequestPcbModelType, +) def test_all(): @@ -40,8 +44,7 @@ def test_all(): def helper_test_run_analysis(analysis): """Test run_analysis API.""" - analysis_request = SherlockAnalysisService_pb2.RunAnalysisRequest - natural_frequency_analysis_type = analysis_request.Analysis.AnalysisType.NaturalFreq + natural_frequency_analysis_type = RunAnalysisRequestAnalysisType.NATURAL_FREQ if analysis._is_connection_up(): try: @@ -50,7 +53,7 @@ def helper_test_run_analysis(analysis): "Invalid CCA", [(natural_frequency_analysis_type, [("Phase 1", ["Harmonic Vibe"])])], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockRunAnalysisError @@ -68,7 +71,7 @@ def helper_test_run_analysis(analysis): analysis.run_analysis( "", "Main Board", [(natural_frequency_analysis_type, [("Phase 1", ["Harmonic Vibe"])])] ), - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunAnalysisError as e: assert str(e) == "Run analysis error: Project name is invalid." @@ -78,27 +81,26 @@ def helper_test_run_analysis(analysis): "", [(natural_frequency_analysis_type, [("Phase 1", ["Harmonic Vibe"])])], ), - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunAnalysisError as e: assert str(e) == "Run analysis error: CCA name is invalid." try: analysis.run_analysis("AssemblyTutorial", "Main Board", "Not a list") - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunAnalysisError as e: assert str(e) == "Run analysis error: Analyses argument is invalid." try: analysis.run_analysis("Test", "Card", []) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunAnalysisError as e: assert str(e) == "Run analysis error: One or more analyses are missing." def helper_test_run_strain_map_analysis(analysis): """Test run_strain_map_analysis API.""" - analysis_request = SherlockAnalysisService_pb2.RunStrainMapAnalysisRequest - random_vibe_analysis_type = analysis_request.StrainMapAnalysis.AnalysisType.RandomVibe + random_vibe_analysis_type = RunStrainMapAnalysisRequestAnalysisType.RANDOM_VIBE if analysis._is_connection_up(): try: analysis.run_strain_map_analysis( @@ -121,7 +123,7 @@ def helper_test_run_strain_map_analysis(analysis): ] ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockRunStrainMapAnalysisError @@ -165,7 +167,7 @@ def helper_test_run_strain_map_analysis(analysis): ] ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert str(e) == "Run strain map analysis error: Project name is invalid." @@ -184,7 +186,7 @@ def helper_test_run_strain_map_analysis(analysis): ] ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert str(e) == "Run strain map analysis error: CCA name is invalid." @@ -194,14 +196,14 @@ def helper_test_run_strain_map_analysis(analysis): "Main Board", "Invalid analyses", ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert str(e) == "Run strain map analysis error: Analyses argument is invalid." try: analyses = [] analysis.run_strain_map_analysis("AssemblyTutorial", "Main Board", analyses) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert str(e) == "Run strain map analysis error: One or more analyses are missing." @@ -212,7 +214,7 @@ def helper_test_run_strain_map_analysis(analysis): "Main Board", analyses, ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert ( str(e) == "Run strain map analysis error: Analyses argument is invalid for strain " @@ -226,7 +228,7 @@ def helper_test_run_strain_map_analysis(analysis): "Main Board", analyses, ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert ( str(e) @@ -250,7 +252,7 @@ def helper_test_run_strain_map_analysis(analysis): ] ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert ( str(e) == "Run strain map analysis error: Analysis type is missing for strain map " @@ -269,7 +271,7 @@ def helper_test_run_strain_map_analysis(analysis): ] ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert ( str(e) == "Run strain map analysis error: One or more event strain maps are " @@ -288,7 +290,7 @@ def helper_test_run_strain_map_analysis(analysis): ] ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert ( str(e) == "Run strain map analysis error: Event strain maps argument is invalid for " @@ -310,7 +312,7 @@ def helper_test_run_strain_map_analysis(analysis): ] ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert ( str(e) == "Run strain map analysis error: Number of elements (3) is wrong for event " @@ -332,7 +334,7 @@ def helper_test_run_strain_map_analysis(analysis): ] ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert ( str(e) == "Run strain map analysis error: Life phase is missing for event strain map 1 " @@ -354,7 +356,7 @@ def helper_test_run_strain_map_analysis(analysis): ] ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert ( str(e) == "Run strain map analysis error: Event name is missing for event strain map 2 " @@ -384,7 +386,7 @@ def helper_test_run_strain_map_analysis(analysis): ], ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert ( str(e) @@ -407,7 +409,7 @@ def helper_test_run_strain_map_analysis(analysis): ] ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockRunStrainMapAnalysisError as e: assert ( str(e) == "Run strain map analysis error: Strain map name is missing for event strain " @@ -436,9 +438,7 @@ def helper_test_get_random_vibe_input_fields(analysis): assert "random_vibe_damping" in fields assert "require_material_assignment_enabled" in fields - fields = analysis.get_random_vibe_input_fields( - SherlockAnalysisService_pb2.ModelSource.GENERATED - ) + fields = analysis.get_random_vibe_input_fields(ModelSource.GENERATED) assert "analysis_temp" in fields assert "analysis_temp_units" in fields assert "model_source" in fields @@ -446,9 +446,7 @@ def helper_test_get_random_vibe_input_fields(analysis): assert "random_vibe_damping" in fields assert "require_material_assignment_enabled" in fields - fields = analysis.get_random_vibe_input_fields( - SherlockAnalysisService_pb2.ModelSource.STRAIN_MAP - ) + fields = analysis.get_random_vibe_input_fields(ModelSource.STRAIN_MAP) assert "model_source" in fields assert "part_validation_enabled" in fields assert "random_vibe_damping" in fields @@ -628,7 +626,7 @@ def helper_test_update_harmonic_vibe_props(analysis): if analysis._is_connection_up(): try: analysis.update_harmonic_vibe_props( - "Test", + "Tutorial Project", [ { "cca_name": "Main Board", @@ -642,29 +640,29 @@ def helper_test_update_harmonic_vibe_props(analysis): }, ], ) - assert False - except SherlockUpdateHarmonicVibePropsError as e: - assert ( - str(e) == "Update harmonic vibe properties error: " - "Analysis temperature units are invalid for harmonic vibe properties 0: foo" - ) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockUpdateHarmonicVibePropsError - result = analysis.update_harmonic_vibe_props( - "Test", - [ - { - "cca_name": "Main Board", - "harmonic_vibe_count": 2, - "harmonic_vibe_damping": "0.01, 0.02", - "part_validation_enabled": False, - "require_material_assignment_enabled": False, - "analysis_temp": 20, - "analysis_temp_units": "C", - "filter_by_event_frequency": False, - }, - ], - ) - assert result == 0 + try: + result = analysis.update_harmonic_vibe_props( + "Tutorial Project", + [ + { + "cca_name": "Main Board", + "harmonic_vibe_count": 2, + "harmonic_vibe_damping": "0.01, 0.02", + "part_validation_enabled": False, + "require_material_assignment_enabled": False, + "analysis_temp": 20, + "analysis_temp_units": "C", + "filter_by_event_frequency": False, + }, + ], + ) + assert result == 0 + except SherlockUpdateHarmonicVibePropsError as e: + pytest.fail(str(e)) def helper_test_update_random_vibe_props(analysis): @@ -672,7 +670,7 @@ def helper_test_update_random_vibe_props(analysis): analysis.update_random_vibe_props( "", "Card", random_vibe_damping="0.01, 0.05", analysis_temp=20, analysis_temp_units="C" ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateRandomVibePropsError as e: assert str(e) == "Update random vibe properties error: Project name is invalid." @@ -680,13 +678,13 @@ def helper_test_update_random_vibe_props(analysis): analysis.update_random_vibe_props( "Test", "", random_vibe_damping="0.01, 0.05", analysis_temp=20, analysis_temp_units="C" ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateRandomVibePropsError as e: assert str(e) == "Update random vibe properties error: CCA name is invalid." try: analysis.update_random_vibe_props("Tutorial Project", "Main Board", random_vibe_damping="") - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateRandomVibePropsError as e: assert ( str(e) == "Update random vibe properties error: Random vibe damping value is invalid." @@ -697,10 +695,10 @@ def helper_test_update_random_vibe_props(analysis): "Test", "Card", random_vibe_damping="0.01, 0.02", - model_source=SherlockAnalysisService_pb2.ModelSource.STRAIN_MAP, + model_source=ModelSource.STRAIN_MAP, strain_map_natural_freqs=None, ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateRandomVibePropsError as e: assert str(e) == "Update random vibe properties error: Natural frequencies are invalid." @@ -713,10 +711,10 @@ def helper_test_update_random_vibe_props(analysis): random_vibe_damping="0.01, 0.02", part_validation_enabled=True, require_material_assignment_enabled=False, - model_source=SherlockAnalysisService_pb2.ModelSource.STRAIN_MAP, + model_source=ModelSource.STRAIN_MAP, strain_map_natural_freqs=invalid_strain_map_natural_freqs, ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockUpdateRandomVibePropsError @@ -727,7 +725,7 @@ def helper_test_update_random_vibe_props(analysis): random_vibe_damping="0.01, 0.02", part_validation_enabled=True, require_material_assignment_enabled=False, - model_source=SherlockAnalysisService_pb2.ModelSource.GENERATED, + model_source=ModelSource.GENERATED, strain_map_natural_freqs="101, 201, 501, 1001", ) assert result == 0 @@ -760,7 +758,7 @@ def helper_test_update_natural_frequency_props(analysis): part_validation_enabled=True, require_material_assignment_enabled=False, ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateNaturalFrequencyPropsError as e: assert str(e) == "Update natural frequency properties error: Project name is invalid." @@ -776,7 +774,7 @@ def helper_test_update_natural_frequency_props(analysis): part_validation_enabled=True, require_material_assignment_enabled=False, ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateNaturalFrequencyPropsError as e: assert str(e) == "Update natural frequency properties error: CCA name is invalid." @@ -796,7 +794,7 @@ def helper_test_update_natural_frequency_props(analysis): analysis_temp=25, analysis_temp_units="C", ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockUpdateNaturalFrequencyPropsError @@ -839,7 +837,7 @@ def helper_test_update_pcb_modeling_props(analysis): ) ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePcbModelingPropsError as e: assert str(e) == "Update PCB Modeling Error: Project name is invalid." @@ -862,7 +860,7 @@ def helper_test_update_pcb_modeling_props(analysis): ) ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePcbModelingPropsError as e: assert str(e) == "Update PCB Modeling Error: CCA names are invalid." @@ -872,28 +870,22 @@ def helper_test_update_pcb_modeling_props(analysis): ["Main Board"], [], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePcbModelingPropsError as e: assert str(e) == "Update PCB Modeling Error: Analysis input(s) are invalid." if analysis._is_connection_up(): - request = SherlockAnalysisService_pb2.UpdatePcbModelingPropsRequest - analysis_type = request.Analysis.AnalysisType - pcb_model_type = request.Analysis.PcbModelType - pcb_material_model = request.Analysis.PcbMaterialModel - element_order = SherlockAnalysisService_pb2.ElementOrder - try: analysis.update_pcb_modeling_props( "Tutorial Project", ["Invalid CCA"], [ ( - analysis_type.NaturalFreq, - pcb_model_type.Bonded, + UpdatePcbModelingPropsRequestAnalysisType.NATURAL_FREQUENCY, + UpdatePcbModelingPropsRequestPcbModelType.BONDED, True, - pcb_material_model.Layered, - element_order.SolidShell, + UpdatePcbModelingPropsRequestPcbMaterialModel.LAYERED, + ElementOrder.SOLID_SHELL, 6, "mm", 3, @@ -902,7 +894,7 @@ def helper_test_update_pcb_modeling_props(analysis): ) ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: print(str(e)) assert type(e) == SherlockUpdatePcbModelingPropsError @@ -913,11 +905,11 @@ def helper_test_update_pcb_modeling_props(analysis): ["Main Board"], [ ( - analysis_type.NaturalFreq, - pcb_model_type.Bonded, + UpdatePcbModelingPropsRequestAnalysisType.NATURAL_FREQUENCY, + UpdatePcbModelingPropsRequestPcbModelType.BONDED, True, - pcb_material_model.Uniform, - element_order.SolidShell, + UpdatePcbModelingPropsRequestPcbMaterialModel.UNIFORM, + ElementOrder.SOLID_SHELL, 6, "mm", 3, @@ -936,11 +928,11 @@ def helper_test_update_pcb_modeling_props(analysis): ["Main Board"], [ ( - analysis_type.NaturalFreq, - pcb_model_type.Bonded, + UpdatePcbModelingPropsRequestAnalysisType.NATURAL_FREQUENCY, + UpdatePcbModelingPropsRequestPcbModelType.BONDED, True, - pcb_material_model.Uniform, - element_order.SolidShell, + UpdatePcbModelingPropsRequestPcbMaterialModel.UNIFORM, + ElementOrder.SOLID_SHELL, 6, "mm", 3, @@ -959,11 +951,11 @@ def helper_test_update_pcb_modeling_props(analysis): ["Main Board"], [ ( - analysis_type.NaturalFreq, - pcb_model_type.Bonded, + UpdatePcbModelingPropsRequestAnalysisType.NATURAL_FREQUENCY, + UpdatePcbModelingPropsRequestPcbModelType.BONDED, True, - pcb_material_model.Layered, - element_order.SolidShell, + UpdatePcbModelingPropsRequestPcbMaterialModel.LAYERED, + ElementOrder.SOLID_SHELL, 6, "mm", 3, @@ -982,12 +974,12 @@ def helper_test_update_pcb_modeling_props(analysis): ["Main Board"], [ ( - analysis_type.NaturalFreq, - pcb_model_type.Bonded, + UpdatePcbModelingPropsRequestAnalysisType.NATURAL_FREQUENCY, + UpdatePcbModelingPropsRequestPcbModelType.BONDED, True, - pcb_material_model.UniformElements, + UpdatePcbModelingPropsRequestPcbMaterialModel.UNIFORM_ELEMENTS, 94, - element_order.SolidShell, + ElementOrder.SOLID_SHELL, 6, "mm", 3, @@ -1006,12 +998,12 @@ def helper_test_update_pcb_modeling_props(analysis): ["Main Board"], [ ( - analysis_type.NaturalFreq, - pcb_model_type.Bonded, + UpdatePcbModelingPropsRequestAnalysisType.NATURAL_FREQUENCY, + UpdatePcbModelingPropsRequestPcbModelType.BONDED, True, - pcb_material_model.LayeredElements, + UpdatePcbModelingPropsRequestPcbMaterialModel.LAYERED_ELEMENTS, 94, - element_order.SolidShell, + ElementOrder.SOLID_SHELL, 6, "mm", 3, diff --git a/tests/test_common.py b/tests/test_common.py index 92cf504ff..97b3e72b3 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -1,9 +1,10 @@ # Copyright (c) 2023 ANSYS, Inc. and/or its affiliates. import grpc +import pytest from ansys.sherlock.core.common import Common -from ansys.sherlock.core.errors import SherlockCommonServiceError +from ansys.sherlock.core.types.common_types import ListUnitsRequestUnitType def test_all(): @@ -21,67 +22,10 @@ def helper_test_list_units(common): return try: - common.list_units("NOTHING") - assert False - except SherlockCommonServiceError as e: - assert str(e) == "Sherlock common service error: Unit type 'NOTHING' is invalid." - - units = common.list_units("ACCEL_DENSITY") - assert len(units) == 5 and "G2/Hz" in units - units = common.list_units("ACCELERATION") - assert len(units) == 5 and "G" in units - units = common.list_units("AREA") - assert len(units) == 4 and "in2" in units - units = common.list_units("BANDWIDTH") - assert len(units) == 4 and "Bps" in units - units = common.list_units("CAPACITANCE") - assert len(units) == 10 and "pF" in units - units = common.list_units("CTE") - assert len(units) == 2 and "ppm/C" in units - units = common.list_units("CURRENT") - assert len(units) == 4 and "uA" in units - units = common.list_units("DENSITY") - assert len(units) == 15 and "g/cc" in units - units = common.list_units("DISP_DENSITY") - assert len(units) == 4 and "m2/Hz" in units - units = common.list_units("FORCE") - assert len(units) == 5 and "N" in units - units = common.list_units("FREQUENCY") - assert len(units) == 4 and "HZ" in units - units = common.list_units("INDUCTANCE") - assert len(units) == 5 and "H" in units - units = common.list_units("LENGTH") - assert len(units) == 6 and "in" in units - units = common.list_units("POWER") - assert len(units) == 12 and "pW" in units - units = common.list_units("RESISTANCE") - assert len(units) == 11 and "picoOhm" in units - units = common.list_units("SIZE") - assert len(units) == 18 and "bit" in units - units = common.list_units("SPECIFIC_HEAT") - assert len(units) == 5 and "J/kg-C" in units - units = common.list_units("STRAIN") - assert len(units) == 3 and "µε" in units - units = common.list_units("STRESS") - assert len(units) == 5 and "MPA" in units - units = common.list_units("TEMPERATURE") - assert len(units) == 3 and "C" in units - units = common.list_units("THERMAL_CONDUCTIVITY") - assert len(units) == 7 and "W/m-K" in units - units = common.list_units("THERMAL_RESISTANCE") - assert len(units) == 1 and "C/W" in units - units = common.list_units("TIME") - assert len(units) == 6 and "ms" in units - units = common.list_units("VELOCITY") - assert len(units) == 4 and "m/s" in units - units = common.list_units("VELOCITY_DENSITY") - assert len(units) == 4 and "m2/s2/Hz" in units - units = common.list_units("VOLTAGE") - assert len(units) == 11 and "pV" in units - units = common.list_units("VOLUME") - assert len(units) == 6 and "cc" in units - units = common.list_units("WEIGHT") - assert len(units) == 5 and "mg" in units + units = common.list_units(ListUnitsRequestUnitType.ACCEL_DENSITY) + assert len(units) != 0 + except Exception as e: + pytest.fail(str(e)) if __name__ == "__main__": diff --git a/tests/test_model.py b/tests/test_model.py index f834edc47..87b427df2 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -5,6 +5,7 @@ import unittest import grpc +import pytest from ansys.sherlock.core.errors import SherlockModelServiceError from ansys.sherlock.core.model import Model @@ -29,25 +30,25 @@ def test_model_export_trace_reinforcement_model(self): try: invalid_cca = "Invalid CCA" model.export_trace_reinforcement_model("Tutorial Project", invalid_cca, path) - assert False + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockModelServiceError try: model.export_trace_reinforcement_model("", "Main Board", path) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert str(e) == "Model service error: Project name is invalid." try: model.export_trace_reinforcement_model("Tutorial Project", "", path) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert str(e) == "Model service error: CCA name is invalid." try: model.export_trace_reinforcement_model("Tutorial Project", "Main Board", export_file="") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert str(e) == "Model service error: Export file path is invalid." @@ -56,7 +57,7 @@ def test_model_export_trace_reinforcement_model(self): model.export_trace_reinforcement_model( "Tutorial Project", "Main Board", missing_file_path ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert ( str(e) == "Model service error: Export file directory" @@ -79,7 +80,7 @@ def test_model_generate_trace_model(self): copper_layer_name=copper_layer_name, max_arc_segment=max_arc_segment, ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert str(e) == "Model service error: Project name is invalid." @@ -90,7 +91,7 @@ def test_model_generate_trace_model(self): copper_layer_name=copper_layer_name, max_arc_segment=max_arc_segment, ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert str(e) == "Model service error: CCA name is invalid." @@ -101,7 +102,7 @@ def test_model_generate_trace_model(self): copper_layer_name="", max_arc_segment=max_arc_segment, ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert str(e) == "Model service error: Copper layer name is required." @@ -112,7 +113,7 @@ def test_model_generate_trace_model(self): copper_layer_name=copper_layer_name, max_arc_segment=None, ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert str(e) == "Model service error: Maximum arc segment is required." @@ -124,7 +125,7 @@ def test_model_generate_trace_model(self): max_arc_segment=max_arc_segment, max_arc_segment_units="", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert str(e) == "Model service error: Maximum arc segment units are required." @@ -136,7 +137,7 @@ def test_model_generate_trace_model(self): max_arc_segment=max_arc_segment, min_trace_area=None, ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert str(e) == "Model service error: Minimum trace area is required." @@ -148,7 +149,7 @@ def test_model_generate_trace_model(self): max_arc_segment=max_arc_segment, min_trace_area_units="", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert str(e) == "Model service error: Minimum trace area units are required." @@ -160,7 +161,7 @@ def test_model_generate_trace_model(self): max_arc_segment=max_arc_segment, min_hole_area=None, ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert str(e) == "Model service error: Minimum hole area is required." @@ -172,19 +173,11 @@ def test_model_generate_trace_model(self): max_arc_segment=max_arc_segment, min_hole_area_units="", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockModelServiceError as e: assert str(e) == "Model service error: Minimum hole area units are required." if model._is_connection_up(): - result = model.generate_trace_model( - project_name, - cca_name, - copper_layer_name, - max_arc_segment, - ) - assert result == 0 - try: invalid_cca_name = "Invalid CCA" model.generate_trace_model( @@ -193,10 +186,21 @@ def test_model_generate_trace_model(self): copper_layer_name=copper_layer_name, max_arc_segment=max_arc_segment, ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockModelServiceError + try: + result = model.generate_trace_model( + project_name, + cca_name, + copper_layer_name, + max_arc_segment, + ) + assert result == 0 + except SherlockModelServiceError as e: + pytest.fail(str(e)) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_parts.py b/tests/test_parts.py index 4d31971fe..729e109d0 100644 --- a/tests/test_parts.py +++ b/tests/test_parts.py @@ -17,6 +17,10 @@ SherlockUpdatePartsLocationsError, ) from ansys.sherlock.core.parts import Parts +from ansys.sherlock.core.types.parts_types import ( + UpdatesPartsListRequestDuplicationMode, + UpdatesPartsListRequestMatchingMode, +) def test_all(): @@ -43,8 +47,8 @@ def helper_test_update_parts_list(parts): "Tutorial Project", "Main Board", "Sherlock Part Library", - "Both", - "Error", + UpdatesPartsListRequestMatchingMode.BOTH, + UpdatesPartsListRequestDuplicationMode.ERROR, ) assert result == 0 # wait for Sherlock to finish updating so subsequent tests don't fail @@ -57,10 +61,10 @@ def helper_test_update_parts_list(parts): "Tutorial Project", "Invalid CCA", "Sherlock Part Library", - "Both", - "Error", + UpdatesPartsListRequestMatchingMode.BOTH, + UpdatesPartsListRequestDuplicationMode.ERROR, ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockUpdatePartsListError @@ -69,10 +73,10 @@ def helper_test_update_parts_list(parts): "", "Card", "Sherlock Part Library", - "Both", - "Error", + UpdatesPartsListRequestMatchingMode.BOTH, + UpdatesPartsListRequestDuplicationMode.ERROR, ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePartsListError as e: assert e.str_itr()[0] == "Update parts list error: Project name is invalid." @@ -81,10 +85,10 @@ def helper_test_update_parts_list(parts): "Test", "", "Sherlock Part Library", - "Both", - "Error", + UpdatesPartsListRequestMatchingMode.BOTH, + UpdatesPartsListRequestDuplicationMode.ERROR, ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePartsListError as e: assert e.str_itr()[0] == "Update parts list error: CCA name is invalid." @@ -93,67 +97,43 @@ def helper_test_update_parts_list(parts): "Test", "Card", "", - "Both", - "Error", + UpdatesPartsListRequestMatchingMode.BOTH, + UpdatesPartsListRequestDuplicationMode.ERROR, ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePartsListError as e: assert e.str_itr()[0] == "Update parts list error: Parts library is invalid." - try: - parts.update_parts_list( - "Test", - "Card", - "Sherlock Part Library", - "Invalid", - "Error", - ) - assert False - except SherlockUpdatePartsListError as e: - assert e.str_itr()[0] == "Update parts list error: Matching argument is invalid." - - try: - parts.update_parts_list( - "Test", - "Card", - "Sherlock Part Library", - "Both", - "Invalid", - ) - assert False - except SherlockUpdatePartsListError as e: - assert e.str_itr()[0] == "Update parts list error: Duplication argument is invalid." - def helper_test_update_parts_locations(parts): """Test update_parts_locations API.""" if parts._is_connection_up(): try: - result = parts.update_parts_locations( + parts.update_parts_locations( "Tutorial Project", - "Main Board", + "Invalid CCA", [ ("C1", "-2.7", "-1.65", "0", "in", "TOP", "False"), ("J1", "-3.55", "1", "90", "in", "TOP", "False"), ], ) - assert result == 0 + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: - pytest.fail(e.message) + assert type(e) == SherlockUpdatePartsLocationsError try: - parts.update_parts_locations( + result = parts.update_parts_locations( "Tutorial Project", - "Invalid CCA", + "Main Board", [ ("C1", "-2.7", "-1.65", "0", "in", "TOP", "False"), ("J1", "-3.55", "1", "90", "in", "TOP", "False"), ], ) - pytest.fail("No exception thrown when using an invalid parameter") - except Exception as e: - assert type(e) == SherlockUpdatePartsLocationsError + assert result == 0 + except SherlockUpdatePartsLocationsError as e: + pytest.fail(e.message) try: parts.update_parts_locations( @@ -164,7 +144,7 @@ def helper_test_update_parts_locations(parts): ("J1", "-3.55", "-2.220446049250313E-16", "90", "in", "TOP", "False"), ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePartsLocationsError as e: assert e.str_itr()[0] == "Update parts locations error: Project name is invalid." @@ -177,19 +157,19 @@ def helper_test_update_parts_locations(parts): ("J1", "-3.55", "-2.220446049250313E-16", "90", "in", "TOP", "False"), ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePartsLocationsError as e: assert e.str_itr()[0] == "Update parts locations error: CCA name is invalid." try: parts.update_parts_locations("Test", "Card", "Invalid") - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePartsLocationsError as e: assert e.str_itr()[0] == "Update parts locations error: Part location argument is invalid." try: parts.update_parts_locations("Test", "Card", []) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePartsLocationsError as e: assert ( e.str_itr()[0] == "Update parts locations error: Part location properties " @@ -255,7 +235,7 @@ def helper_test_update_parts_locations(parts): ("J1", "-3.55", "-2.220446049250313E-16", "90", "in", "TOP", "False"), ], ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePartsLocationsError as e: assert ( e.str_itr()[0] @@ -387,7 +367,7 @@ def helper_test_update_parts_locations_by_file(parts): "Main Board", "Invalid file path", ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockUpdatePartsLocationsByFileError @@ -423,7 +403,7 @@ def helper_test_import_parts_list(parts): "Invalid file path", False, ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockImportPartsListError @@ -485,7 +465,7 @@ def helper_test_export_parts_list(parts): "Invalid CCA", parts_list_file, ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockExportPartsListError @@ -495,7 +475,7 @@ def helper_test_export_parts_list(parts): "Card", "Parts List.csv", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockExportPartsListError as e: assert str(e) == "Export parts list error: Project name is invalid." @@ -505,7 +485,7 @@ def helper_test_export_parts_list(parts): "", "Parts List.csv", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockExportPartsListError as e: assert str(e) == "Export parts list error: CCA name is invalid." @@ -527,7 +507,7 @@ def helper_test_enable_lead_modeling(parts): "Tutorial Project", "Invalid CCA", ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockEnableLeadModelingError @@ -536,7 +516,7 @@ def helper_test_enable_lead_modeling(parts): "", "Card", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockEnableLeadModelingError as e: assert str(e) == "Enable lead modeling error: Project name is invalid." @@ -545,7 +525,7 @@ def helper_test_enable_lead_modeling(parts): "Test", "", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockEnableLeadModelingError as e: assert str(e) == "Enable lead modeling error: CCA name is invalid." @@ -572,7 +552,7 @@ def helper_test_get_part_location(parts): "C1", "in", ) - pytest.fail("No exception thrown when using an invalid parameter") + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockGetPartLocationError @@ -583,7 +563,7 @@ def helper_test_get_part_location(parts): "C1", "in", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetPartLocationError as e: assert str(e) == "Get part location error: Project name is invalid." @@ -594,7 +574,7 @@ def helper_test_get_part_location(parts): "C1", "in", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetPartLocationError as e: assert str(e) == "Get part location error: CCA name is invalid." @@ -605,7 +585,7 @@ def helper_test_get_part_location(parts): "", "in", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetPartLocationError as e: assert str(e) == "Get part location error: Ref Des is invalid." @@ -616,7 +596,7 @@ def helper_test_get_part_location(parts): "C1", "", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetPartLocationError as e: assert str(e) == "Get part location error: Location unit is invalid."