def test_set_vi_session_with_session_reference(self): session = nitclk.SessionReference(SESSION_NUM_FOR_TEST) self.patched_library.niTClk_SetAttributeViSession.side_effect = self.side_effects_helper.niTClk_SetAttributeViSession attribute_id = 3 other_session_number = 43 other_session_reference = nitclk.SessionReference(other_session_number) session.start_trigger_master_session = other_session_reference self.patched_library.niTClk_SetAttributeViSession.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViStringMatcher(''), _matchers.ViAttrMatcher(attribute_id), _matchers.ViSessionMatcher(other_session_number))
def test_nitclk_error_handling(): test_session_reference = nitclk.SessionReference(42) # Invalid session try: test_session_reference.exported_tclk_output_terminal = 'test' assert False except nitclk.errors.DriverError as e: assert e.code == -250032
def test_set_vi_string(self): session = nitclk.SessionReference(SESSION_NUM_FOR_TEST) self.patched_library.niTClk_SetAttributeViString.side_effect = self.side_effects_helper.niTClk_SetAttributeViString attribute_id = 13 test_string = "The answer to the ultimate question is 42" session.sync_pulse_sender_sync_pulse_source = test_string self.patched_library.niTClk_SetAttributeViString.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViStringMatcher(''), _matchers.ViAttrMatcher(attribute_id), _matchers.ViStringMatcher(test_string))
def test_set_timedelta_as_timedelta(self): session = nitclk.SessionReference(SESSION_NUM_FOR_TEST) self.patched_library.niTClk_SetAttributeViReal64.side_effect = self.side_effects_helper.niTClk_SetAttributeViReal64 attribute_id = 11 test_number = 4.2 session.sample_clock_delay = hightime.timedelta(seconds=test_number) self.patched_library.niTClk_SetAttributeViReal64.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViStringMatcher(''), _matchers.ViAttrMatcher(attribute_id), _matchers.ViReal64Matcher(test_number))
def test_set_vi_real64(self): session = nitclk.SessionReference(SESSION_NUM_FOR_TEST) self.patched_library.niTClk_SetAttributeViReal64.side_effect = self.side_effects_helper.niTClk_SetAttributeViReal64 attribute_id = 8 test_number = 4.2 session.tclk_actual_period = test_number self.patched_library.niTClk_SetAttributeViReal64.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViStringMatcher(''), _matchers.ViAttrMatcher(attribute_id), _matchers.ViReal64Matcher(test_number))
def test_get_timedelta(self): session = nitclk.SessionReference(SESSION_NUM_FOR_TEST) self.patched_library.niTClk_GetAttributeViReal64.side_effect = self.side_effects_helper.niTClk_GetAttributeViReal64 attribute_id = 11 test_number = 4.2 self.side_effects_helper['GetAttributeViReal64']['value'] = test_number attr_timedelta = session.sample_clock_delay assert(attr_timedelta.total_seconds() == test_number) self.patched_library.niTClk_GetAttributeViReal64.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViStringMatcher(''), _matchers.ViAttrMatcher(attribute_id), _matchers.ViReal64PointerMatcher())
def test_get_vi_real64(self): session = nitclk.SessionReference(SESSION_NUM_FOR_TEST) self.patched_library.niTClk_GetAttributeViReal64.side_effect = self.side_effects_helper.niTClk_GetAttributeViReal64 attribute_id = 8 test_number = 4.2 self.side_effects_helper['GetAttributeViReal64']['value'] = test_number attr_val = session.tclk_actual_period assert(attr_val == test_number) self.patched_library.niTClk_GetAttributeViReal64.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViStringMatcher(''), _matchers.ViAttrMatcher(attribute_id), _matchers.ViReal64PointerMatcher())
def test_set_vi_session_with_int(self): session = nitclk.SessionReference(SESSION_NUM_FOR_TEST) self.patched_library.niTClk_SetAttributeViSession.side_effect = self.side_effects_helper.niTClk_SetAttributeViSession other_session_number = 43 # We do not support using just the number try: session.start_trigger_master_session = other_session_number assert False except TypeError: pass
def test_get_tclk_session_reference(self): session = nitclk.SessionReference(SESSION_NUM_FOR_TEST) self.patched_library.niTClk_GetAttributeViSession.side_effect = self.side_effects_helper.niTClk_GetAttributeViSession attribute_id = 3 other_session_number = 43 self.side_effects_helper['GetAttributeViSession']['value'] = other_session_number attr_session_reference = session.start_trigger_master_session assert type(attr_session_reference) is nitclk.SessionReference assert(attr_session_reference._get_tclk_session_reference() == other_session_number) self.patched_library.niTClk_GetAttributeViSession.assert_called_once_with(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViStringMatcher(''), _matchers.ViAttrMatcher(attribute_id), _matchers.ViSessionPointerMatcher())
def test_session_reference_get_error_description_fails(self): session = nitclk.SessionReference(SESSION_NUM_FOR_TEST) self.patched_library.niTClk_GetAttributeViReal64.side_effect = self.side_effects_helper.niTClk_GetAttributeViReal64 self.side_effects_helper['GetAttributeViReal64']['return'] = -1 self.patched_library.niTClk_GetExtendedErrorInfo.side_effect = self.side_effects_helper.niTClk_GetExtendedErrorInfo self.side_effects_helper['GetExtendedErrorInfo']['return'] = -2 try: test = session.sample_clock_delay print(test) # Get rid of flake8 F841 assert False except nitclk.Error as e: assert e.code == -1 # we want the original error code from getting the attribute. assert e.description == "Failed to retrieve error description."
def test_get_vi_string(self): session = nitclk.SessionReference(SESSION_NUM_FOR_TEST) self.patched_library.niTClk_GetAttributeViString.side_effect = self.side_effects_helper.niTClk_GetAttributeViString attribute_id = 13 test_string = "The answer to the ultimate question is 42" self.side_effects_helper['GetAttributeViString']['value'] = test_string attr_string = session.sync_pulse_sender_sync_pulse_source assert(attr_string == test_string) from unittest.mock import call calls = [call(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViStringMatcher(''), _matchers.ViAttrMatcher(attribute_id), _matchers.ViInt32Matcher(0), None), call(_matchers.ViSessionMatcher(SESSION_NUM_FOR_TEST), _matchers.ViStringMatcher(''), _matchers.ViAttrMatcher(attribute_id), _matchers.ViInt32Matcher(len(test_string)), _matchers.ViCharBufferMatcher(len(test_string)))] self.patched_library.niTClk_GetAttributeViString.assert_has_calls(calls) assert self.patched_library.niTClk_GetAttributeViString.call_count == 2
def test_session_reference_error(self): session = nitclk.SessionReference(SESSION_NUM_FOR_TEST) error_string = 'Error' self.patched_library.niTClk_GetAttributeViReal64.side_effect = self.side_effects_helper.niTClk_GetAttributeViReal64 self.side_effects_helper['GetAttributeViReal64']['return'] = -1 self.patched_library.niTClk_GetExtendedErrorInfo.side_effect = self.side_effects_helper.niTClk_GetExtendedErrorInfo self.side_effects_helper['GetExtendedErrorInfo']['errorString'] = error_string try: test = session.sample_clock_delay print(test) # Get rid of flake8 F841 assert False except nitclk.Error as e: assert e.code == -1 assert e.description == error_string
def __init__(self, session_number): self.tclk = nitclk.SessionReference(session_number)
import _matchers import _mock_helper import datetime import nitclk from mock import patch SESSION_NUM_FOR_TEST = 42 single_session = [SESSION_NUM_FOR_TEST] single_session_reference = [nitclk.SessionReference(x) for x in single_session] multiple_sessions = [ SESSION_NUM_FOR_TEST, SESSION_NUM_FOR_TEST * 10, SESSION_NUM_FOR_TEST * 100, SESSION_NUM_FOR_TEST + 1 ] multiple_session_references = [ nitclk.SessionReference(x) for x in multiple_sessions ] class NitclkSupportingDriverSession(object): '''Session objects for drivers that support NI-TClk are expected to have a property of type nitclk.SessionReference called tclk This is why we're creating this fake driver class and adding the tclk property. ''' def __init__(self, session_number): self.tclk = nitclk.SessionReference(session_number) class TestNitclkApi(object): def setup_method(self, method):