Skip to content

Commit feb9357

Browse files
Tests added
1 parent 5a38961 commit feb9357

6 files changed

Lines changed: 15 additions & 16 deletions

File tree

Delta_mode_Keithley_6221_2182/Delta_RT_K6221_K2182_L350_T_Control_GUI_v5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ def _update_measurement_loop(self):
944944
else:
945945
# Slightly less than 1s to prevent drift
946946
self.root.after(900, self._update_measurement_loop)
947-
except Exception as e:
947+
except Exception:
948948
self.log(f"RUNTIME ERROR: {traceback.format_exc()}")
949949
self.stop_measurement()
950950

Lock_in_amplifier/BasicTest_S830_Backend_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def main():
7575

7676
except pyvisa.errors.VisaIOError as e:
7777
# Handle VISA-specific errors, like instrument not found or timeout.
78-
print(f"VISA Error: Could not connect or communicate with the instrument.")
78+
print("VISA Error: Could not connect or communicate with the instrument.")
7979
print(f" Details: {e}")
8080
print(" Troubleshooting tips:")
8181
print(" - Is the instrument powered on and connected?")

deployment/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def run_command(command):
115115
try:
116116
subprocess.run(command, check=True, text=True, capture_output=True)
117117
except subprocess.CalledProcessError as e:
118-
print(f"--- ERROR ---", file=sys.stderr)
118+
print("--- ERROR ---", file=sys.stderr)
119119
print(e.stdout, file=sys.stderr)
120120
print(e.stderr, file=sys.stderr)
121121
raise
@@ -175,9 +175,9 @@ def build():
175175
final_app_dir)
176176

177177
print("\n--- Build Complete! ---")
178-
print(f"The final application folder is located at:")
178+
print("The final application folder is located at:")
179179
print(f" {final_app_dir}")
180-
print(f"\nA distributable ZIP file has been created at:")
180+
print("\nA distributable ZIP file has been created at:")
181181
print(f" {os.path.join(DIST_DIR, zip_filename + '.zip')}")
182182

183183

tests/test_deep_simulation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def run_module_safely(self, module_name):
6969
print(f" -> Running {module_name}.main()...", flush=True)
7070
mod.main()
7171
else:
72-
print(f" -> Module loaded (no main function).", flush=True)
72+
print(" -> Module loaded (no main function).", flush=True)
7373
except Exception as e:
7474
if "Force Test Exit" in str(e) or isinstance(e, SystemExit):
7575
print(
@@ -196,7 +196,7 @@ def test_08_combined_2400_2182(self):
196196
# THIS WAS THE TEST CAUSING THE HANG
197197
# We suspect input mismatch or resource opening hang.
198198
with patch('pyvisa.ResourceManager') as MockRM, \
199-
patch('pymeasure.instruments.keithley.Keithley2400') as MockK2400, \
199+
patch('pymeasure.instruments.keithley.Keithley2400'), \
200200
patch('time.sleep', side_effect=self.get_circuit_breaker(10)):
201201

202202
rm = MockRM.return_value

tests/test_iv_k2400_loop_backend.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import unittest
2-
from unittest.mock import patch, MagicMock, mock_open
3-
import numpy as np
4-
import pandas as pd
2+
from unittest.mock import patch, MagicMock
53
import sys
64
import os
75

@@ -14,7 +12,7 @@
1412
class TestIVK2400LoopBackend(unittest.TestCase):
1513

1614
@patch('builtins.input', side_effect=['10', '2', 'test_output'])
17-
@patch('pymeasure.instruments.keithley.Keithley2400')
15+
@patch('Keithley_2400.Backends.IV_K2400_Loop_Backend_v10.Keithley2400')
1816
@patch('matplotlib.pyplot.show')
1917
@patch('pandas.DataFrame.to_csv')
2018
def test_main_full_run(self, mock_to_csv, mock_plt_show, mock_keithley_class, mock_input):

tests/test_t_control_l350_backend.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import unittest
22
from unittest.mock import patch, MagicMock, mock_open
33
import pyvisa
4-
import time
54
import sys
65
import os
76

@@ -31,7 +30,7 @@ def test_initialization_success(self):
3130
@patch('pyvisa.ResourceManager')
3231
def test_initialization_failure(self, mock_rm):
3332
# Test that a connection error is raised if pyvisa fails
34-
mock_rm.return_value.open_resource.side_effect = pyvisa.errors.VisaIOError("Test Error")
33+
mock_rm.return_value.open_resource.side_effect = pyvisa.errors.VisaIOError(pyvisa.constants.VI_ERROR_RSRC_NFOUND)
3534
with self.assertRaises(ConnectionError):
3635
Lakeshore350("GPIB0::13::INSTR")
3736

@@ -79,7 +78,7 @@ def test_close(self):
7978
self.assertIsNone(self.controller.instrument)
8079

8180
class TestMainFunctionAndUserInput(unittest.TestCase):
82-
@patch('builtins.input', side_effect=['100', '200', '300', '10', 'not-a-number', '50', '350', '400'])
81+
@patch('builtins.input', side_effect=['100', '200', '300', '10', 'not-a-number', '50', '350', '400', '10'])
8382
def test_get_user_parameters(self, mock_input):
8483
# First call: Valid input
8584
start, end, rate, cutoff = get_user_parameters()
@@ -89,15 +88,17 @@ def test_get_user_parameters(self, mock_input):
8988
# Second call: Invalid text input, should retry and get the next valid ones
9089
start, end, rate, cutoff = get_user_parameters()
9190
self.assertEqual((start, end, cutoff), (50, 350, 400))
92-
91+
self.assertEqual(rate, 10)
92+
93+
@patch('tkinter.Tk')
9394
@patch('tkinter.filedialog.asksaveasfilename', return_value='test.csv')
9495
@patch('builtins.input', side_effect=['10', '20', '5', '30'])
9596
@patch('Lakeshore_350_340.Backends.T_Control_L350_Simple_Backend_v10.Lakeshore350')
9697
@patch('matplotlib.pyplot.show')
9798
@patch('builtins.open', new_callable=mock_open)
9899
@patch('time.sleep', MagicMock())
99100
@patch('time.time', side_effect=[1000, 1002, 1004, 1006, 1008, 1010]) # Simulate time passing
100-
def test_main_runs_and_completes(self, mock_time, mock_open_file, mock_plt_show, mock_ls_class, mock_input, mock_file_dialog):
101+
def test_main_runs_and_completes(self, mock_time, mock_open_file, mock_plt_show, mock_ls_class, mock_input, mock_file_dialog, mock_tk):
101102
# --- MOCK SETUP ---
102103
mock_controller = MagicMock()
103104
mock_ls_class.return_value = mock_controller

0 commit comments

Comments
 (0)