diff --git a/build/templates/_library_interpreter.py/_get_error_description.py.mako b/build/templates/_library_interpreter.py/_get_error_description.py.mako index b2d68496be..e937fb304e 100644 --- a/build/templates/_library_interpreter.py/_get_error_description.py.mako +++ b/build/templates/_library_interpreter.py/_get_error_description.py.mako @@ -20,12 +20,22 @@ pass % if 'error_message' in config['functions']: + try: + ''' + It is possible that the session is valid but the returned_error_code unequal to error_code + ''' + error_string = self.error_message(error_code) + return error_string + except errors.Error: + pass + try: ''' It is expected for get_error to raise when the session is invalid (IVI spec requires GetError to fail). Use error_message instead. It doesn't require a session. ''' + self.set_session_handle() error_string = self.error_message(error_code) return error_string except errors.Error: diff --git a/generated/nidcpower/nidcpower/_library_interpreter.py b/generated/nidcpower/nidcpower/_library_interpreter.py index 473680f188..7ce7ae3913 100644 --- a/generated/nidcpower/nidcpower/_library_interpreter.py +++ b/generated/nidcpower/nidcpower/_library_interpreter.py @@ -103,12 +103,22 @@ def get_error_description(self, error_code): except errors.Error: pass + try: + ''' + It is possible that the session is valid but the returned_error_code unequal to error_code + ''' + error_string = self.error_message(error_code) + return error_string + except errors.Error: + pass + try: ''' It is expected for get_error to raise when the session is invalid (IVI spec requires GetError to fail). Use error_message instead. It doesn't require a session. ''' + self.set_session_handle() error_string = self.error_message(error_code) return error_string except errors.Error: diff --git a/generated/nidigital/nidigital/_library_interpreter.py b/generated/nidigital/nidigital/_library_interpreter.py index e830756ab8..a97018732e 100644 --- a/generated/nidigital/nidigital/_library_interpreter.py +++ b/generated/nidigital/nidigital/_library_interpreter.py @@ -101,12 +101,22 @@ def get_error_description(self, error_code): except errors.Error: pass + try: + ''' + It is possible that the session is valid but the returned_error_code unequal to error_code + ''' + error_string = self.error_message(error_code) + return error_string + except errors.Error: + pass + try: ''' It is expected for get_error to raise when the session is invalid (IVI spec requires GetError to fail). Use error_message instead. It doesn't require a session. ''' + self.set_session_handle() error_string = self.error_message(error_code) return error_string except errors.Error: diff --git a/generated/nidmm/nidmm/_library_interpreter.py b/generated/nidmm/nidmm/_library_interpreter.py index 4e87b4274b..76e5c6475f 100644 --- a/generated/nidmm/nidmm/_library_interpreter.py +++ b/generated/nidmm/nidmm/_library_interpreter.py @@ -99,12 +99,22 @@ def get_error_description(self, error_code): except errors.Error: pass + try: + ''' + It is possible that the session is valid but the returned_error_code unequal to error_code + ''' + error_string = self.error_message(error_code) + return error_string + except errors.Error: + pass + try: ''' It is expected for get_error to raise when the session is invalid (IVI spec requires GetError to fail). Use error_message instead. It doesn't require a session. ''' + self.set_session_handle() error_string = self.error_message(error_code) return error_string except errors.Error: diff --git a/generated/nifake/nifake/_library_interpreter.py b/generated/nifake/nifake/_library_interpreter.py index 45ca3ef39a..a6e0291145 100644 --- a/generated/nifake/nifake/_library_interpreter.py +++ b/generated/nifake/nifake/_library_interpreter.py @@ -115,12 +115,22 @@ def get_error_description(self, error_code): except errors.Error: pass + try: + ''' + It is possible that the session is valid but the returned_error_code unequal to error_code + ''' + error_string = self.error_message(error_code) + return error_string + except errors.Error: + pass + try: ''' It is expected for get_error to raise when the session is invalid (IVI spec requires GetError to fail). Use error_message instead. It doesn't require a session. ''' + self.set_session_handle() error_string = self.error_message(error_code) return error_string except errors.Error: diff --git a/generated/nifake/nifake/unit_tests/test_library_interpreter.py b/generated/nifake/nifake/unit_tests/test_library_interpreter.py index 6bcc6ebc55..8a7c5f8e02 100644 --- a/generated/nifake/nifake/unit_tests/test_library_interpreter.py +++ b/generated/nifake/nifake/unit_tests/test_library_interpreter.py @@ -716,6 +716,36 @@ def test_get_error_description_error_message_error(self): assert e.description == test_error_desc self.patched_library.niFake_error_message.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViInt32Matcher(test_error_code), _matchers.ViCharBufferMatcher(256)) + def test_get_error_description_error_message_after_session_reset(self): + test_error_code = -42 + test_error_desc = "The answer to the ultimate question" + self.patched_library.niFake_PoorlyNamedSimpleFunction.side_effect = self.side_effects_helper.niFake_PoorlyNamedSimpleFunction + self.side_effects_helper['PoorlyNamedSimpleFunction']['return'] = test_error_code + self.patched_library.niFake_GetError.side_effect = self.side_effects_helper.niFake_GetError + self.side_effects_helper['GetError']['errorCode'] = -1 + self.side_effects_helper['GetError']['description'] = "Shouldn't get this" + self.side_effects_helper['GetError']['return'] = -2 + self.side_effects_helper['error_message']['errorMessage'] = test_error_desc + + def error_message_side_effect(vi, error_code, error_message_buf): + if vi.value == SESSION_NUM_FOR_TEST: + return -3 + return self.side_effects_helper.niFake_error_message(vi, error_code, error_message_buf) + + self.patched_library.niFake_error_message.side_effect = error_message_side_effect + interpreter = self.get_initialized_library_interpreter() + try: + interpreter.simple_function() + assert False + except nifake.Error as e: + assert e.code == test_error_code + assert e.description == test_error_desc + assert self.patched_library.niFake_error_message.call_count == 2 + self.patched_library.niFake_error_message.assert_has_calls([ + call(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViInt32Matcher(test_error_code), _matchers.ViCharBufferMatcher(256)), + call(_matchers.ViSessionMatcher(0), _matchers.ViInt32Matcher(test_error_code), _matchers.ViCharBufferMatcher(256)), + ]) + # Custom types def test_set_custom_type(self): diff --git a/generated/nifgen/nifgen/_library_interpreter.py b/generated/nifgen/nifgen/_library_interpreter.py index 6370353a26..7c32eb64e6 100644 --- a/generated/nifgen/nifgen/_library_interpreter.py +++ b/generated/nifgen/nifgen/_library_interpreter.py @@ -99,12 +99,22 @@ def get_error_description(self, error_code): except errors.Error: pass + try: + ''' + It is possible that the session is valid but the returned_error_code unequal to error_code + ''' + error_string = self.error_message(error_code) + return error_string + except errors.Error: + pass + try: ''' It is expected for get_error to raise when the session is invalid (IVI spec requires GetError to fail). Use error_message instead. It doesn't require a session. ''' + self.set_session_handle() error_string = self.error_message(error_code) return error_string except errors.Error: diff --git a/generated/niscope/niscope/_library_interpreter.py b/generated/niscope/niscope/_library_interpreter.py index 1cb9a7d26a..8427d4ac5c 100644 --- a/generated/niscope/niscope/_library_interpreter.py +++ b/generated/niscope/niscope/_library_interpreter.py @@ -103,12 +103,22 @@ def get_error_description(self, error_code): except errors.Error: pass + try: + ''' + It is possible that the session is valid but the returned_error_code unequal to error_code + ''' + error_string = self.error_message(error_code) + return error_string + except errors.Error: + pass + try: ''' It is expected for get_error to raise when the session is invalid (IVI spec requires GetError to fail). Use error_message instead. It doesn't require a session. ''' + self.set_session_handle() error_string = self.error_message(error_code) return error_string except errors.Error: diff --git a/generated/niswitch/niswitch/_library_interpreter.py b/generated/niswitch/niswitch/_library_interpreter.py index 4d7dc8ea7c..daf3ed06e2 100644 --- a/generated/niswitch/niswitch/_library_interpreter.py +++ b/generated/niswitch/niswitch/_library_interpreter.py @@ -99,12 +99,22 @@ def get_error_description(self, error_code): except errors.Error: pass + try: + ''' + It is possible that the session is valid but the returned_error_code unequal to error_code + ''' + error_string = self.error_message(error_code) + return error_string + except errors.Error: + pass + try: ''' It is expected for get_error to raise when the session is invalid (IVI spec requires GetError to fail). Use error_message instead. It doesn't require a session. ''' + self.set_session_handle() error_string = self.error_message(error_code) return error_string except errors.Error: diff --git a/src/nifake/unit_tests/test_library_interpreter.py b/src/nifake/unit_tests/test_library_interpreter.py index 6bcc6ebc55..8a7c5f8e02 100644 --- a/src/nifake/unit_tests/test_library_interpreter.py +++ b/src/nifake/unit_tests/test_library_interpreter.py @@ -716,6 +716,36 @@ def test_get_error_description_error_message_error(self): assert e.description == test_error_desc self.patched_library.niFake_error_message.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViInt32Matcher(test_error_code), _matchers.ViCharBufferMatcher(256)) + def test_get_error_description_error_message_after_session_reset(self): + test_error_code = -42 + test_error_desc = "The answer to the ultimate question" + self.patched_library.niFake_PoorlyNamedSimpleFunction.side_effect = self.side_effects_helper.niFake_PoorlyNamedSimpleFunction + self.side_effects_helper['PoorlyNamedSimpleFunction']['return'] = test_error_code + self.patched_library.niFake_GetError.side_effect = self.side_effects_helper.niFake_GetError + self.side_effects_helper['GetError']['errorCode'] = -1 + self.side_effects_helper['GetError']['description'] = "Shouldn't get this" + self.side_effects_helper['GetError']['return'] = -2 + self.side_effects_helper['error_message']['errorMessage'] = test_error_desc + + def error_message_side_effect(vi, error_code, error_message_buf): + if vi.value == SESSION_NUM_FOR_TEST: + return -3 + return self.side_effects_helper.niFake_error_message(vi, error_code, error_message_buf) + + self.patched_library.niFake_error_message.side_effect = error_message_side_effect + interpreter = self.get_initialized_library_interpreter() + try: + interpreter.simple_function() + assert False + except nifake.Error as e: + assert e.code == test_error_code + assert e.description == test_error_desc + assert self.patched_library.niFake_error_message.call_count == 2 + self.patched_library.niFake_error_message.assert_has_calls([ + call(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViInt32Matcher(test_error_code), _matchers.ViCharBufferMatcher(256)), + call(_matchers.ViSessionMatcher(0), _matchers.ViInt32Matcher(test_error_code), _matchers.ViCharBufferMatcher(256)), + ]) + # Custom types def test_set_custom_type(self):