1+ import hightime
2+ import nirfsg
3+
4+ from unittest .mock import MagicMock
5+ from unittest .mock import patch
6+ import _mock_helper
7+
8+ SESSION_NUM_FOR_TEST = 42
9+
10+ class TestSession :
11+
12+ class PatchedLibraryInterpreter (nirfsg ._library_interpreter .LibraryInterpreter ):
13+ def __init__ (self , encoding ):
14+ for f in dir (self ):
15+ if not f .startswith ("_" ) and f not in {'get_session_handle' , 'set_session_handle' }:
16+ setattr (self , f , MagicMock (spec_set = getattr (self , f ), side_effect = _mock_helper .MockFunctionCallError (f )))
17+
18+ def setup_method (self , method ):
19+ self .patched_library_interpreter = self .PatchedLibraryInterpreter (None )
20+ self .patched_library_interpreter_ctor = patch ('nirfsg.session._library_interpreter.LibraryInterpreter' , return_value = self .patched_library_interpreter )
21+ self .patched_library_interpreter_ctor .start ()
22+
23+ # We don't actually call into the nitclk DLL, but we do need to mock the function since it is called
24+ self .tclk_patched_library_singleton_get = patch ('nitclk._library_interpreter._library_singleton.get' , return_value = None )
25+ self .tclk_patched_library_singleton_get .start ()
26+
27+ def interpreter_init (* args , ** kwargs ):
28+ self .patched_library_interpreter ._close_on_exit = True
29+ return SESSION_NUM_FOR_TEST
30+
31+ self .patched_library_interpreter .init_with_options .side_effect = interpreter_init
32+ self .patched_library_interpreter .close .side_effect = [None ]
33+
34+ # Mock lock/unlock
35+ self .patched_library_interpreter .lock .side_effect = lambda * args : None
36+ self .patched_library_interpreter .unlock .side_effect = lambda * args : None
37+
38+ def teardown_method (self , method ):
39+ self .patched_library_interpreter_ctor .stop ()
40+
41+ def test_attribute_get_for_repeated_capability_custom_object (self ):
42+ string = 'markerterminal'
43+ self .patched_library_interpreter .get_attribute_vi_string .side_effect = [string ]
44+ with nirfsg .Session ('dev1' ,id_query = False , reset_device = False ) as session :
45+ # Custom expansion: Specify marker '0'
46+ value = session .markers ['0' ].marker_event_terminal_name
47+ # Verify that the repeated capability string is '0'
48+ self .patched_library_interpreter .get_attribute_vi_string .assert_called_once_with ('marker0' , 1150115 )
0 commit comments