Skip to content

Commit cf0dd62

Browse files
flask8 fixes 2
1 parent df4e7c9 commit cf0dd62

3 files changed

Lines changed: 9 additions & 26 deletions

File tree

tests/test_gui_iv_k2400.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,4 @@ def test_start_measurement_logic(self, mock_fig_subplots, MockBackend):
6868
self.assertAlmostEqual(passed_params['max_current'], 100e-6)
6969

7070
# 3. Did the GUI generate the correct sweep points?
71-
mock_backend_instance.generate_sweep_points.assert_called_once()
72-
71+
mock_backend_instance.generate_sweep_points.assert_called_once()

tests/test_iv_k6517b_simple_backend.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
import unittest
2-
from unittest.mock import patch, MagicMock, mock_open
3-
import numpy as np
2+
from unittest.mock import patch, MagicMock, mock_open, call
43

54
# Import the main function from the script we want to test
65
from Keithley_6517B.High_Resistance.Backends.IV_K6517B_Simple_Backend_v10 import main as iv_simple_main
76

7+
88
class TestIVK6517BSimpleBackend(unittest.TestCase):
99
@patch('time.sleep', MagicMock())
1010
@patch('builtins.input', side_effect=['-10', '10', '5', '0.1', 'test_iv_simple.csv'])
11-
@patch('pymeasure.adapters.visa.VISAAdapter') # New patch
12-
@patch('Keithley_6517B.High_Resistance.Backends.IV_K6517B_Simple_Backend_v10.Keithley6517B')
11+
@patch('pymeasure.instruments.keithley.Keithley6517B')
1312
@patch('builtins.open', new_callable=mock_open)
1413
@patch('matplotlib.pyplot.show')
15-
def test_full_run(self, mock_show, mock_file, mock_keithley_class, mock_visa_adapter, mock_input):
14+
def test_full_run(self, mock_show, mock_file, mock_keithley_class, mock_input):
1615
"""
1716
Tests a complete, successful run of the IV_K6517B_Simple_Backend script.
1817
"""
19-
# --- MOCK SETUP for VISAAdapter ---
20-
mock_visa_adapter_instance = MagicMock()
21-
mock_visa_adapter.return_value = mock_visa_adapter_instance
22-
# Simulate IDN query result that Keithley6517B might perform
23-
mock_visa_adapter_instance.ask.return_value = "Mocked Keithley 6517B ID"
24-
2518
# --- Setup Mocks for Keithley6517B ---
2619
mock_instrument = MagicMock()
2720
mock_keithley_class.return_value = mock_instrument
@@ -30,13 +23,12 @@ def test_full_run(self, mock_show, mock_file, mock_keithley_class, mock_visa_ada
3023
# Simulate resistance measurement
3124
mock_instrument.resistance = 1.23e9
3225

33-
3426
# --- Run the main function and catch exceptions ---
3527
try:
3628
iv_simple_main()
3729
except Exception as e:
3830
# The script might exit or raise an error after plotting, which is fine for this test
39-
if "no display name" not in str(e): # Ignore matplotlib display errors in CI
31+
if "no display name" not in str(e): # Ignore matplotlib display errors in CI
4032
pass
4133

4234
# --- Assertions ---

tests/test_pica_launcher.py

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

64
# -----------------------------------------------------------------------------
75
# MOCK HELPER CLASSES for GUI Testing
@@ -21,6 +19,7 @@ def invoke(self):
2119
if self.command:
2220
self.command()
2321

22+
2423
class MockPicaLauncher:
2524
"""
2625
Simulates the PICA_v6.py launcher class structure.
@@ -30,7 +29,6 @@ def __init__(self):
3029
# Attach MockTkWidget to simulate the 'command' binding for the button
3130
self.button_iv_sweep = MockTkWidget(command=self.open_iv_sweep)
3231
self.button_temp_control = MockTkWidget(command=self.open_temp_control)
33-
3432
# Internal state tracker to confirm methods are called
3533
self.open_gui_calls = {'iv_sweep': 0, 'temp_control': 0}
3634

@@ -57,40 +55,34 @@ class TestPicaLauncher(unittest.TestCase):
5755
def test_iv_sweep_button_click_calls_function(self, mock_open_iv_sweep):
5856
"""Tests that clicking the IV Sweep button calls its launch function once."""
5957
launcher = MockPicaLauncher()
60-
6158
# Simulate button click
6259
launcher.button_iv_sweep.invoke()
6360

6461
# Assert the mocked function was called
6562
mock_open_iv_sweep.assert_called_once()
66-
6763
# Assert the internal counter was incremented
6864
self.assertEqual(launcher.open_gui_calls['iv_sweep'], 1)
6965

7066
@patch('test_pica_launcher.MockPicaLauncher.open_temp_control')
7167
def test_temp_control_button_click_calls_function(self, mock_open_temp_control):
7268
"""Tests that clicking the Temp Control button calls its launch function once."""
7369
launcher = MockPicaLauncher()
74-
7570
# Simulate button click
7671
launcher.button_temp_control.invoke()
7772

7873
# Assert the mocked function was called
7974
mock_open_temp_control.assert_called_once()
80-
8175
# Assert the internal counter was incremented
8276
self.assertEqual(launcher.open_gui_calls['temp_control'], 1)
8377

8478
def test_multiple_clicks(self):
8579
"""Tests that multiple clicks correctly register multiple calls."""
8680
launcher = MockPicaLauncher()
87-
8881
# Simulate multiple clicks
8982
for _ in range(3):
9083
launcher.button_iv_sweep.invoke()
91-
9284
self.assertEqual(launcher.open_gui_calls['iv_sweep'], 3)
93-
self.assertEqual(launcher.open_gui_calls['temp_control'], 0) # Ensure others are not called
85+
self.assertEqual(launcher.open_gui_calls['temp_control'], 0) # Ensure others are not called
9486

9587

9688
if __name__ == '__main__':

0 commit comments

Comments
 (0)