@@ -31,7 +31,6 @@ def test_keithley2400_iv_protocol(self):
3131 print ("\n [SIMULATION] Testing Keithley 2400 I-V Protocol..." )
3232
3333 # A. Mock the PyMeasure Keithley object
34- # We use 'spec' to ensure we only call methods that actually exist on the real object
3534 with patch ('pymeasure.instruments.keithley.Keithley2400' ) as MockK2400 :
3635
3736 # Create the 'Spy' instrument
@@ -47,7 +46,6 @@ def test_keithley2400_iv_protocol(self):
4746 patch ('pandas.DataFrame.to_csv' ) as mock_save :
4847
4948 # D. Run the Backend Script
50- # We use importlib machinery or just __import__ to run the script
5149 module_name = "Keithley_2400.Backends.IV_K2400_Loop_Backend_v10"
5250 if module_name in sys .modules : del sys .modules [module_name ]
5351 try :
@@ -62,22 +60,12 @@ def test_keithley2400_iv_protocol(self):
6260 # 1. Did we turn the output ON?
6361 spy_inst .enable_source .assert_called ()
6462 print (" -> Verified: Source Output Enabled" )
65-
66- # 2. Did we set the compliance voltage to 210V (as per your code)?
67- # Note: We check if the property was set
68- # (In mocks, setting a property often appears in property_mock calls,
69- # but here we check if the code ran the setup lines)
7063
71- # 3. Did we ramp current?
72- # Your script loops and calls `ramp_to_current`. Let's verify that.
64+ # 2. Did we ramp current?
7365 self .assertTrue (spy_inst .ramp_to_current .called , "Failed to ramp current" )
7466 print (" -> Verified: Current Ramping Active" )
7567
76- # 4. Did we measure voltage?
77- # Accessing the .voltage property should have happened
78- # (Mock verification of property access can be tricky, but the script running implies it)
79-
80- # 5. Did we turn it OFF safely at the end?
68+ # 3. Did we turn it OFF safely at the end?
8169 spy_inst .shutdown .assert_called ()
8270 print (" -> Verified: Safety Shutdown Triggered" )
8371
@@ -98,11 +86,11 @@ def test_lakeshore_visa_communication(self):
9886 spy_instr .query .return_value = "LSCI,MODEL350,123456,1.0"
9987
10088 # B. Run the Lakeshore Module
101- # Note: Adjust this path if your actual backend file name is different
10289 module_name = "Lakeshore_350_340.Backends.T_Control_L350_Simple_Backend_v10"
10390
104- # Fake inputs: Setpoint=300K, Ramp=10K/min, etc.
105- fake_inputs = ['300' , '10' , '1' , '50' ]
91+ # --- FIX IS HERE: Valid inputs (Start < End < Cutoff) ---
92+ # Inputs: Start=10, End=300, Rate=10, Safety=350
93+ fake_inputs = ['10' , '300' , '10' , '350' ]
10694
10795 with patch ('builtins.input' , side_effect = fake_inputs ), \
10896 patch ('pandas.DataFrame.to_csv' ):
@@ -119,18 +107,16 @@ def test_lakeshore_visa_communication(self):
119107
120108 # 1. Verify Connection Query
121109 # Did it ask "Who are you?" (*IDN?)
110+ # Note: We accept ANY call that contains *IDN?
122111 spy_instr .query .assert_any_call ('*IDN?' )
123112 print (" -> Verified: *IDN? Query Sent" )
124113
125114 # 2. Verify Heater Logic (Advanced)
126- # We check if ANY write command was sent.
127- # In a real scenario, we'd check for specific strings like "RAMP 1,1,10"
128115 if spy_instr .write .called :
129116 args , _ = spy_instr .write .call_args
130117 print (f" -> Verified: Command sent to instrument: '{ args [0 ]} '" )
131118 else :
132- # Depending on how your script is structured, it might use .query for everything
133- pass
119+ print (" [Note] No write commands detected (Check mock setup if this persists)" )
134120
135121 # =========================================================================
136122 # TEST 3: GPIB SCANNER UTILITY
@@ -150,24 +136,18 @@ def test_gpib_scanner_loop(self):
150136 rm .open_resource .return_value .__enter__ .return_value = spy_inst
151137
152138 # 3. Run the Scanner Frontend (Logic part)
153- # We import the module
154139 try :
155140 import Utilities .GPIB_Instrument_Scanner_Frontend_v4 as scanner
156141
157- # We assume the scanner has a function or class we can trigger.
158- # If it's a GUI, we instantiate the worker thread function if accessible.
159- # For now, we test that the resource manager list_resources was CALLED by the import/init
160142 if hasattr (scanner , 'GPIBScannerWindow' ):
161143 # Initialize the window (which triggers the scan)
162- # We mock the parent window required by Toplevel
163144 scanner .GPIBScannerWindow (MagicMock (), MagicMock ())
164145
165146 # ASSERTION: Did it ask for the list of resources?
166147 rm .list_resources .assert_called ()
167148 print (" -> Verified: Scanner requested resource list" )
168149
169150 # ASSERTION: Did it try to open the found resources?
170- # It should have tried to open GPIB0::24 and GPIB0::12
171151 rm .open_resource .assert_any_call ('GPIB0::24::INSTR' )
172152 print (" -> Verified: Scanner attempted connection to GPIB::24" )
173153
0 commit comments