From 46367bc4f1258ddbbe95baddc4c3ba989a72f30e Mon Sep 17 00:00:00 2001 From: Jeff Moody Date: Thu, 15 Jun 2023 18:49:58 -0500 Subject: [PATCH 1/2] Lifecycle: remove retrieving units and using for validation. Add and refactor tests. Fix error classes. --- src/ansys/sherlock/core/errors.py | 17 +- src/ansys/sherlock/core/lifecycle.py | 198 ++------ tests/test_lifecycle.py | 713 ++++++++++++++------------- 3 files changed, 418 insertions(+), 510 deletions(-) diff --git a/src/ansys/sherlock/core/errors.py b/src/ansys/sherlock/core/errors.py index b30d2f681..dbdb2246f 100644 --- a/src/ansys/sherlock/core/errors.py +++ b/src/ansys/sherlock/core/errors.py @@ -288,7 +288,7 @@ def __init__(self, message=None, error_array=None): def str_itr(self): """Create list of error messages.""" if self.message is None: - return [f"Create life phase error: {error}" for error in self.error_array] + return [f"Add harmonic event error: {error}" for error in self.error_array] assert self.error_array is None return [f"Add harmonic event error: {self.message}"] @@ -348,13 +348,18 @@ def str_itr(self): class SherlockLoadRandomVibeProfileError(Exception): """Contains the error raised when loading random vibe properties.""" - def __init__(self, message): - """Initialize Error Message.""" + def __init__(self, message=None, error_array=None): + """Initialize error message.""" self.message = message + self.error_array = error_array - def __str__(self): - """Format error message.""" - return f"Load random vibe profile error: {self.message}" + def str_itr(self): + """Create list of error messages.""" + if self.message is None: + return [f"Load random vibe profile error: {error}" for error in self.error_array] + + assert self.error_array is None + return [f"Load random vibe profile error: {self.message}"] class SherlockLoadHarmonicProfileError(Exception): diff --git a/src/ansys/sherlock/core/lifecycle.py b/src/ansys/sherlock/core/lifecycle.py index 6ed4a46f5..5716eb9b5 100644 --- a/src/ansys/sherlock/core/lifecycle.py +++ b/src/ansys/sherlock/core/lifecycle.py @@ -42,26 +42,15 @@ def __init__(self, channel): """Initialize a gRPC stub for the Sherlock Life Cycle service.""" super().__init__(channel) self.stub = SherlockLifeCycleService_pb2_grpc.SherlockLifeCycleServiceStub(channel) - self.TIME_UNIT_LIST = None self.CYCLE_TYPE_LIST = None self.RV_PROFILE_TYPE_LIST = None self.HARMONIC_PROFILE_TYPE_LIST = None - self.FREQ_UNIT_LIST = None self.AMPL_UNIT_LIST = None self.CYCLE_STATE_LIST = None - self.TEMP_UNIT_LIST = None self.LOAD_UNIT_LIST = None self.SHOCK_SHAPE_LIST = None self.STEP_TYPE_LIST = ["RAMP", "HOLD"] - def _init_time_units(self): - """Initialize the list for time units.""" - if self._is_connection_up(): - duration_unit_request = SherlockLifeCycleService_pb2.ListDurationUnitsRequest() - duration_unit_response = self.stub.listDurationUnits(duration_unit_request) - if duration_unit_response.returnCode.value == 0: - self.TIME_UNIT_LIST = duration_unit_response.durationUnits - def _init_cycle_types(self): """Initialize the list for cycle types.""" if self._is_connection_up(): @@ -88,14 +77,6 @@ def _init_harmonic_profile_types(self): if harmonic_profile_response.returnCode.value == 0: self.HARMONIC_PROFILE_TYPE_LIST = harmonic_profile_response.types - def _init_freq_units(self): - """Initialize the list for frequency units.""" - if self._is_connection_up(): - freq_unit_request = SherlockLifeCycleService_pb2.ListFreqUnitsRequest() - freq_type_response = self.stub.listFreqUnits(freq_unit_request) - if freq_type_response.returnCode.value == 0: - self.FREQ_UNIT_LIST = freq_type_response.freqUnits - def _init_ampl_units(self): """Initialize the list for amplitude units.""" if self._is_connection_up(): @@ -112,14 +93,6 @@ def _init_cycle_states(self): if cycle_state_response.returnCode.value == 0: self.CYCLE_STATE_LIST = cycle_state_response.states - def _init_temp_units(self): - """Initialize the list for temperature units.""" - if self._is_connection_up(): - temp_unit_request = SherlockLifeCycleService_pb2.ListTempUnitsRequest() - temp_unit_response = self.stub.listTempUnits(temp_unit_request) - if temp_unit_response.returnCode.value == 0: - self.TEMP_UNIT_LIST = temp_unit_response.tempUnits - def _init_load_units(self): """Initialize the list for load units.""" if self._is_connection_up(): @@ -136,7 +109,8 @@ def _init_shock_shapes(self): if shock_shape_response.returnCode.value == 0: self.SHOCK_SHAPE_LIST = shock_shape_response.shockPulse - def _check_load_direction_validity(self, input): + @staticmethod + def _check_load_direction_validity(input): """Check that the input string is a valid load.""" directions = input.split(",") @@ -157,7 +131,8 @@ def _check_load_direction_validity(self, input): except TypeError: raise SherlockInvalidLoadDirectionError("Direction coordinates are invalid.") - def _check_orientation_validity(self, input): + @staticmethod + def _check_orientation_validity(input): """Check input string if it is a valid orientation.""" orientation = input.split(",") @@ -175,7 +150,8 @@ def _check_orientation_validity(self, input): except: raise SherlockInvalidOrientationError("Elevation value is invalid.") - def _check_random_vibe_profile_entries_validity(self, input): + @staticmethod + def _check_random_vibe_profile_entries_validity(input): """Check input array to see if all elements are valid for random vibe entries.""" if not isinstance(input, list): raise SherlockInvalidRandomVibeProfileEntriesError("Entries argument is invalid.") @@ -248,7 +224,6 @@ def _check_harmonic_profile_entries_validity(self, input): raise SherlockInvalidHarmonicProfileEntriesError( message=f"Invalid entry {i}: Load must be greater than 0" ) - return except TypeError: raise SherlockInvalidHarmonicProfileEntriesError( message=f"Invalid entry {i}: Frequency or load is invalid" @@ -291,38 +266,6 @@ def _check_shock_profile_entries_validity(self, input): message=f"Invalid entry {i}: Load, frequency, or decay is invalid" ) - def _add_random_vibe_profile_entries(self, request, entries): - """Add the random vibe entries to the request.""" - for e in entries: - entry = request.randomVibeProfileEntries.add() - entry.freq = e[0] - entry.ampl = e[1] - - def _add_thermal_profile_entries(self, request, entries): - """Add the thermal entries to the request.""" - for e in entries: - entry = request.thermalProfileEntries.add() - entry.step = e[0] - entry.type = e[1] - entry.time = e[2] - entry.temp = e[3] - - def _add_harmonic_profile_entries(self, request, entries): - """Add the harmonic profile entries to the request.""" - for e in entries: - entry = request.harmonicProfileEntries.add() - entry.freq = e[0] - entry.load = e[1] - - def _add_shock_profile_entries(self, request, entries): - """Add the shock profile entries to the request.""" - for e in entries: - entry = request.shockProfileEntries.add() - entry.shape = e[0] - entry.load = e[1] - entry.freq = e[2] - entry.decay = e[3] - def create_life_phase( self, project, @@ -375,8 +318,6 @@ def create_life_phase( "COUNT", ) """ - if self.TIME_UNIT_LIST is None: - self._init_time_units() if self.CYCLE_TYPE_LIST is None: self._init_cycle_types() @@ -385,8 +326,6 @@ def create_life_phase( raise SherlockCreateLifePhaseError(message="Project name is invalid.") if phase_name == "": raise SherlockCreateLifePhaseError(message="Phase name is invalid.") - if (self.TIME_UNIT_LIST is not None) and (duration_units not in self.TIME_UNIT_LIST): - raise SherlockCreateLifePhaseError(message="Duration unit is invalid.") if duration <= 0.0: raise SherlockCreateLifePhaseError(message="Duration must be greater than 0.") if (self.CYCLE_TYPE_LIST is not None) and (cycle_type not in self.CYCLE_TYPE_LIST): @@ -512,8 +451,6 @@ def add_random_vibe_event( "2,4,5", ) """ - if self.TIME_UNIT_LIST is None: - self._init_time_units() if self.CYCLE_TYPE_LIST is None: self._init_cycle_types() if self.RV_PROFILE_TYPE_LIST is None: @@ -526,8 +463,6 @@ def add_random_vibe_event( raise SherlockAddRandomVibeEventError(message="Phase name is invalid.") if event_name == "": raise SherlockAddRandomVibeEventError(message="Event name is invalid.") - if (self.TIME_UNIT_LIST is not None) and (duration_units not in self.TIME_UNIT_LIST): - raise SherlockAddRandomVibeEventError(message="Duration unit is invalid.") if duration <= 0.0: raise SherlockAddRandomVibeEventError(message="Duration must be greater than 0.") if (self.CYCLE_TYPE_LIST is not None) and (cycle_type not in self.CYCLE_TYPE_LIST): @@ -546,9 +481,7 @@ def add_random_vibe_event( if (self.RV_PROFILE_TYPE_LIST is not None) and ( profile_type not in self.RV_PROFILE_TYPE_LIST ): - raise SherlockAddRandomVibeEventError( - message="Profile type for a random event can only be Uniaxial." - ) + raise SherlockAddRandomVibeEventError(message="Invalid profile type.") self._check_orientation_validity(orientation) except (SherlockInvalidLoadDirectionError, SherlockInvalidOrientationError) as e: LOG.error(f"Add random vibe event error: {str(e)}") @@ -669,8 +602,6 @@ def add_random_vibe_profiles( )] ) """ - if self.FREQ_UNIT_LIST is None: - self._init_freq_units() if self.AMPL_UNIT_LIST is None: self._init_ampl_units() @@ -701,14 +632,6 @@ def add_random_vibe_profiles( raise SherlockAddRandomVibeProfilesError( f"Profile name is invalid for random vibe profile {i}." ) - elif not isinstance(profile_entry[3], str) or ( - (self.FREQ_UNIT_LIST is not None) - and (profile_entry[3] not in self.FREQ_UNIT_LIST) - ): - raise SherlockAddRandomVibeProfilesError( - f"Frequency units {profile_entry[3]} are invalid for random vibe " - f"profile {i}." - ) elif not isinstance(profile_entry[4], str) or ( (self.AMPL_UNIT_LIST is not None) and (profile_entry[4] not in self.AMPL_UNIT_LIST) @@ -840,7 +763,7 @@ def add_thermal_event( if event_name == "": raise SherlockAddThermalEventError(message="Event name is invalid.") if (self.CYCLE_TYPE_LIST is not None) and (cycle_type not in self.CYCLE_TYPE_LIST): - raise SherlockAddThermalEventError(message="Ccycle type is invalid.") + raise SherlockAddThermalEventError(message="Cycle type is invalid.") if num_of_cycles <= 0.0: raise SherlockAddThermalEventError( message="Number of cycles must be greater than 0." @@ -962,11 +885,6 @@ def add_thermal_profiles( )] ) """ - if self.TIME_UNIT_LIST is None: - self._init_time_units() - if self.TEMP_UNIT_LIST is None: - self._init_temp_units() - try: if project == "": raise SherlockAddThermalProfilesError(message="Project name is invalid.") @@ -992,24 +910,9 @@ def add_thermal_profiles( raise SherlockAddThermalProfilesError( f"Profile name is invalid for thermal profile {i}." ) - elif not isinstance(profile_entry[3], str) or ( - (self.TIME_UNIT_LIST is not None) - and (profile_entry[3] not in self.TIME_UNIT_LIST) - ): - raise SherlockAddThermalProfilesError( - f"Time units {profile_entry[3]} are invalid for thermal profile {i}." - ) - elif not isinstance(profile_entry[4], str) or ( - (self.TEMP_UNIT_LIST is not None) - and (profile_entry[4] not in self.TEMP_UNIT_LIST) - ): - raise SherlockAddThermalProfilesError( - f"Temperature units {profile_entry[4]} are invalid for thermal profile {i}." - ) try: self._check_thermal_profile_entries_validity(profile_entry[5]) - except ( SherlockAddThermalProfilesError, SherlockInvalidThermalProfileEntriesError, @@ -1143,8 +1046,6 @@ def add_harmonic_event( "2,4,5", ) """ - if self.TIME_UNIT_LIST is None: - self._init_time_units() if self.CYCLE_TYPE_LIST is None: self._init_cycle_types() if self.HARMONIC_PROFILE_TYPE_LIST is None: @@ -1157,8 +1058,6 @@ def add_harmonic_event( raise SherlockAddHarmonicEventError(message="Phase name is invalid.") if event_name == "": raise SherlockAddHarmonicEventError(message="Event name is invalid.") - if (self.TIME_UNIT_LIST is not None) and (duration_units not in self.TIME_UNIT_LIST): - raise SherlockAddHarmonicEventError(message="Duration units are invalid.") if duration <= 0.0: raise SherlockAddHarmonicEventError(message="Duration must be greater than 0.") if (self.CYCLE_TYPE_LIST is not None) and (cycle_type not in self.CYCLE_TYPE_LIST): @@ -1309,8 +1208,6 @@ def add_harmonic_vibe_profiles( )] ) """ - if self.FREQ_UNIT_LIST is None: - self._init_freq_units() if self.LOAD_UNIT_LIST is None: self._init_load_units() @@ -1336,14 +1233,6 @@ def add_harmonic_vibe_profiles( raise SherlockAddHarmonicVibeProfilesError( f"Profile name is invalid for harmonic vibe profile {i}." ) - elif not isinstance(profile_entry[3], str) or ( - (self.FREQ_UNIT_LIST is not None) - and (profile_entry[3] not in self.FREQ_UNIT_LIST) - ): - raise SherlockAddHarmonicVibeProfilesError( - f"Frequency units {profile_entry[3]} are invalid for harmonic vibe " - f"profile {i}." - ) elif not isinstance(profile_entry[4], str) or ( (self.LOAD_UNIT_LIST is not None) and (profile_entry[4] not in self.LOAD_UNIT_LIST) @@ -1478,8 +1367,6 @@ def add_shock_event( "2,4,5", ) """ - if self.TIME_UNIT_LIST is None: - self._init_time_units() if self.CYCLE_TYPE_LIST is None: self._init_cycle_types() @@ -1490,8 +1377,6 @@ def add_shock_event( raise SherlockAddShockEventError(message="Phase name is invalid.") if event_name == "": raise SherlockAddShockEventError(message="Event name is invalid.") - if (self.TIME_UNIT_LIST is not None) and (duration_units not in self.TIME_UNIT_LIST): - raise SherlockAddShockEventError(message="Duration units are invalid.") if duration <= 0.0: raise SherlockAddShockEventError(message="Duration must be greater than 0.") if (self.CYCLE_TYPE_LIST is not None) and (cycle_type not in self.CYCLE_TYPE_LIST): @@ -1533,9 +1418,8 @@ def add_shock_event( raise SherlockAddShockEventError(error_array=response.errors) raise SherlockAddShockEventError(message=return_code.message) - else: - LOG.info(return_code.message) - return return_code.value + + return return_code.value except SherlockAddShockEventError as e: for error in e.str_itr(): LOG.error(error) @@ -1635,12 +1519,8 @@ def add_shock_profiles( )] ) """ - if self.TIME_UNIT_LIST is None: - self._init_time_units() if self.LOAD_UNIT_LIST is None: self._init_load_units() - if self.FREQ_UNIT_LIST is None: - self._init_freq_units() if self.SHOCK_SHAPE_LIST is None: self._init_shock_shapes() @@ -1670,10 +1550,7 @@ def add_shock_profiles( raise SherlockAddShockProfilesError( f"Duration must be greater than 0 for shock profile {i}." ) - elif not isinstance(profile_entry[4], str) or ( - (self.TIME_UNIT_LIST is not None) - and (profile_entry[4] not in self.TIME_UNIT_LIST) - ): + elif not isinstance(profile_entry[4], str): raise SherlockAddShockProfilesError( f"Duration units {profile_entry[4]} are invalid for shock profile {i}." ) @@ -1681,10 +1558,7 @@ def add_shock_profiles( raise SherlockAddShockProfilesError( f"Sample rate must be greater than 0 for shock profile {i}." ) - elif not isinstance(profile_entry[6], str) or ( - (self.TIME_UNIT_LIST is not None) - and (profile_entry[6] not in self.TIME_UNIT_LIST) - ): + elif not isinstance(profile_entry[6], str): raise SherlockAddShockProfilesError( f"Sample rate unit {profile_entry[6]} are invalid for shock profile {i}." ) @@ -1695,13 +1569,6 @@ def add_shock_profiles( raise SherlockAddShockProfilesError( f"Load units {profile_entry[7]} are invalid for shock profile {i}." ) - elif not isinstance(profile_entry[8], str) or ( - (self.FREQ_UNIT_LIST is not None) - and (profile_entry[8] not in self.FREQ_UNIT_LIST) - ): - raise SherlockAddShockProfilesError( - f"Frequency units {profile_entry[8]} are invalid for shock profile {i}." - ) try: self._check_shock_profile_entries_validity(profile_entry[9]) @@ -1731,7 +1598,7 @@ def add_shock_profiles( profile.loadUnits = s[7] profile.freqUnits = s[8] - """Add shock entries to the request.""" + # Add shock entries to the request for e in s[9]: entry = profile.shockProfileEntries.add() entry.shape = e[0] @@ -1740,18 +1607,15 @@ def add_shock_profiles( entry.decay = e[3] response = self.stub.addShockProfiles(request) - return_code = response.returnCode - try: if return_code.value == -1: if return_code.message == "": raise SherlockAddShockProfilesError(error_array=response.errors) else: raise SherlockAddShockProfilesError(message=return_code.message) - else: - LOG.info(return_code.message) - return return_code.value + + return return_code.value except SherlockAddShockProfilesError as e: for error in e.str_itr(): LOG.error(error) @@ -1811,7 +1675,14 @@ def load_random_vibe_profile(self, project, phase_name, event_name, file_path): filePath=file_path, ) response = self.stub.loadRandomVibeProfile(request) - return response + return_code = response.returnCode + if return_code.value == -1: + if return_code.message == "": + raise SherlockLoadRandomVibeProfileError(error_array=response.errors) + + raise SherlockLoadRandomVibeProfileError(message=return_code.message) + + return return_code.value except SherlockLoadRandomVibeProfileError as e: LOG.error(str(e)) raise e @@ -1870,7 +1741,11 @@ def load_thermal_profile(self, project, phase_name, event_name, file_path): filePath=file_path, ) response = self.stub.loadThermalProfile(request) - return response + return_code = response.returnCode + if return_code.value == -1: + raise SherlockLoadThermalProfileError(return_code.message) + + return return_code.value except SherlockLoadThermalProfileError as e: LOG.error(str(e)) raise e @@ -1929,7 +1804,11 @@ def load_harmonic_profile(self, project, phase_name, event_name, file_path): filePath=file_path, ) response = self.stub.loadHarmonicProfile(request) - return response + return_code = response.returnCode + if return_code.value == -1: + raise SherlockLoadHarmonicProfileError(return_code.message) + + return return_code.value except SherlockLoadHarmonicProfileError as e: LOG.error(str(e)) raise e @@ -1983,7 +1862,11 @@ def load_shock_profile_dataset(self, project, phase_name, event_name, file_path) filePath=file_path, ) response = self.stub.loadShockProfileDataset(request) - return response + return_code = response.returnCode + if return_code.value == -1: + raise SherlockLoadShockProfileDatasetError(return_code.message) + + return return_code.value except SherlockLoadShockProfileDatasetError as e: LOG.error(str(e)) raise e @@ -2043,8 +1926,11 @@ def load_shock_profile_pulses(self, project, phase_name, event_name, file_path): filePath=file_path, ) response = self.stub.loadShockProfilePulses(request) + return_code = response.returnCode + if return_code.value == -1: + raise SherlockLoadShockProfilePulsesError(return_code.message) - return response + return return_code.value except SherlockLoadShockProfilePulsesError as e: LOG.error(str(e)) raise e diff --git a/tests/test_lifecycle.py b/tests/test_lifecycle.py index 42ed362e2..d3f66adb9 100644 --- a/tests/test_lifecycle.py +++ b/tests/test_lifecycle.py @@ -2,6 +2,7 @@ import uuid import grpc +import pytest from ansys.sherlock.core.errors import ( SherlockAddHarmonicEventError, @@ -32,7 +33,7 @@ def test_all(): random_vibe_event_name = helper_test_add_random_vibe_event(lifecycle, phase_name) helper_test_add_random_vibe_profile(lifecycle, random_vibe_event_name, phase_name) thermal_event_name = helper_test_add_thermal_event(lifecycle, phase_name) - helper_test_add_thermal_profile(lifecycle, phase_name, thermal_event_name) + helper_test_add_thermal_profiles(lifecycle, phase_name, thermal_event_name) harmonic_vibe_event_name = helper_test_add_harmonic_event(lifecycle, phase_name) helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_event_name) shock_event_name = helper_test_add_shock_event(lifecycle, phase_name) @@ -49,56 +50,65 @@ def helper_test_create_life_phase(lifecycle): try: lifecycle.create_life_phase("", "", 1, "sec", 1, "PER SEC", description="Test1") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockCreateLifePhaseError as e: assert e.str_itr()[0] == "Create life phase error: Project name is invalid." try: lifecycle.create_life_phase("Test", "", 1, "sec", 1, "PER SEC", description="Test1") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockCreateLifePhaseError as e: assert e.str_itr()[0] == "Create life phase error: Phase name is invalid." try: lifecycle.create_life_phase("Test", "Example", 0, "sec", 1, "PER SEC", description="Test1") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockCreateLifePhaseError as e: assert e.str_itr()[0] == "Create life phase error: Duration must be greater than 0." if lifecycle._is_connection_up(): - try: - lifecycle.create_life_phase( - "Test", "Example", 0, "invalid", 1, "PER SEC", description="Test1" - ) - assert False - except SherlockCreateLifePhaseError as e: - assert e.str_itr()[0] == "Create life phase error: Duration unit is invalid." - try: lifecycle.create_life_phase( "Test", "Example", 5, "sec", 0, "invalid", description="Test1" ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockCreateLifePhaseError as e: assert e.str_itr()[0] == "Create life phase error: Cycle type is invalid." try: lifecycle.create_life_phase("Test", "Example", 5, "sec", 0, "PER SEC", description="Test1") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockCreateLifePhaseError as e: assert e.str_itr()[0] == "Create life phase error: Number of cycles must be greater than 0." if lifecycle._is_connection_up(): phase_name = "Phase " + str(uuid.uuid4()) - result = lifecycle.create_life_phase( - "Tutorial Project", - phase_name, - duration=8400, - duration_units="sec", - num_of_cycles=4, - cycle_type="COUNT", - ) - assert result == 0 + try: + lifecycle.create_life_phase( + "Invalid Project", + phase_name, + duration=8400, + duration_units="sec", + num_of_cycles=4, + cycle_type="COUNT", + ) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockCreateLifePhaseError + + try: + result = lifecycle.create_life_phase( + "Tutorial Project", + phase_name, + duration=8400, + duration_units="sec", + num_of_cycles=4, + cycle_type="COUNT", + ) + assert result == 0 + except SherlockCreateLifePhaseError as e: + pytest.fail(str(e.str_itr())) + return phase_name @@ -109,7 +119,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): lifecycle.add_random_vibe_event( "", "", "", 1, "sec", 1, "PER SEC", "45,45", "Uniaxial", "1,2,3", description="Test1" ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: assert e.str_itr()[0] == "Add random vibe event error: Project name is invalid." @@ -127,7 +137,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): "1,2,3", description="Test1", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: assert e.str_itr()[0] == "Add random vibe event error: Phase name is invalid." @@ -145,7 +155,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): "1,2,3", description="Test1", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: assert e.str_itr()[0] == "Add random vibe event error: Event name is invalid." @@ -163,29 +173,11 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): "1,2,3", description="Test1", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: assert e.str_itr()[0] == "Add random vibe event error: Duration must be greater than 0." if lifecycle._is_connection_up(): - try: - lifecycle.add_random_vibe_event( - "Test", - "Example", - "Event1", - 0, - "invalid", - 1, - "PER SEC", - "45,45", - "Uniaxial", - "1,2,3", - description="Test1", - ) - assert False - except SherlockAddRandomVibeEventError as e: - assert e.str_itr()[0] == "Add random vibe event error: Duration unit is invalid." - try: lifecycle.add_random_vibe_event( "Test", @@ -200,7 +192,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): "1,2,3", description="Test1", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: assert e.str_itr()[0] == "Add random vibe event error: Cycle type is invalid." @@ -218,7 +210,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): "1,2,3", description="Test1", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: assert ( e.str_itr()[0] == "Add random vibe event error: " @@ -239,7 +231,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): "1,2,3", description="Test1", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: assert e.str_itr()[0] == "Add random vibe event error: Elevation value is invalid." @@ -257,7 +249,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): "0,0,0", description="Test1", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: assert ( e.str_itr()[0] @@ -279,7 +271,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): "0,1,0", description="Test1", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: assert ( e.str_itr()[0] == "Add random vibe event error: " @@ -315,6 +307,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): "Uniaxial", "2,4,5", ) + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockAddRandomVibeEventError @@ -324,6 +317,24 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): """Test the add_random_vibe_profiles API""" + try: + lifecycle.add_random_vibe_profiles( + "", + [ + ( + phase_name, + event_name, + "Profile1", + "HZ", + "G2/Hz", + [(1, 2), (3, 4)], + ) + ], + ) + pytest.fail("No exception raised when using an invalid parameter") + except SherlockAddRandomVibeProfilesError as e: + assert e.str_itr()[0] == "Add random vibe profiles error: " "Project name is invalid." + try: lifecycle.add_random_vibe_profiles( "Test", @@ -338,7 +349,7 @@ def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeProfilesError as e: assert ( e.str_itr()[0] == "Add random vibe profiles error: " @@ -359,7 +370,7 @@ def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeProfilesError as e: assert ( e.str_itr()[0] == "Add random vibe profiles error: " @@ -382,7 +393,7 @@ def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeProfilesError as e: assert ( e.str_itr()[0] == "Add random vibe profiles error:" @@ -404,7 +415,7 @@ def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeProfilesError as e: assert ( e.str_itr()[0] == "Add random vibe profiles error:" @@ -413,20 +424,23 @@ def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): ) if lifecycle._is_connection_up(): - result = lifecycle.add_random_vibe_profiles( - "Tutorial Project", - [ - ( - phase_name, - event_name, - "Profile1", - "HZ", - "G2/Hz", - [(1, 2), (3, 4)], - ) - ], - ) - assert result == 0 + try: + result = lifecycle.add_random_vibe_profiles( + "Tutorial Project", + [ + ( + phase_name, + event_name, + "Profile1", + "HZ", + "G2/Hz", + [(1, 2), (3, 4)], + ) + ], + ) + assert result == 0 + except SherlockAddRandomVibeProfilesError as e: + pytest.fail(str(e.str_itr())) try: lifecycle.add_random_vibe_profiles( @@ -442,7 +456,7 @@ def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockAddRandomVibeProfilesError @@ -459,7 +473,7 @@ def helper_test_add_thermal_event(lifecycle, phase_name): "PER SEC", "STORAGE", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddThermalEventError as e: assert e.str_itr()[0] == "Add thermal event error: Project name is invalid." @@ -472,7 +486,7 @@ def helper_test_add_thermal_event(lifecycle, phase_name): "PER SEC", "STORAGE", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddThermalEventError as e: assert e.str_itr()[0] == "Add thermal event error: Phase name is invalid." @@ -485,7 +499,7 @@ def helper_test_add_thermal_event(lifecycle, phase_name): "PER SEC", "STORAGE", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddThermalEventError as e: assert e.str_itr()[0] == "Add thermal event error: Event name is invalid." @@ -498,7 +512,7 @@ def helper_test_add_thermal_event(lifecycle, phase_name): "PER SEC", "STORAGE", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddThermalEventError as e: assert e.str_itr()[0] == "Add thermal event error: Number of cycles must be greater than 0." @@ -523,13 +537,14 @@ def helper_test_add_thermal_event(lifecycle, phase_name): cycle_type="COUNT", cycle_state="OPERATING", ) + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockAddThermalEventError return event_name -def helper_test_add_thermal_profile(lifecycle, phase_name, event_name): +def helper_test_add_thermal_profiles(lifecycle, phase_name, event_name): """Test add_thermal_profiles API.""" try: @@ -550,59 +565,13 @@ def helper_test_add_thermal_profile(lifecycle, phase_name, event_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddThermalProfilesError as e: assert ( e.str_itr()[0] == "Add thermal profiles error: Profile name is invalid for thermal profile 0." ) - if lifecycle._is_connection_up(): - try: - lifecycle.add_thermal_profiles( - "Test", - [ - ( - "Example", - "Event1", - "Profile1", - "Sec", - "F", - [ - ("Initial", "HOLD", 40, 40), - ("Up", "RAMP", 20, 20), - ("Back", "RAMP", 20, 40), - ], - ) - ], - ) - except SherlockAddThermalProfilesError as e: - print(str(e.str_itr()[0])) - assert True - - try: - lifecycle.add_thermal_profiles( - "Test", - [ - ( - "Example", - "Event1", - "Profile1", - "sec", - "IDK", - [ - ("Initial", "HOLD", 40, 40), - ("Up", "RAMP", 20, 20), - ("Back", "RAMP", 20, 40), - ], - ) - ], - ) - - except SherlockAddThermalProfilesError as e: - print(str(e.str_itr()[0])) - assert True - try: lifecycle.add_thermal_profiles( "Test", @@ -753,26 +722,52 @@ def helper_test_add_thermal_profile(lifecycle, phase_name, event_name): == "Add thermal profiles error: Invalid entry 0: Temperature is invalid for thermal " "profile 0." ) + if lifecycle._is_connection_up(): profile = str(uuid.uuid4()) - result = lifecycle.add_thermal_profiles( - "Tutorial Project", - [ - ( - phase_name, - event_name, - profile, - "sec", - "F", - [ - ("Steady1", "HOLD", 40, 40), - ("Steady", "HOLD", 20, 20), - ("Back", "RAMP", 20, 40), - ], - ) - ], - ) - assert result == 0 + try: + lifecycle.add_thermal_profiles( + "Missing Project", + [ + ( + phase_name, + event_name, + profile, + "sec", + "F", + [ + ("Steady1", "HOLD", 40, 40), + ("Steady", "HOLD", 20, 20), + ("Back", "RAMP", 20, 40), + ], + ) + ], + ) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockAddThermalProfilesError + + try: + result = lifecycle.add_thermal_profiles( + "Tutorial Project", + [ + ( + phase_name, + event_name, + profile, + "sec", + "F", + [ + ("Steady1", "HOLD", 40, 40), + ("Steady", "HOLD", 20, 20), + ("Back", "RAMP", 20, 40), + ], + ) + ], + ) + assert result == 0 + except SherlockAddThermalProfilesError as e: + pytest.fail(str(e.str_itr())) def helper_test_add_harmonic_event(lifecycle, phase_name): @@ -792,7 +787,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): "Uniaxial", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert e.str_itr()[0] == "Add harmonic event error: Project name is invalid." @@ -810,7 +805,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): "Uniaxial", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert e.str_itr()[0] == "Add harmonic event error: Phase name is invalid." @@ -828,7 +823,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): "Uniaxial", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert e.str_itr()[0] == "Add harmonic event error: Event name is invalid." @@ -846,29 +841,11 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): "Uniaxial", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert e.str_itr()[0] == "Add harmonic event error: Duration must be greater than 0." if lifecycle._is_connection_up(): - try: - lifecycle.add_harmonic_event( - "Test", - "Example", - "Event1", - 1.5, - "Invalid", - 4.0, - "PER MIN", - 5, - "45,45", - "Uniaxial", - "2,4,5", - ) - except SherlockAddHarmonicEventError as e: - print(str(e.str_itr()[0])) - assert True - try: lifecycle.add_harmonic_event( "Test", @@ -877,13 +854,13 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): 1.5, "sec", 4.0, - "Invalid", + "Invalid Cycle Type", 5, "45,45", "Uniaxial", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert e.str_itr()[0] == "Add harmonic event error: Cycle type is invalid." @@ -898,12 +875,12 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): "PER MIN", 5, "45,45", - "Invalid", + "Invalid Profile Type", "2,4,5", ) + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: - print(str(e.str_itr()[0])) - assert True + assert e.str_itr()[0] == "Add harmonic event error: Profile type is invalid." try: lifecycle.add_harmonic_event( @@ -919,7 +896,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): "Uniaxial", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert ( e.str_itr()[0] == "Add harmonic event error: Number of cycles must be " @@ -940,7 +917,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): "Uniaxial", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert e.str_itr()[0] == "Add harmonic event error: Sweep rate must be greater than 0." @@ -958,7 +935,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): "Uniaxial", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert e.str_itr()[0] == "Add harmonic event error: Azimuth value is invalid." @@ -976,7 +953,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): "Uniaxial", "0,0,0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert ( e.str_itr()[0] @@ -997,7 +974,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): "Uniaxial", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert ( e.str_itr()[0] == "Add harmonic event error: Number of spherical coordinates " @@ -1005,20 +982,41 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): ) if lifecycle._is_connection_up(): event_name = "Harmonic Vibe Event " + str(uuid.uuid4()) - result = lifecycle.add_harmonic_event( - "Tutorial Project", - phase_name, - event_name, - 1.0, - "sec", - 4.0, - "PER MIN", - 5.0, - "45,45", - "Triaxial", - "2,4,5", - ) - assert result == 0 + try: + lifecycle.add_harmonic_event( + "Invalid Project", + phase_name, + event_name, + 1.0, + "sec", + 4.0, + "PER MIN", + 5.0, + "45,45", + "Triaxial", + "2,4,5", + ) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockAddHarmonicEventError + + try: + result = lifecycle.add_harmonic_event( + "Tutorial Project", + phase_name, + event_name, + 1.0, + "sec", + 4.0, + "PER MIN", + 5.0, + "45,45", + "Triaxial", + "2,4,5", + ) + assert result == 0 + except SherlockAddHarmonicEventError as e: + raise (str(e.str_itr())) return event_name @@ -1044,7 +1042,7 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert e.str_itr()[0] == "Add harmonic vibe profiles error: Project name is invalid." @@ -1066,7 +1064,7 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( e.str_itr()[0] == "Add harmonic vibe profiles error:" @@ -1091,7 +1089,7 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( e.str_itr()[0] == "Add harmonic vibe profiles error:" @@ -1116,7 +1114,7 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( e.str_itr()[0] == "Add harmonic vibe profiles error:" @@ -1124,28 +1122,6 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e ) if lifecycle._is_connection_up(): - try: - lifecycle.add_harmonic_vibe_profiles( - "Test", - [ - ( - "Example", - "Event1", - "Profile1", - "badUnits", - "G", - [ - (10, 1), - (1000, 1), - ], - "", - ) - ], - ) - except SherlockAddHarmonicVibeProfilesError as e: - print(str(e.str_itr()[0])) - assert True - try: lifecycle.add_harmonic_vibe_profiles( "Test", @@ -1155,7 +1131,7 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e "Event1", "Profile1", "HZ", - "badUnits", + "InvalidLoadUnits", [ (10, 1), (1000, 1), @@ -1164,9 +1140,12 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e ) ], ) + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: - print(str(e.str_itr()[0])) - assert True + assert ( + e.str_itr()[0] == "Add harmonic vibe profiles error: " + "Load units InvalidLoadUnits are invalid for harmonic vibe profile 0." + ) try: lifecycle.add_harmonic_vibe_profiles( @@ -1186,7 +1165,7 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( e.str_itr()[0] == "Add harmonic vibe profiles error:" @@ -1212,7 +1191,7 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( e.str_itr()[0] == "Add harmonic vibe profiles error: " @@ -1238,7 +1217,7 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( e.str_itr()[0] == "Add harmonic vibe profiles error:" @@ -1247,24 +1226,49 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e ) if lifecycle._is_connection_up(): profile = str(uuid.uuid4()) - result = lifecycle.add_harmonic_vibe_profiles( - "Tutorial Project", - [ - ( - phase_name, - harmonic_vibe_event_name, - profile, - "HZ", - "G", - [ - (10, 1), - (1000, 1), - ], - "z", - ) - ], - ) - assert result == 0 + try: + lifecycle.add_harmonic_vibe_profiles( + "Invalid Project", + [ + ( + phase_name, + harmonic_vibe_event_name, + profile, + "HZ", + "G", + [ + (10, 1), + (1000, 1), + ], + "z", + ) + ], + ) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockAddHarmonicVibeProfilesError + + try: + result = lifecycle.add_harmonic_vibe_profiles( + "Tutorial Project", + [ + ( + phase_name, + harmonic_vibe_event_name, + profile, + "HZ", + "G", + [ + (10, 1), + (1000, 1), + ], + "z", + ) + ], + ) + assert result == 0 + except SherlockAddHarmonicVibeProfilesError as e: + pytest.fail(str(e.str_itr())) def helper_test_add_shock_event(lifecycle, phase_name): @@ -1282,7 +1286,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): "45,45", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: assert e.str_itr()[0] == "Add shock event error: Project name is invalid." @@ -1298,7 +1302,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): "45,45", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: assert e.str_itr()[0] == "Add shock event error: Phase name is invalid." @@ -1314,7 +1318,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): "45,45", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: assert e.str_itr()[0] == "Add shock event error: Event name is invalid." @@ -1330,7 +1334,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): "45,45", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: assert e.str_itr()[0] == "Add shock event error: Duration must be greater than 0." @@ -1346,7 +1350,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): "45,45", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: assert e.str_itr()[0] == "Add shock event error: Number of cycles must be greater than 0." @@ -1363,7 +1367,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): "1,2,3", description="Test1", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: assert e.str_itr()[0] == "Add shock event error: Elevation value is invalid." @@ -1380,7 +1384,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): "0,0,0", description="Test1", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: assert ( e.str_itr()[0] == "Add shock event error: At least one direction coordinate must be " @@ -1400,7 +1404,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): "0,1,0", description="Test1", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: assert ( e.str_itr()[0] == "Add shock event error: Number of spherical coordinates " @@ -1408,20 +1412,6 @@ def helper_test_add_shock_event(lifecycle, phase_name): ) if lifecycle._is_connection_up(): - event_name = "Shock Event " + str(uuid.uuid4()) - result = lifecycle.add_shock_event( - "Tutorial Project", - phase_name, - event_name, - 1.0, - "sec", - 4.0, - "PER MIN", - "45,45", - "2,4,5", - ) - assert result == 0 - try: lifecycle.add_shock_event( "Test", @@ -1434,10 +1424,27 @@ def helper_test_add_shock_event(lifecycle, phase_name): "45,45", "2,4,5", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockAddShockEventError + try: + event_name = "Shock Event " + str(uuid.uuid4()) + result = lifecycle.add_shock_event( + "Tutorial Project", + phase_name, + event_name, + 1.0, + "sec", + 4.0, + "PER MIN", + "45,45", + "2,4,5", + ) + assert result == 0 + except SherlockAddShockEventError as e: + pytest.fail(str(e.str_itr())) + return event_name @@ -1462,7 +1469,7 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert e.str_itr()[0] == "Add shock profiles error: Project name is invalid." @@ -1484,7 +1491,7 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( e.str_itr()[0] == "Add shock profiles error: Phase name is invalid for " @@ -1509,7 +1516,7 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( e.str_itr()[0] == "Add shock profiles error: Event name is invalid for " @@ -1534,7 +1541,7 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( e.str_itr()[0] == "Add shock profiles error:" @@ -1559,7 +1566,7 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( e.str_itr()[0] == "Add shock profiles error:" @@ -1584,7 +1591,7 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( e.str_itr()[0] == "Add shock profiles error:" @@ -1609,7 +1616,7 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( e.str_itr()[0] == "Add shock profiles error:" @@ -1634,7 +1641,7 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( e.str_itr()[0] == "Add shock profiles error:" @@ -1660,7 +1667,7 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( e.str_itr()[0] == "Add shock profiles error:" @@ -1686,7 +1693,7 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( e.str_itr()[0] == "Add shock profiles error:" @@ -1696,25 +1703,6 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): if lifecycle._is_connection_up(): profile = str(uuid.uuid4()) - result = lifecycle.add_shock_profiles( - "Tutorial Project", - [ - ( - phase_name, - shock_event_name, - profile, - 10.0, - "ms", - 0.1, - "ms", - "G", - "HZ", - [("HalfSine", 100.0, 100.0, 0)], - ) - ], - ) - assert result == 0 - try: lifecycle.add_shock_profiles( "Test", @@ -1733,10 +1721,32 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockAddShockProfilesError + try: + result = lifecycle.add_shock_profiles( + "Tutorial Project", + [ + ( + phase_name, + shock_event_name, + profile, + 10.0, + "ms", + 0.1, + "ms", + "G", + "HZ", + [("HalfSine", 100.0, 100.0, 0)], + ) + ], + ) + assert result == 0 + except SherlockAddShockProfilesError as e: + pytest.fail(str(e.str_itr())) + def helper_test_load_random_vibe_profile(lifecycle): """Test load_random_vibe_profile.""" @@ -1748,9 +1758,10 @@ def helper_test_load_random_vibe_profile(lifecycle): "Random Event", "TestProfile.dat", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadRandomVibeProfileError as e: - assert str(e) == "Load random vibe profile error: Project name is invalid." + assert str(e.str_itr()) == "['Load random vibe profile error: Project name is invalid.']" + try: lifecycle.load_random_vibe_profile( "Test", @@ -1758,9 +1769,10 @@ def helper_test_load_random_vibe_profile(lifecycle): "Random Event", "TestProfile.dat", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadRandomVibeProfileError as e: - assert str(e) == "Load random vibe profile error: Phase name is invalid." + assert str(e.str_itr()) == "['Load random vibe profile error: Phase name is invalid.']" + try: lifecycle.load_random_vibe_profile( "Test", @@ -1768,9 +1780,9 @@ def helper_test_load_random_vibe_profile(lifecycle): "", "TestProfile.dat", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadRandomVibeProfileError as e: - assert str(e) == "Load random vibe profile error: Event name is invalid." + assert str(e.str_itr()) == "['Load random vibe profile error: Event name is invalid.']" try: lifecycle.load_random_vibe_profile( @@ -1779,21 +1791,21 @@ def helper_test_load_random_vibe_profile(lifecycle): "Random Event", "", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadRandomVibeProfileError as e: - assert str(e) == "Load random vibe profile error: File path is invalid." + assert str(e.str_itr()) == "['Load random vibe profile error: File path is invalid.']" if lifecycle._is_connection_up(): - loaded = lifecycle.load_random_vibe_profile( - "Test Project", - "Phase 1", - "Random Event", - "TestProfile.dat", - ) try: - return loaded + lifecycle.load_random_vibe_profile( + "Invalid Project", + "Phase 1", + "Random Event", + "TestProfile.dat", + ) + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: - print(str(e)) + type(e) == SherlockLoadRandomVibeProfileError def helper_test_load_harmonic_profile(lifecycle): @@ -1801,38 +1813,38 @@ def helper_test_load_harmonic_profile(lifecycle): try: lifecycle.load_harmonic_profile("", "Phase 1", "Harmonic Event", "Test_Profile.dat") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadHarmonicProfileError as e: assert str(e) == "Load Harmonic profile error: Project name is invalid." try: lifecycle.load_harmonic_profile("Test", "", "Harmonic Event", "Test_Profile.dat") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadHarmonicProfileError as e: assert str(e) == "Load Harmonic profile error: Phase name is invalid." try: lifecycle.load_harmonic_profile("Test", "Phase 1", "", "Test_Profile.dat") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadHarmonicProfileError as e: assert str(e) == "Load Harmonic profile error: Event name is invalid." try: lifecycle.load_harmonic_profile("Test", "Phase 1", "Harmonic Event", "") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadHarmonicProfileError as e: assert str(e) == "Load Harmonic profile error: File name is invalid." if lifecycle._is_connection_up(): - loaded = lifecycle.load_harmonic_profile( - "Test Project", - "Phase 1", - "Harmonic Event", - "Test_Profile.dat", - ) try: - return loaded + lifecycle.load_harmonic_profile( + "Invalid Project", + "Phase 1", + "Harmonic Event", + "Test_Profile.dat", + ) + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: - print(str(e)) + assert type(e) == SherlockLoadHarmonicProfileError def helper_test_load_thermal_profile(lifecycle): @@ -1845,7 +1857,7 @@ def helper_test_load_thermal_profile(lifecycle): "Thermal Event", "Tutorial_Profile.dat", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadThermalProfileError as e: assert str(e) == "Load thermal profile error: Project name is invalid." @@ -1856,7 +1868,7 @@ def helper_test_load_thermal_profile(lifecycle): "Thermal Event", "Tutorial_Profile.dat", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadThermalProfileError as e: assert str(e) == "Load thermal profile error: Phase name is invalid." @@ -1867,7 +1879,7 @@ def helper_test_load_thermal_profile(lifecycle): "", "Tutorial_Profile.dat", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadThermalProfileError as e: assert str(e) == "Load thermal profile error: Event name is invalid." @@ -1878,21 +1890,21 @@ def helper_test_load_thermal_profile(lifecycle): "Thermal Event", "", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadThermalProfileError as e: assert str(e) == "Load thermal profile error: File path is invalid." if lifecycle._is_connection_up(): - loaded = lifecycle.load_thermal_profile( - "Test Project", - "Phase 1", - "Thermal Event", - "Tutorial_Profile.dat", - ) try: - return loaded + lifecycle.load_thermal_profile( + "Test Project", + "Phase 1", + "Thermal Event", + "Tutorial_Profile.dat", + ) + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: - print(str(e)) + assert type(e) == SherlockLoadThermalProfileError def helper_test_load_shock_profile_dataset(lifecycle): @@ -1905,7 +1917,7 @@ def helper_test_load_shock_profile_dataset(lifecycle): "Shock Event", "Test_Profile.dat", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfileDatasetError as e: assert str(e) == "Load shock profile dataset error: Project name is invalid." @@ -1916,7 +1928,7 @@ def helper_test_load_shock_profile_dataset(lifecycle): "Shock Event", "Test_Profile.dat", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfileDatasetError as e: assert str(e) == "Load shock profile dataset error: Phase name is invalid." @@ -1927,7 +1939,7 @@ def helper_test_load_shock_profile_dataset(lifecycle): "", "Test_Profile.dat", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfileDatasetError as e: assert str(e) == "Load shock profile dataset error: Event name is invalid." @@ -1938,21 +1950,21 @@ def helper_test_load_shock_profile_dataset(lifecycle): "Shock Event", "", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfileDatasetError as e: assert str(e) == "Load shock profile dataset error: File path is invalid." if lifecycle._is_connection_up(): - loaded = lifecycle.load_shock_profile_dataset( - "Tutorial Project", - "Phase 1", - "Shock Event", - "Test_Profile.dat", - ) try: - return loaded + lifecycle.load_shock_profile_dataset( + "Tutorial Project", + "Phase 1", + "Shock Event", + "Test_Profile.dat", + ) + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: - print(str(e)) + assert type(e) == SherlockLoadShockProfileDatasetError def helper_test_load_shock_profile_pulses(lifecycle): @@ -1964,6 +1976,7 @@ def helper_test_load_shock_profile_pulses(lifecycle): "Shock Event", "Test_Profile.dat", ) + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfilePulsesError as e: assert str(e) == "Load shock profile pulses error: Project name is invalid." @@ -1974,6 +1987,7 @@ def helper_test_load_shock_profile_pulses(lifecycle): "Shock Event", "Test_Profile.dat", ) + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfilePulsesError as e: assert str(e) == "Load shock profile pulses error: Phase name is invalid." @@ -1984,6 +1998,7 @@ def helper_test_load_shock_profile_pulses(lifecycle): "", "Test_Profile.dat", ) + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfilePulsesError as e: assert str(e) == "Load shock profile pulses error: Event name is invalid." @@ -1994,19 +2009,21 @@ def helper_test_load_shock_profile_pulses(lifecycle): "Shock Event", "", ) + pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfilePulsesError as e: assert str(e) == "Load shock profile pulses error: File path is invalid." + if lifecycle._is_connection_up(): - loaded = lifecycle.load_shock_profile_pulses( - "Tutorial Project", - "Phase 1", - "Shock Event", - "Test_Profile.dat", - ) try: - return loaded + lifecycle.load_shock_profile_pulses( + "Tutorial Project", + "Phase 1", + "Shock Event", + "Test_Profile.dat", + ) + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: - print(str(e)) + assert type(e) == SherlockLoadShockProfilePulsesError if __name__ == "__main__": From 9cf80be00f3602a9923c85019454e4e04e78cdae Mon Sep 17 00:00:00 2001 From: Jeff Moody Date: Fri, 16 Jun 2023 11:56:53 -0500 Subject: [PATCH 2/2] Changed some error classes to support multiple errors. Updates for test code consistency. --- src/ansys/sherlock/core/errors.py | 52 +++-- src/ansys/sherlock/core/lifecycle.py | 9 +- tests/test_common.py | 21 +- tests/test_lifecycle.py | 274 ++++++++++++++------------- tests/test_parts.py | 112 +++++------ tests/test_project.py | 179 +++++++++-------- tests/test_stackup.py | 141 +++++++------- 7 files changed, 419 insertions(+), 369 deletions(-) diff --git a/src/ansys/sherlock/core/errors.py b/src/ansys/sherlock/core/errors.py index dbdb2246f..1a91caede 100644 --- a/src/ansys/sherlock/core/errors.py +++ b/src/ansys/sherlock/core/errors.py @@ -365,13 +365,18 @@ def str_itr(self): class SherlockLoadHarmonicProfileError(Exception): """Contains the error raised when loading a harmonic profile.""" - def __init__(self, message): + def __init__(self, message=None, error_array=None): """Initialize error message.""" self.message = message + self.error_array = error_array - def __str__(self): - """Format Error Message.""" - return f"Load Harmonic profile error: {self.message}" + def str_itr(self): + """Create list of error messages.""" + if self.message is None: + return [f"Load harmonic profile error: {error}" for error in self.error_array] + + assert self.error_array is None + return [f"Load harmonic profile error: {self.message}"] class SherlockUpdateMountPointsByFileError(Exception): @@ -529,13 +534,18 @@ def __str__(self): class SherlockLoadThermalProfileError(Exception): """Contains the error raised when loading thermal profile.""" - def __init__(self, message): + def __init__(self, message=None, error_array=None): """Initialize error message.""" self.message = message + self.error_array = error_array - def __str__(self): - """Format error message.""" - return f"Load thermal profile error: {self.message}" + def str_itr(self): + """Create list of error messages.""" + if self.message is None: + return [f"Load thermal profile error: {error}" for error in self.error_array] + + assert self.error_array is None + return [f"Load thermal profile error: {self.message}"] class SherlockRunAnalysisError(Exception): @@ -577,13 +587,18 @@ def __str__(self): class SherlockLoadShockProfileDatasetError(Exception): """Contains the error raised when loading shock profile dataset results in an error.""" - def __init__(self, message): + def __init__(self, message=None, error_array=None): """Initialize error message.""" self.message = message + self.error_array = error_array - def __str__(self): - """Initialize error message.""" - return f"Load shock profile dataset error: {self.message}" + def str_itr(self): + """Create list of error messages.""" + if self.message is None: + return [f"Load shock profile dataset error: {error}" for error in self.error_array] + + assert self.error_array is None + return [f"Load shock profile dataset error: {self.message}"] class SherlockUpdateNaturalFrequencyPropsError(Exception): @@ -757,13 +772,18 @@ def __str__(self): class SherlockLoadShockProfilePulsesError(Exception): """Contains the error raised when loading shock profile pulses.""" - def __init__(self, message): + def __init__(self, message=None, error_array=None): """Initialize error message.""" self.message = message + self.error_array = error_array - def __str__(self): - """Format error message.""" - return f"Load shock profile pulses error: {self.message}" + def str_itr(self): + """Create list of error messages.""" + if self.message is None: + return [f"Load shock profile pulses error: {error}" for error in self.error_array] + + assert self.error_array is None + return [f"Load shock profile pulses error: {self.message}"] class SherlockUpdatePcbModelingPropsError(Exception): diff --git a/src/ansys/sherlock/core/lifecycle.py b/src/ansys/sherlock/core/lifecycle.py index 5716eb9b5..9b9fc8c7b 100644 --- a/src/ansys/sherlock/core/lifecycle.py +++ b/src/ansys/sherlock/core/lifecycle.py @@ -205,7 +205,8 @@ def _check_thermal_profile_entries_validity(self, input): except TypeError: raise SherlockInvalidThermalProfileEntriesError(f"Invalid entry {i}: Time is invalid") - def _check_harmonic_profile_entries_validity(self, input): + @staticmethod + def _check_harmonic_profile_entries_validity(input): """Check input array if all elements are valid for harmonic entries.""" if not isinstance(input, list): raise SherlockInvalidHarmonicProfileEntriesError(message="Entries argument is invalid.") @@ -1805,8 +1806,12 @@ def load_harmonic_profile(self, project, phase_name, event_name, file_path): ) response = self.stub.loadHarmonicProfile(request) return_code = response.returnCode + if return_code.value == -1: - raise SherlockLoadHarmonicProfileError(return_code.message) + if return_code.message == "": + raise SherlockLoadHarmonicProfileError(error_array=response.errors) + + raise SherlockLoadHarmonicProfileError(message=return_code.message) return return_code.value except SherlockLoadHarmonicProfileError as e: diff --git a/tests/test_common.py b/tests/test_common.py index 97b3e72b3..981743a87 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -4,6 +4,7 @@ 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 @@ -18,14 +19,18 @@ def test_all(): def helper_test_list_units(common): """Test list_units API""" - if not common._is_connection_up(): - return - - try: - units = common.list_units(ListUnitsRequestUnitType.ACCEL_DENSITY) - assert len(units) != 0 - except Exception as e: - pytest.fail(str(e)) + if common._is_connection_up(): + try: + common.list_units(ListUnitsRequestUnitType.WEIGHT + 10000) + pytest.fail("No exception raised when using an invalid parameter") + except Exception as e: + assert type(e) == SherlockCommonServiceError + + try: + units = common.list_units(ListUnitsRequestUnitType.ACCEL_DENSITY) + assert len(units) != 0 + except SherlockCommonServiceError as e: + pytest.fail(str(e)) if __name__ == "__main__": diff --git a/tests/test_lifecycle.py b/tests/test_lifecycle.py index d3f66adb9..dcf04fb59 100644 --- a/tests/test_lifecycle.py +++ b/tests/test_lifecycle.py @@ -31,7 +31,7 @@ def test_all(): phase_name = helper_test_create_life_phase(lifecycle) random_vibe_event_name = helper_test_add_random_vibe_event(lifecycle, phase_name) - helper_test_add_random_vibe_profile(lifecycle, random_vibe_event_name, phase_name) + helper_test_add_random_vibe_profiles(lifecycle, random_vibe_event_name, phase_name) thermal_event_name = helper_test_add_thermal_event(lifecycle, phase_name) helper_test_add_thermal_profiles(lifecycle, phase_name, thermal_event_name) harmonic_vibe_event_name = helper_test_add_harmonic_event(lifecycle, phase_name) @@ -52,19 +52,19 @@ def helper_test_create_life_phase(lifecycle): lifecycle.create_life_phase("", "", 1, "sec", 1, "PER SEC", description="Test1") pytest.fail("No exception raised when using an invalid parameter") except SherlockCreateLifePhaseError as e: - assert e.str_itr()[0] == "Create life phase error: Project name is invalid." + assert str(e.str_itr()) == "['Create life phase error: Project name is invalid.']" try: lifecycle.create_life_phase("Test", "", 1, "sec", 1, "PER SEC", description="Test1") pytest.fail("No exception raised when using an invalid parameter") except SherlockCreateLifePhaseError as e: - assert e.str_itr()[0] == "Create life phase error: Phase name is invalid." + assert str(e.str_itr()) == "['Create life phase error: Phase name is invalid.']" try: lifecycle.create_life_phase("Test", "Example", 0, "sec", 1, "PER SEC", description="Test1") pytest.fail("No exception raised when using an invalid parameter") except SherlockCreateLifePhaseError as e: - assert e.str_itr()[0] == "Create life phase error: Duration must be greater than 0." + assert str(e.str_itr()) == "['Create life phase error: Duration must be greater than 0.']" if lifecycle._is_connection_up(): try: @@ -73,13 +73,16 @@ def helper_test_create_life_phase(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockCreateLifePhaseError as e: - assert e.str_itr()[0] == "Create life phase error: Cycle type is invalid." + assert str(e.str_itr()) == "['Create life phase error: Cycle type is invalid.']" try: lifecycle.create_life_phase("Test", "Example", 5, "sec", 0, "PER SEC", description="Test1") pytest.fail("No exception raised when using an invalid parameter") except SherlockCreateLifePhaseError as e: - assert e.str_itr()[0] == "Create life phase error: Number of cycles must be greater than 0." + assert ( + str(e.str_itr()) + == "['Create life phase error: Number of cycles must be greater than 0.']" + ) if lifecycle._is_connection_up(): phase_name = "Phase " + str(uuid.uuid4()) @@ -121,7 +124,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: - assert e.str_itr()[0] == "Add random vibe event error: Project name is invalid." + assert str(e.str_itr()) == "['Add random vibe event error: Project name is invalid.']" try: lifecycle.add_random_vibe_event( @@ -139,7 +142,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: - assert e.str_itr()[0] == "Add random vibe event error: Phase name is invalid." + assert str(e.str_itr()) == "['Add random vibe event error: Phase name is invalid.']" try: lifecycle.add_random_vibe_event( @@ -157,7 +160,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: - assert e.str_itr()[0] == "Add random vibe event error: Event name is invalid." + assert str(e.str_itr()) == "['Add random vibe event error: Event name is invalid.']" try: lifecycle.add_random_vibe_event( @@ -175,7 +178,9 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: - assert e.str_itr()[0] == "Add random vibe event error: Duration must be greater than 0." + assert ( + str(e.str_itr()) == "['Add random vibe event error: Duration must be greater than 0.']" + ) if lifecycle._is_connection_up(): try: @@ -194,7 +199,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: - assert e.str_itr()[0] == "Add random vibe event error: Cycle type is invalid." + assert str(e.str_itr()) == "['Add random vibe event error: Cycle type is invalid.']" try: lifecycle.add_random_vibe_event( @@ -213,8 +218,8 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: assert ( - e.str_itr()[0] == "Add random vibe event error: " - "Number of cycles must be greater than 0." + str(e.str_itr()) + == "['Add random vibe event error: Number of cycles must be greater than 0.']" ) try: @@ -233,7 +238,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: - assert e.str_itr()[0] == "Add random vibe event error: Elevation value is invalid." + assert str(e.str_itr()) == "['Add random vibe event error: Elevation value is invalid.']" try: lifecycle.add_random_vibe_event( @@ -252,11 +257,9 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: assert ( - e.str_itr()[0] - == "Add random vibe event error: At least one direction coordinate must be " - "non-zero." + str(e.str_itr()) == "['Add random vibe event error: " + "At least one direction coordinate must be non-zero.']" ) - try: lifecycle.add_random_vibe_event( "Test", @@ -274,8 +277,8 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeEventError as e: assert ( - e.str_itr()[0] == "Add random vibe event error: " - "Number of spherical coordinates is invalid." + str(e.str_itr()) + == "['Add random vibe event error: Number of spherical coordinates is invalid.']" ) if lifecycle._is_connection_up(): @@ -314,7 +317,7 @@ def helper_test_add_random_vibe_event(lifecycle, phase_name): return event_name -def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): +def helper_test_add_random_vibe_profiles(lifecycle, event_name, phase_name): """Test the add_random_vibe_profiles API""" try: @@ -333,7 +336,7 @@ def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeProfilesError as e: - assert e.str_itr()[0] == "Add random vibe profiles error: " "Project name is invalid." + assert str(e.str_itr()) == "['Add random vibe profiles error: " "Project name is invalid.']" try: lifecycle.add_random_vibe_profiles( @@ -352,8 +355,8 @@ def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeProfilesError as e: assert ( - e.str_itr()[0] == "Add random vibe profiles error: " - "Profile name is invalid for random vibe profile 0." + str(e.str_itr()) == "['Add random vibe profiles error: " + "Profile name is invalid for random vibe profile 0.']" ) try: @@ -373,10 +376,9 @@ def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeProfilesError as e: assert ( - e.str_itr()[0] == "Add random vibe profiles error: " + str(e.str_itr()) == "['Add random vibe profiles error: " "Invalid entry 0: " - "Number of elements is wrong for random vibe " - "profile 0." + "Number of elements is wrong for random vibe profile 0.']" ) try: @@ -396,9 +398,9 @@ def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeProfilesError as e: assert ( - e.str_itr()[0] == "Add random vibe profiles error:" + str(e.str_itr()) == "['Add random vibe profiles error:" " Invalid entry 1:" - " Frequency or amplitude is invalid for random vibe profile 0." + " Frequency or amplitude is invalid for random vibe profile 0.']" ) try: @@ -418,9 +420,9 @@ def helper_test_add_random_vibe_profile(lifecycle, event_name, phase_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddRandomVibeProfilesError as e: assert ( - e.str_itr()[0] == "Add random vibe profiles error:" + str(e.str_itr()) == "['Add random vibe profiles error:" " Invalid entry 2:" - " Frequencies must be greater than 0 for random vibe profile 0." + " Frequencies must be greater than 0 for random vibe profile 0.']" ) if lifecycle._is_connection_up(): @@ -475,7 +477,7 @@ def helper_test_add_thermal_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddThermalEventError as e: - assert e.str_itr()[0] == "Add thermal event error: Project name is invalid." + assert str(e.str_itr()) == "['Add thermal event error: Project name is invalid.']" try: lifecycle.add_thermal_event( @@ -488,7 +490,7 @@ def helper_test_add_thermal_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddThermalEventError as e: - assert e.str_itr()[0] == "Add thermal event error: Phase name is invalid." + assert str(e.str_itr()) == "['Add thermal event error: Phase name is invalid.']" try: lifecycle.add_thermal_event( @@ -501,7 +503,7 @@ def helper_test_add_thermal_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddThermalEventError as e: - assert e.str_itr()[0] == "Add thermal event error: Event name is invalid." + assert str(e.str_itr()) == "['Add thermal event error: Event name is invalid.']" try: lifecycle.add_thermal_event( @@ -514,7 +516,10 @@ def helper_test_add_thermal_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddThermalEventError as e: - assert e.str_itr()[0] == "Add thermal event error: Number of cycles must be greater than 0." + assert ( + str(e.str_itr()) == "['Add thermal event error: " + "Number of cycles must be greater than 0.']" + ) if lifecycle._is_connection_up(): event_name = "Thermal Event " + str(uuid.uuid4()) @@ -568,8 +573,8 @@ def helper_test_add_thermal_profiles(lifecycle, phase_name, event_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddThermalProfilesError as e: assert ( - e.str_itr()[0] - == "Add thermal profiles error: Profile name is invalid for thermal profile 0." + str(e.str_itr()) == "['Add thermal profiles error: " + "Profile name is invalid for thermal profile 0.']" ) try: @@ -593,8 +598,9 @@ def helper_test_add_thermal_profiles(lifecycle, phase_name, event_name): assert False except SherlockAddThermalProfilesError as e: assert ( - e.str_itr()[0] == "Add thermal profiles error: Invalid entry 0: " - "Number of elements is wrong for thermal profile 0." + str(e.str_itr()) == "['Add thermal profiles error: " + "Invalid entry 0: " + "Number of elements is wrong for thermal profile 0.']" ) try: @@ -618,8 +624,9 @@ def helper_test_add_thermal_profiles(lifecycle, phase_name, event_name): assert False except SherlockAddThermalProfilesError as e: assert ( - e.str_itr()[0] == "Add thermal profiles error: Invalid entry 1: " - "Step name is invalid for thermal profile 0." + str(e.str_itr()) == "['Add thermal profiles error: " + "Invalid entry 1: " + "Step name is invalid for thermal profile 0.']" ) try: @@ -643,8 +650,9 @@ def helper_test_add_thermal_profiles(lifecycle, phase_name, event_name): assert False except SherlockAddThermalProfilesError as e: assert ( - e.str_itr()[0] == "Add thermal profiles error: Invalid entry 2: " - "Step type is invalid for thermal profile 0." + str(e.str_itr()) == "['Add thermal profiles error: " + "Invalid entry 2: " + "Step type is invalid for thermal profile 0.']" ) try: @@ -668,8 +676,9 @@ def helper_test_add_thermal_profiles(lifecycle, phase_name, event_name): assert False except SherlockAddThermalProfilesError as e: assert ( - e.str_itr()[0] == "Add thermal profiles error: Invalid entry 1: " - "Time must be greater than 0 for thermal profile 0." + str(e.str_itr()) == "['Add thermal profiles error: " + "Invalid entry 1: " + "Time must be greater than 0 for thermal profile 0.']" ) try: @@ -693,8 +702,9 @@ def helper_test_add_thermal_profiles(lifecycle, phase_name, event_name): assert False except SherlockAddThermalProfilesError as e: assert ( - e.str_itr()[0] - == "Add thermal profiles error: Invalid entry 1: Time is invalid for thermal profile 0." + str(e.str_itr()) == "['Add thermal profiles error: " + "Invalid entry 1: " + "Time is invalid for thermal profile 0.']" ) try: @@ -718,9 +728,8 @@ def helper_test_add_thermal_profiles(lifecycle, phase_name, event_name): assert False except SherlockAddThermalProfilesError as e: assert ( - e.str_itr()[0] - == "Add thermal profiles error: Invalid entry 0: Temperature is invalid for thermal " - "profile 0." + str(e.str_itr()) == "['Add thermal profiles error: " + "Invalid entry 0: Temperature is invalid for thermal profile 0.']" ) if lifecycle._is_connection_up(): @@ -789,7 +798,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: - assert e.str_itr()[0] == "Add harmonic event error: Project name is invalid." + assert str(e.str_itr()) == "['Add harmonic event error: Project name is invalid.']" try: lifecycle.add_harmonic_event( @@ -807,7 +816,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: - assert e.str_itr()[0] == "Add harmonic event error: Phase name is invalid." + assert str(e.str_itr()) == "['Add harmonic event error: Phase name is invalid.']" try: lifecycle.add_harmonic_event( @@ -825,7 +834,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: - assert e.str_itr()[0] == "Add harmonic event error: Event name is invalid." + assert str(e.str_itr()) == "['Add harmonic event error: Event name is invalid.']" try: lifecycle.add_harmonic_event( @@ -843,7 +852,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: - assert e.str_itr()[0] == "Add harmonic event error: Duration must be greater than 0." + assert str(e.str_itr()) == "['Add harmonic event error: Duration must be greater than 0.']" if lifecycle._is_connection_up(): try: @@ -862,7 +871,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: - assert e.str_itr()[0] == "Add harmonic event error: Cycle type is invalid." + assert str(e.str_itr()) == "['Add harmonic event error: Cycle type is invalid.']" try: lifecycle.add_harmonic_event( @@ -880,7 +889,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: - assert e.str_itr()[0] == "Add harmonic event error: Profile type is invalid." + assert str(e.str_itr()) == "['Add harmonic event error: Profile type is invalid.']" try: lifecycle.add_harmonic_event( @@ -899,8 +908,8 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert ( - e.str_itr()[0] == "Add harmonic event error: Number of cycles must be " - "greater than 0." + str(e.str_itr()) == "['Add harmonic event error: " + "Number of cycles must be greater than 0.']" ) try: @@ -919,7 +928,10 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: - assert e.str_itr()[0] == "Add harmonic event error: Sweep rate must be greater than 0." + assert ( + str(e.str_itr()) == "['Add harmonic event error: " + "Sweep rate must be greater than 0.']" + ) try: lifecycle.add_harmonic_event( @@ -937,7 +949,7 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: - assert e.str_itr()[0] == "Add harmonic event error: Azimuth value is invalid." + assert str(e.str_itr()) == "['Add harmonic event error: Azimuth value is invalid.']" try: lifecycle.add_harmonic_event( @@ -956,8 +968,8 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert ( - e.str_itr()[0] - == "Add harmonic event error: At least one direction coordinate must be non-zero." + str(e.str_itr()) == "['Add harmonic event error: " + "At least one direction coordinate must be non-zero.']" ) try: @@ -977,8 +989,8 @@ def helper_test_add_harmonic_event(lifecycle, phase_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicEventError as e: assert ( - e.str_itr()[0] == "Add harmonic event error: Number of spherical coordinates " - "is invalid." + str(e.str_itr()) == "['Add harmonic event error: " + "Number of spherical coordinates is invalid.']" ) if lifecycle._is_connection_up(): event_name = "Harmonic Vibe Event " + str(uuid.uuid4()) @@ -1044,7 +1056,7 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: - assert e.str_itr()[0] == "Add harmonic vibe profiles error: Project name is invalid." + assert str(e.str_itr()) == "['Add harmonic vibe profiles error: Project name is invalid.']" try: lifecycle.add_harmonic_vibe_profiles( @@ -1067,8 +1079,8 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( - e.str_itr()[0] == "Add harmonic vibe profiles error:" - " Phase name is invalid for harmonic vibe profile 0." + str(e.str_itr()) == "['Add harmonic vibe profiles error:" + " Phase name is invalid for harmonic vibe profile 0.']" ) try: @@ -1092,8 +1104,8 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( - e.str_itr()[0] == "Add harmonic vibe profiles error:" - " Event name is invalid for harmonic vibe profile 0." + str(e.str_itr()) == "['Add harmonic vibe profiles error:" + " Event name is invalid for harmonic vibe profile 0.']" ) try: @@ -1117,8 +1129,8 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( - e.str_itr()[0] == "Add harmonic vibe profiles error:" - " Profile name is invalid for harmonic vibe profile 0." + str(e.str_itr()) == "['Add harmonic vibe profiles error:" + " Profile name is invalid for harmonic vibe profile 0.']" ) if lifecycle._is_connection_up(): @@ -1143,8 +1155,8 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( - e.str_itr()[0] == "Add harmonic vibe profiles error: " - "Load units InvalidLoadUnits are invalid for harmonic vibe profile 0." + str(e.str_itr()) == "['Add harmonic vibe profiles error: " + "Load units InvalidLoadUnits are invalid for harmonic vibe profile 0.']" ) try: @@ -1168,9 +1180,8 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( - e.str_itr()[0] == "Add harmonic vibe profiles error:" - " Invalid entry 0:" - " Number of elements is wrong for harmonic vibe profile 0." + str(e.str_itr()) == "['Add harmonic vibe profiles error:" + " Invalid entry 0: Number of elements is wrong for harmonic vibe profile 0.']" ) try: @@ -1194,9 +1205,8 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( - e.str_itr()[0] == "Add harmonic vibe profiles error: " - "Invalid entry 1: Frequency or load is invalid for " - "harmonic vibe profile 0." + str(e.str_itr()) == "['Add harmonic vibe profiles error: " + "Invalid entry 1: Frequency or load is invalid for harmonic vibe profile 0.']" ) try: @@ -1220,9 +1230,8 @@ def helper_test_add_harmonic_vibe_profile(lifecycle, phase_name, harmonic_vibe_e pytest.fail("No exception raised when using an invalid parameter") except SherlockAddHarmonicVibeProfilesError as e: assert ( - e.str_itr()[0] == "Add harmonic vibe profiles error:" - " Invalid entry 0:" - " Load must be greater than 0 for harmonic vibe profile 0." + str(e.str_itr()) == "['Add harmonic vibe profiles error:" + " Invalid entry 0: Load must be greater than 0 for harmonic vibe profile 0.']" ) if lifecycle._is_connection_up(): profile = str(uuid.uuid4()) @@ -1288,7 +1297,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: - assert e.str_itr()[0] == "Add shock event error: Project name is invalid." + assert str(e.str_itr()) == "['Add shock event error: Project name is invalid.']" try: lifecycle.add_shock_event( @@ -1304,7 +1313,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: - assert e.str_itr()[0] == "Add shock event error: Phase name is invalid." + assert str(e.str_itr()) == "['Add shock event error: Phase name is invalid.']" try: lifecycle.add_shock_event( @@ -1320,7 +1329,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: - assert e.str_itr()[0] == "Add shock event error: Event name is invalid." + assert str(e.str_itr()) == "['Add shock event error: Event name is invalid.']" try: lifecycle.add_shock_event( @@ -1336,7 +1345,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: - assert e.str_itr()[0] == "Add shock event error: Duration must be greater than 0." + assert str(e.str_itr()) == "['Add shock event error: Duration must be greater than 0.']" try: lifecycle.add_shock_event( @@ -1352,7 +1361,10 @@ def helper_test_add_shock_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: - assert e.str_itr()[0] == "Add shock event error: Number of cycles must be greater than 0." + assert ( + str(e.str_itr()) == "['Add shock event error: " + "Number of cycles must be greater than 0.']" + ) try: lifecycle.add_shock_event( @@ -1369,7 +1381,7 @@ def helper_test_add_shock_event(lifecycle, phase_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: - assert e.str_itr()[0] == "Add shock event error: Elevation value is invalid." + assert str(e.str_itr()) == "['Add shock event error: Elevation value is invalid.']" try: lifecycle.add_shock_event( @@ -1387,8 +1399,8 @@ def helper_test_add_shock_event(lifecycle, phase_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: assert ( - e.str_itr()[0] == "Add shock event error: At least one direction coordinate must be " - "non-zero." + str(e.str_itr()) == "['Add shock event error: " + "At least one direction coordinate must be non-zero.']" ) try: @@ -1407,8 +1419,8 @@ def helper_test_add_shock_event(lifecycle, phase_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockEventError as e: assert ( - e.str_itr()[0] == "Add shock event error: Number of spherical coordinates " - "is invalid." + str(e.str_itr()) == "['Add shock event error: " + "Number of spherical coordinates is invalid.']" ) if lifecycle._is_connection_up(): @@ -1471,7 +1483,7 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: - assert e.str_itr()[0] == "Add shock profiles error: Project name is invalid." + assert str(e.str_itr()) == "['Add shock profiles error: Project name is invalid.']" try: lifecycle.add_shock_profiles( @@ -1494,8 +1506,8 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( - e.str_itr()[0] == "Add shock profiles error: Phase name is invalid for " - "shock profile 0." + str(e.str_itr()) == "['Add shock profiles error: Phase name is invalid for " + "shock profile 0.']" ) try: @@ -1519,8 +1531,8 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( - e.str_itr()[0] == "Add shock profiles error: Event name is invalid for " - "shock profile 0." + str(e.str_itr()) == "['Add shock profiles error: Event name is invalid for " + "shock profile 0.']" ) try: @@ -1544,8 +1556,8 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( - e.str_itr()[0] == "Add shock profiles error:" - " Profile name is invalid for shock profile 0." + str(e.str_itr()) == "['Add shock profiles error:" + " Profile name is invalid for shock profile 0.']" ) try: @@ -1569,8 +1581,8 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( - e.str_itr()[0] == "Add shock profiles error:" - " Duration must be greater than 0 for shock profile 0." + str(e.str_itr()) == "['Add shock profiles error:" + " Duration must be greater than 0 for shock profile 0.']" ) try: @@ -1594,8 +1606,8 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( - e.str_itr()[0] == "Add shock profiles error:" - " Duration must be greater than 0 for shock profile 0." + str(e.str_itr()) == "['Add shock profiles error:" + " Duration must be greater than 0 for shock profile 0.']" ) try: @@ -1619,8 +1631,8 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( - e.str_itr()[0] == "Add shock profiles error:" - " Sample rate must be greater than 0 for shock profile 0." + str(e.str_itr()) == "['Add shock profiles error:" + " Sample rate must be greater than 0 for shock profile 0.']" ) try: @@ -1644,9 +1656,9 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( - e.str_itr()[0] == "Add shock profiles error:" + str(e.str_itr()) == "['Add shock profiles error:" " Invalid entry 0: Number of elements is wrong for shock" - " profile 0." + " profile 0.']" ) try: @@ -1670,9 +1682,9 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( - e.str_itr()[0] == "Add shock profiles error:" + str(e.str_itr()) == "['Add shock profiles error:" " Invalid entry 0: Load must be " - "greater than 0 for shock profile 0." + "greater than 0 for shock profile 0.']" ) try: @@ -1696,9 +1708,9 @@ def helper_test_add_shock_profile(lifecycle, phase_name, shock_event_name): pytest.fail("No exception raised when using an invalid parameter") except SherlockAddShockProfilesError as e: assert ( - e.str_itr()[0] == "Add shock profiles error:" + str(e.str_itr()) == "['Add shock profiles error:" " Invalid entry 0: Decay must be non-negative for " - "shock profile 0." + "shock profile 0.']" ) if lifecycle._is_connection_up(): @@ -1796,6 +1808,7 @@ def helper_test_load_random_vibe_profile(lifecycle): assert str(e.str_itr()) == "['Load random vibe profile error: File path is invalid.']" if lifecycle._is_connection_up(): + # happy path test missing because needs valid file try: lifecycle.load_random_vibe_profile( "Invalid Project", @@ -1805,7 +1818,7 @@ def helper_test_load_random_vibe_profile(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except Exception as e: - type(e) == SherlockLoadRandomVibeProfileError + assert type(e) == SherlockLoadRandomVibeProfileError def helper_test_load_harmonic_profile(lifecycle): @@ -1815,26 +1828,28 @@ def helper_test_load_harmonic_profile(lifecycle): lifecycle.load_harmonic_profile("", "Phase 1", "Harmonic Event", "Test_Profile.dat") pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadHarmonicProfileError as e: - assert str(e) == "Load Harmonic profile error: Project name is invalid." + assert str(e.str_itr()) == "['Load harmonic profile error: Project name is invalid.']" try: lifecycle.load_harmonic_profile("Test", "", "Harmonic Event", "Test_Profile.dat") pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadHarmonicProfileError as e: - assert str(e) == "Load Harmonic profile error: Phase name is invalid." + assert str(e.str_itr()) == "['Load harmonic profile error: Phase name is invalid.']" try: lifecycle.load_harmonic_profile("Test", "Phase 1", "", "Test_Profile.dat") pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadHarmonicProfileError as e: - assert str(e) == "Load Harmonic profile error: Event name is invalid." + assert str(e.str_itr()) == "['Load harmonic profile error: Event name is invalid.']" try: lifecycle.load_harmonic_profile("Test", "Phase 1", "Harmonic Event", "") pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadHarmonicProfileError as e: - assert str(e) == "Load Harmonic profile error: File name is invalid." + assert str(e.str_itr()) == "['Load harmonic profile error: File name is invalid.']" + if lifecycle._is_connection_up(): + # happy path test missing because needs valid file try: lifecycle.load_harmonic_profile( "Invalid Project", @@ -1859,7 +1874,7 @@ def helper_test_load_thermal_profile(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadThermalProfileError as e: - assert str(e) == "Load thermal profile error: Project name is invalid." + assert str(e.str_itr()) == "['Load thermal profile error: Project name is invalid.']" try: lifecycle.load_thermal_profile( @@ -1870,7 +1885,7 @@ def helper_test_load_thermal_profile(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadThermalProfileError as e: - assert str(e) == "Load thermal profile error: Phase name is invalid." + assert str(e.str_itr()) == "['Load thermal profile error: Phase name is invalid.']" try: lifecycle.load_thermal_profile( @@ -1881,7 +1896,7 @@ def helper_test_load_thermal_profile(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadThermalProfileError as e: - assert str(e) == "Load thermal profile error: Event name is invalid." + assert str(e.str_itr()) == "['Load thermal profile error: Event name is invalid.']" try: lifecycle.load_thermal_profile( @@ -1892,9 +1907,10 @@ def helper_test_load_thermal_profile(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadThermalProfileError as e: - assert str(e) == "Load thermal profile error: File path is invalid." + assert str(e.str_itr()) == "['Load thermal profile error: File path is invalid.']" if lifecycle._is_connection_up(): + # happy path test missing because needs valid file try: lifecycle.load_thermal_profile( "Test Project", @@ -1919,7 +1935,7 @@ def helper_test_load_shock_profile_dataset(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfileDatasetError as e: - assert str(e) == "Load shock profile dataset error: Project name is invalid." + assert str(e.str_itr()) == "['Load shock profile dataset error: Project name is invalid.']" try: lifecycle.load_shock_profile_dataset( @@ -1930,7 +1946,7 @@ def helper_test_load_shock_profile_dataset(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfileDatasetError as e: - assert str(e) == "Load shock profile dataset error: Phase name is invalid." + assert str(e.str_itr()) == "['Load shock profile dataset error: Phase name is invalid.']" try: lifecycle.load_shock_profile_dataset( @@ -1941,7 +1957,7 @@ def helper_test_load_shock_profile_dataset(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfileDatasetError as e: - assert str(e) == "Load shock profile dataset error: Event name is invalid." + assert str(e.str_itr()) == "['Load shock profile dataset error: Event name is invalid.']" try: lifecycle.load_shock_profile_dataset( @@ -1952,9 +1968,10 @@ def helper_test_load_shock_profile_dataset(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfileDatasetError as e: - assert str(e) == "Load shock profile dataset error: File path is invalid." + assert str(e.str_itr()) == "['Load shock profile dataset error: File path is invalid.']" if lifecycle._is_connection_up(): + # happy path test missing because needs valid file try: lifecycle.load_shock_profile_dataset( "Tutorial Project", @@ -1978,7 +1995,7 @@ def helper_test_load_shock_profile_pulses(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfilePulsesError as e: - assert str(e) == "Load shock profile pulses error: Project name is invalid." + assert str(e.str_itr()) == "['Load shock profile pulses error: Project name is invalid.']" try: lifecycle.load_shock_profile_pulses( @@ -1989,7 +2006,7 @@ def helper_test_load_shock_profile_pulses(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfilePulsesError as e: - assert str(e) == "Load shock profile pulses error: Phase name is invalid." + assert str(e.str_itr()) == "['Load shock profile pulses error: Phase name is invalid.']" try: lifecycle.load_shock_profile_pulses( @@ -2000,7 +2017,7 @@ def helper_test_load_shock_profile_pulses(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfilePulsesError as e: - assert str(e) == "Load shock profile pulses error: Event name is invalid." + assert str(e.str_itr()) == "['Load shock profile pulses error: Event name is invalid.']" try: lifecycle.load_shock_profile_pulses( @@ -2011,9 +2028,10 @@ def helper_test_load_shock_profile_pulses(lifecycle): ) pytest.fail("No exception raised when using an invalid parameter") except SherlockLoadShockProfilePulsesError as e: - assert str(e) == "Load shock profile pulses error: File path is invalid." + assert str(e.str_itr()) == "['Load shock profile pulses error: File path is invalid.']" if lifecycle._is_connection_up(): + # happy path test missing because needs valid file try: lifecycle.load_shock_profile_pulses( "Tutorial Project", diff --git a/tests/test_parts.py b/tests/test_parts.py index 729e109d0..900041430 100644 --- a/tests/test_parts.py +++ b/tests/test_parts.py @@ -78,7 +78,7 @@ def helper_test_update_parts_list(parts): ) 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." + assert str(e.str_itr()) == "['Update parts list error: Project name is invalid.']" try: parts.update_parts_list( @@ -90,7 +90,7 @@ def helper_test_update_parts_list(parts): ) 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." + assert str(e.str_itr()) == "['Update parts list error: CCA name is invalid.']" try: parts.update_parts_list( @@ -102,7 +102,7 @@ def helper_test_update_parts_list(parts): ) 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." + assert str(e.str_itr()) == "['Update parts list error: Parts library is invalid.']" def helper_test_update_parts_locations(parts): @@ -146,7 +146,7 @@ def helper_test_update_parts_locations(parts): ) 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." + assert str(e.str_itr()) == "['Update parts locations error: Project name is invalid.']" try: parts.update_parts_locations( @@ -159,21 +159,24 @@ def helper_test_update_parts_locations(parts): ) 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." + assert str(e.str_itr()) == "['Update parts locations error: CCA name is invalid.']" try: parts.update_parts_locations("Test", "Card", "Invalid") 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." + assert ( + str(e.str_itr()) == "['Update parts locations error: " + "Part location argument is invalid.']" + ) try: parts.update_parts_locations("Test", "Card", []) 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 " - "are missing." + str(e.str_itr()) == "['Update parts locations error: " + "Part location properties are missing.']" ) try: @@ -185,11 +188,11 @@ 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: Invalid part location 0: Number of fields is invalid." + str(e.str_itr()) == "['Update parts locations error: " + "Invalid part location 0: Number of fields is invalid.']" ) try: @@ -201,12 +204,11 @@ def helper_test_update_parts_locations(parts): ("", "-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: Invalid part location 1: Reference designator " - "is missing." + str(e.str_itr()) == "['Update parts locations error: " + "Invalid part location 1: Reference designator is missing.']" ) if parts._is_connection_up(): @@ -219,11 +221,11 @@ 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: " - "Invalid part location 0: Location units are invalid." + assert ( + str(e.str_itr()) == "['Update parts locations error: " + "Invalid part location 0: Location units are invalid.']" ) try: @@ -238,8 +240,8 @@ def helper_test_update_parts_locations(parts): pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePartsLocationsError as e: assert ( - e.str_itr()[0] - == "Update parts locations error: Invalid part location 0: Location units are missing." + str(e.str_itr()) == "['Update parts locations error: " + "Invalid part location 0: Location units are missing.']" ) try: @@ -251,11 +253,11 @@ 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: Invalid part location 0: " - "Location X coordinate is invalid." + assert ( + str(e.str_itr()) == "['Update parts locations error: " + "Invalid part location 0: Location X coordinate is invalid.']" ) try: @@ -267,11 +269,11 @@ def helper_test_update_parts_locations(parts): ("J1", "-3.55", "Invalid", "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: Invalid part location 1: " - "Location Y coordinate is invalid." + assert ( + str(e.str_itr()) == "['Update parts locations error: " + "Invalid part location 1: Location Y coordinate is invalid.']" ) try: @@ -283,11 +285,11 @@ def helper_test_update_parts_locations(parts): ("J1", "", "-2.220446049250313E-16", "90", "", "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: Invalid part location 1: Location units are missing." + str(e.str_itr()) == "['Update parts locations error: " + "Invalid part location 1: Location units are missing.']" ) try: @@ -299,11 +301,11 @@ 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: Invalid part location 0: " - "Location rotation is invalid." + assert ( + str(e.str_itr()) == "['Update parts locations error: " + "Invalid part location 0: Location rotation is invalid.']" ) try: @@ -315,11 +317,11 @@ def helper_test_update_parts_locations(parts): ("J1", "-3.55", "-2.220446049250313E-16", "400", "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: Invalid part location 1: " - "Location rotation is invalid." + assert ( + str(e.str_itr()) == "['Update parts locations error: " + "Invalid part location 1: Location rotation is invalid.']" ) if parts._is_connection_up(): @@ -332,11 +334,11 @@ 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: Invalid part location 0: " - "Location board side is invalid." + assert ( + str(e.str_itr()) == "['Update parts locations error: " + "Invalid part location 0: Location board side is invalid.']" ) try: @@ -348,11 +350,11 @@ 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: Invalid part location 0: " - "Location mirrored is invalid." + assert ( + str(e.str_itr()) == "['Update parts locations error: " + "Invalid part location 0: Location mirrored is invalid.']" ) @@ -377,9 +379,11 @@ def helper_test_update_parts_locations_by_file(parts): "Card", "Parts Locations.csv", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePartsLocationsByFileError as e: - assert e.str_itr()[0] == "Update parts locations by file error: Project name is invalid." + assert ( + str(e.str_itr()) == "['Update parts locations by file error: Project name is invalid.']" + ) try: parts.update_parts_locations_by_file( @@ -387,9 +391,9 @@ def helper_test_update_parts_locations_by_file(parts): "", "Parts Locations.csv", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdatePartsLocationsByFileError as e: - assert e.str_itr()[0] == "Update parts locations by file error: CCA name is invalid." + assert str(e.str_itr()) == "['Update parts locations by file error: CCA name is invalid.']" def helper_test_import_parts_list(parts): @@ -414,7 +418,7 @@ def helper_test_import_parts_list(parts): "Parts List.csv", True, ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockImportPartsListError as e: assert str(e) == "Import parts list error: Project name is invalid." @@ -425,7 +429,7 @@ def helper_test_import_parts_list(parts): "Parts List.csv", True, ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockImportPartsListError as e: assert str(e) == "Import parts list error: CCA name is invalid." diff --git a/tests/test_project.py b/tests/test_project.py index 0cd65fe30..aeb739e98 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -4,6 +4,7 @@ import platform import grpc +import pytest from ansys.sherlock.core.errors import ( SherlockAddStrainMapsError, @@ -36,7 +37,7 @@ def helper_test_delete_project(project): """Test delete_project API""" try: project.delete_project("") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockDeleteProjectError as e: assert str(e) == "Delete project error: Project name is blank. Specify a project name." @@ -44,7 +45,7 @@ def helper_test_delete_project(project): try: missing_project_name = "Name of project that should not exist" project.delete_project(missing_project_name) - assert False + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockDeleteProjectError @@ -53,7 +54,7 @@ def helper_test_import_odb_archive(project): """Test import_odb_archive API""" try: project.import_odb_archive("", True, True, True, True) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockImportODBError as e: assert str(e) == "Import ODB error: Archive path is required." @@ -61,7 +62,7 @@ def helper_test_import_odb_archive(project): try: missing_archive_file = "Missing ODB.tgz" project.import_odb_archive(missing_archive_file, True, True, True, True) - assert False + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockImportODBError @@ -70,14 +71,14 @@ def helper_test_import_ipc2581_archive(project): """Test import_ipc2581_archive API""" try: project.import_ipc2581_archive("", True, True) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockImportIpc2581Error as e: assert str(e) == "Import IPC2581 error: Archive file path is required." if project._is_connection_up(): try: project.import_ipc2581_archive("Missing Archive File.zip", True, True) - assert False + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockImportIpc2581Error @@ -86,25 +87,25 @@ def helper_test_generate_project_report(project): """Test generate_project_report API.""" try: project.generate_project_report("", "John Doe", "Generic Co.", "C:/report.pdf") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenerateProjectReportError as e: assert str(e) == "Generate project report error: Project name is invalid." try: project.generate_project_report("Test", "", "Generic Co.", "C:/report.pdf") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenerateProjectReportError as e: assert str(e) == "Generate project report error: Author name is invalid." try: project.generate_project_report("Test", "John Doe", "", "C:/report.pdf") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenerateProjectReportError as e: assert str(e) == "Generate project report error: Company name is invalid." try: project.generate_project_report("Test", "John Doe", "Generic Co.", "") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenerateProjectReportError as e: assert str(e) == "Generate project report error: Report path is required." @@ -126,7 +127,7 @@ def helper_test_generate_project_report(project): report_file = "invalid/invalid" try: project.generate_project_report("Test", "John Doe", "Generic Co.", report_file) - assert False + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockGenerateProjectReportError @@ -136,35 +137,38 @@ def helper_test_list_ccas(project): try: project.list_ccas("") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockListCCAsError as e: - assert e.str_itr()[0] == "List CCAs error: Project name is invalid." + assert str(e.str_itr()) == "['List CCAs error: Project name is invalid.']" try: project.list_ccas("Tutorial Project", "CCA names that is not a list") assert False except SherlockListCCAsError as e: - assert e.str_itr()[0] == "List CCAs error: cca_names is not a list." + assert str(e.str_itr()) == "['List CCAs error: cca_names is not a list.']" if project._is_connection_up(): - ccas = project.list_ccas("AssemblyTutorial") - assert len(ccas) == 4 - assert ccas[0].ccaName == "Main Board" - assert ccas[1].ccaName == "Memory Card 1" - assert ccas[2].ccaName == "Memory Card 2" - assert ccas[3].ccaName == "Power Module" - - cca_names = ["Memory Card 2"] - ccas = project.list_ccas("AssemblyTutorial", cca_names) - assert len(ccas) == 1 - assert ccas[0].ccaName == "Memory Card 2" - try: project.list_ccas("Project that doesn't exist") - assert False + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockListCCAsError + try: + ccas = project.list_ccas("AssemblyTutorial") + assert len(ccas) == 4 + assert ccas[0].ccaName == "Main Board" + assert ccas[1].ccaName == "Memory Card 1" + assert ccas[2].ccaName == "Memory Card 2" + assert ccas[3].ccaName == "Power Module" + + cca_names = ["Memory Card 2"] + ccas = project.list_ccas("AssemblyTutorial", cca_names) + assert len(ccas) == 1 + assert ccas[0].ccaName == "Memory Card 2" + except SherlockListCCAsError as e: + pytest.fail(str(e.str_itr())) + def helper_test_add_strain_maps(project): """Test add_strain_maps API""" @@ -184,9 +188,9 @@ def helper_test_add_strain_maps(project): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: - assert e.str_itr()[0] == "Add strain maps error: Project name is invalid." + assert str(e.str_itr()) == "['Add strain maps error: Project name is invalid.']" try: project.add_strain_maps( @@ -203,9 +207,9 @@ def helper_test_add_strain_maps(project): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: - assert e.str_itr()[0] == "Add strain maps error: Path is required for strain map 0." + assert str(e.str_itr()) == "['Add strain maps error: Path is required for strain map 0.']" try: project.add_strain_maps( @@ -222,11 +226,11 @@ def helper_test_add_strain_maps(project): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - e.str_itr()[0] == "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: @@ -244,12 +248,11 @@ def helper_test_add_strain_maps(project): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - e.str_itr()[0] == "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: @@ -267,11 +270,11 @@ def helper_test_add_strain_maps(project): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - e.str_itr()[0] == "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: @@ -289,11 +292,11 @@ def helper_test_add_strain_maps(project): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - e.str_itr()[0] == "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: @@ -311,11 +314,11 @@ def helper_test_add_strain_maps(project): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - e.str_itr()[0] == "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: @@ -333,11 +336,11 @@ def helper_test_add_strain_maps(project): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: assert ( - e.str_itr()[0] == '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: @@ -356,26 +359,15 @@ def helper_test_add_strain_maps(project): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockAddStrainMapsError as e: - assert e.str_itr()[0] == "Add strain maps error: cca_names is not a list for strain map 0." + assert ( + str(e.str_itr()) == "['Add strain maps error: " + "cca_names is not a list for strain map 0.']" + ) if project._is_connection_up(): - # project.add_strain_maps( - # "Tutorial Project", - # [ - # ( - # "C:/Users/pwalters/Source/Sherlock/dist/tutorial/StrainMaps/StrainMap.csv", - # "File comment", - # 0, - # "SolidID", - # "PCB Strain", - # "µε", - # ["Main Board"], - # ) - # ], - # ) - + # happy path test missing because needs valid file try: strain_map = "Missing strain map.csv" project.add_strain_maps( @@ -392,7 +384,7 @@ def helper_test_add_strain_maps(project): ) ], ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockAddStrainMapsError @@ -402,41 +394,46 @@ def helper_test_list_strain_maps(project): try: project.list_strain_maps("") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockListStrainMapsError as e: - assert e.str_itr()[0] == "List strain maps error: Project name is invalid." + assert str(e.str_itr()) == "['List strain maps error: Project name is invalid.']" try: project.list_strain_maps("Tutorial Project", "Not a list") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockListStrainMapsError as e: - assert e.str_itr()[0] == "List strain maps error: cca_names is not a list." + assert str(e.str_itr()) == "['List strain maps error: cca_names is not a list.']" if project._is_connection_up(): - strain_maps = project.list_strain_maps("AssemblyTutorial", ["Main Board", "Power Module"]) - assert len(strain_maps) == 2 - strain_map = strain_maps[0] - assert strain_map.ccaName == "Main Board" - assert len(strain_map.strainMaps) == 4 - assert "MainBoardStrainBot.png" in strain_map.strainMaps - assert "MainBoardStrainTop.png" in strain_map.strainMaps - assert "MainBoardStrain - Bottom" in strain_map.strainMaps - assert "MainBoardStrain - Top" in strain_map.strainMaps - - strain_map = strain_maps[1] - assert strain_map.ccaName == "Power Module" - assert len(strain_map.strainMaps) == 4 - assert "PowerModuleStrainBot.png" in strain_map.strainMaps - assert "PowerModuleStrainTop.png" in strain_map.strainMaps - assert "PowerModuleStrain - Bottom" in strain_map.strainMaps - assert "PowerModuleStrain - Top" in strain_map.strainMaps - try: project.list_strain_maps("AssemblyTutorial", ["CCA name that doesn't exist"]) - assert False + pytest.fail("No exception raised when using an invalid parameter") except Exception as e: assert type(e) == SherlockListStrainMapsError + try: + strain_maps = project.list_strain_maps( + "AssemblyTutorial", ["Main Board", "Power Module"] + ) + assert len(strain_maps) == 2 + strain_map = strain_maps[0] + assert strain_map.ccaName == "Main Board" + assert len(strain_map.strainMaps) == 4 + assert "MainBoardStrainBot.png" in strain_map.strainMaps + assert "MainBoardStrainTop.png" in strain_map.strainMaps + assert "MainBoardStrain - Bottom" in strain_map.strainMaps + assert "MainBoardStrain - Top" in strain_map.strainMaps + + strain_map = strain_maps[1] + assert strain_map.ccaName == "Power Module" + assert len(strain_map.strainMaps) == 4 + assert "PowerModuleStrainBot.png" in strain_map.strainMaps + assert "PowerModuleStrainTop.png" in strain_map.strainMaps + assert "PowerModuleStrain - Bottom" in strain_map.strainMaps + assert "PowerModuleStrain - Top" in strain_map.strainMaps + except SherlockListStrainMapsError as e: + pytest.fail(str(e.str_itr())) + if __name__ == "__main__": test_all() diff --git a/tests/test_stackup.py b/tests/test_stackup.py index c5000577a..874f40f8c 100644 --- a/tests/test_stackup.py +++ b/tests/test_stackup.py @@ -1,6 +1,7 @@ # Copyright (c) 2023 ANSYS, Inc. and/or its affiliates. import grpc +import pytest from ansys.sherlock.core.errors import ( SherlockGenStackupError, @@ -50,7 +51,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Project name is invalid." @@ -72,7 +73,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: CCA name is invalid." @@ -94,7 +95,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Board thickness is invalid." @@ -116,7 +117,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert ( str(e) == "Generate stackup error: Number of conductor layers must be greater than 1." @@ -140,7 +141,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Conductor thickness is invalid." @@ -162,7 +163,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Laminate thickness is invalid." @@ -184,7 +185,7 @@ def helper_test_gen_stackup(stackup): -1, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Power thickness is invalid." @@ -207,7 +208,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Board thickness units are invalid." @@ -229,7 +230,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Laminate manufacturer is invalid." @@ -251,7 +252,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Laminate grade is invalid." @@ -273,7 +274,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Laminate material is invalid." @@ -295,7 +296,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Laminate material is invalid." @@ -317,7 +318,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Conductor thickness units are invalid." @@ -339,7 +340,7 @@ def helper_test_gen_stackup(stackup): 1.0, "mil", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Laminate thickness units are invalid." @@ -361,7 +362,7 @@ def helper_test_gen_stackup(stackup): 1.0, "Invalid", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGenStackupError as e: assert str(e) == "Generate stackup error: Power thickness units are invalid." @@ -380,7 +381,7 @@ def helper_test_update_conductor_layer(stackup): "94.2", "Generic FR-4 Generic FR-4", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateConductorLayerError as e: assert str(e) == "Update conductor layer error: Project name is invalid." @@ -396,7 +397,7 @@ def helper_test_update_conductor_layer(stackup): "94.2", "Generic FR-4 Generic FR-4", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateConductorLayerError as e: assert str(e) == "Update conductor layer error: CCA name is invalid." @@ -412,7 +413,7 @@ def helper_test_update_conductor_layer(stackup): "94.2", "Generic FR-4 Generic FR-4", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateConductorLayerError as e: assert str(e) == "Update conductor layer error: Layer ID conductor is missing." @@ -428,10 +429,10 @@ def helper_test_update_conductor_layer(stackup): "94.2", "Generic FR-4 Generic FR-4", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateConductorLayerError as e: - assert str(e) == ( - "Update conductor layer error: " + assert ( + str(e) == "Update conductor layer error: " "Layer ID is invalid. It must be an integer greater than 0." ) @@ -447,7 +448,7 @@ def helper_test_update_conductor_layer(stackup): "94.2", "Generic FR-4 Generic FR-4", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateConductorLayerError as e: assert ( str(e) == "Update conductor layer error: Layer ID is invalid. " @@ -466,10 +467,10 @@ def helper_test_update_conductor_layer(stackup): "94.2", "Generic FR-4 Generic FR-4", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateConductorLayerError as e: - assert str(e) == ( - "Update conductor layer error: " + assert ( + str(e) == "Update conductor layer error: " 'Conductor type is invalid. Options are "SIGNAL", "POWER", and "SUBSTRATE".' ) @@ -486,7 +487,7 @@ def helper_test_update_conductor_layer(stackup): "94.2", "Generic FR-4 Generic FR-4", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateConductorLayerError as e: assert str(e) == "Update conductor layer error: Conductor material is invalid." @@ -502,7 +503,7 @@ def helper_test_update_conductor_layer(stackup): "94.2", "Generic FR-4 Generic FR-4", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateConductorLayerError as e: assert str(e) == "Update conductor layer error: Conductor thickness is invalid." @@ -519,7 +520,7 @@ def helper_test_update_conductor_layer(stackup): "94.2", "Generic FR-4 Generic FR-4", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateConductorLayerError as e: assert str(e) == "Update conductor layer error: Conductor thickness units are invalid." @@ -535,10 +536,10 @@ def helper_test_update_conductor_layer(stackup): "105", "Generic FR-4 Generic FR-4", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateConductorLayerError as e: - assert str(e) == ( - "Update conductor layer error: " + assert ( + str(e) == "Update conductor layer error: " "Conductor percent is invalid. It must be between 0 and 100." ) @@ -554,11 +555,11 @@ def helper_test_update_conductor_layer(stackup): "Invalid", "Generic FR-4 Generic FR-4", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateConductorLayerError as e: assert ( - str(e) == "Update conductor layer error: Conductor percent is invalid. " - "It must be between 0 and 100." + str(e) == "Update conductor layer error: " + "Conductor percent is invalid. It must be between 0 and 100." ) @@ -581,7 +582,7 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == "Update laminate layer error: Project name is invalid." @@ -601,7 +602,7 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == "Update laminate layer error: CCA name is invalid." @@ -621,7 +622,7 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == "Update laminate layer error: Layer ID laminate is missing." @@ -641,10 +642,10 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: - assert str(e) == ( - "Update laminate layer error: Layer ID is invalid. " + assert ( + str(e) == "Update laminate layer error: Layer ID is invalid. " "It must be an integer greater than 0." ) @@ -664,7 +665,7 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert ( str(e) == "Update laminate layer error: Layer ID is invalid. " @@ -688,7 +689,7 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == "Update laminate layer error: Laminate manufacturer is invalid." @@ -709,7 +710,7 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == "Update laminate layer error: Laminate grade is invalid." @@ -730,7 +731,7 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == "Update laminate layer error: Laminate material is invalid." @@ -750,7 +751,7 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == "Update laminate layer error: Laminate thickness is invalid." @@ -771,7 +772,7 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == "Update laminate layer error: Laminate thickness units are invalid." @@ -791,7 +792,7 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == "Update laminate layer error: glass_construction argument is invalid." @@ -811,11 +812,11 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert ( - str(e) == "Update laminate layer error: Invalid layer 0: Number of elements " - "is wrong." + str(e) == "Update laminate layer error: " + "Invalid layer 0: Number of elements is wrong." ) try: @@ -834,7 +835,7 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == "Update laminate layer error: Invalid layer 0: Thickness is invalid." @@ -855,11 +856,11 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert ( - str(e) - == "Update laminate layer error: Invalid layer 0: Thickness units are invalid." + str(e) == "Update laminate layer error: " + "Invalid layer 0: Thickness units are invalid." ) if stackup._is_connection_up(): @@ -879,7 +880,7 @@ def helper_test_update_laminate_layer(stackup): "COPPER", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == "Update laminate layer error: Fiber material is invalid." @@ -900,7 +901,7 @@ def helper_test_update_laminate_layer(stackup): "Invalid", "0.0", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == "Update laminate layer error: Conductor material is invalid." @@ -920,11 +921,11 @@ def helper_test_update_laminate_layer(stackup): "", "101", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockUpdateLaminateLayerError as e: assert str(e) == ( - "Update laminate layer error: Conductor percent is invalid." - " It must be between 0 and 100." + "Update laminate layer error: " + "Conductor percent is invalid. It must be between 0 and 100." ) @@ -932,7 +933,7 @@ def helper_test_list_conductor_layers(stackup): """Test list_conductor_layers API""" try: stackup.list_conductor_layers("") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockListConductorLayersError as e: assert str(e) == "List conductor layer error: Project name is invalid." @@ -941,7 +942,7 @@ def helper_test_list_laminate_layers(stackup): """Test list_laminate_layers API""" try: stackup.list_laminate_layers("") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockListLaminateLayersError as e: assert str(e) == "List laminate layer error: Project name is invalid." @@ -953,7 +954,7 @@ def helper_test_get_stackup_props(stackup): "", "Card", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetStackupPropsError as e: assert str(e) == "Get stackup prop error: Project name is invalid." try: @@ -961,7 +962,7 @@ def helper_test_get_stackup_props(stackup): "Test", "", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetStackupPropsError as e: assert str(e) == "Get stackup prop error: CCA name is invalid." @@ -970,13 +971,13 @@ def helper_test_get_layer_count(stackup): """Test get_layer_count API""" try: stackup.get_layer_count(project="", cca_name="Card") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetLayerCountError as e: assert str(e) == "Get layer count error: Project name is invalid." try: stackup.get_layer_count(project="Test", cca_name="") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetLayerCountError as e: assert str(e) == "Get layer count error: CCA name is invalid." @@ -986,7 +987,7 @@ def helper_test_get_layer_count(stackup): "", "Card", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetLayerCountError as e: assert str(e) == "Get layer count error: Project name is invalid." @@ -995,7 +996,7 @@ def helper_test_get_layer_count(stackup): "Test", "", ) - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetLayerCountError as e: assert str(e) == "Get layer count error: CCA name is invalid." @@ -1003,19 +1004,19 @@ def helper_test_get_layer_count(stackup): def helper_test_get_total_conductor_thickness(stackup): try: stackup.get_total_conductor_thickness(project="", cca_name="Card", thickness_unit="oz") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetTotalConductorThicknessError as e: assert str(e) == "Get total conductor thickness error: Invalid project name" try: stackup.get_total_conductor_thickness(project="Test", cca_name="", thickness_unit="oz") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetTotalConductorThicknessError as e: assert str(e) == "Get total conductor thickness error: Invalid CCA name" try: stackup.get_total_conductor_thickness(project="Test", cca_name="Card", thickness_unit="") - assert False + pytest.fail("No exception raised when using an invalid parameter") except SherlockGetTotalConductorThicknessError as e: assert str(e) == "Get total conductor thickness error: Invalid thickness unit"