chore: apply linting fixes and expand ruff coverage to test suite
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import pytest
|
||||
import logging
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from pygui.backend.controllers.device_controller import DeviceController
|
||||
from pygui.backend.data.local_settings import LocalSettings
|
||||
from pygui.serialcomm.serial_port import WaferInfo
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_settings():
|
||||
s = LocalSettings()
|
||||
@@ -16,8 +19,8 @@ def mock_settings():
|
||||
|
||||
@pytest.fixture
|
||||
def controller(mock_settings):
|
||||
import tempfile
|
||||
import shutil
|
||||
import tempfile
|
||||
temp_dir = tempfile.mkdtemp()
|
||||
yield DeviceController(mock_settings, temp_dir)
|
||||
shutil.rmtree(temp_dir)
|
||||
@@ -81,7 +84,7 @@ def test_clear_session(controller):
|
||||
controller._connection_status = "Connected"
|
||||
controller._selected_port = "COM1"
|
||||
controller._last_wafer_info = {"serialNumber": "P00001"}
|
||||
|
||||
|
||||
controller.clearSession()
|
||||
assert controller.connectionStatus == "Disconnected"
|
||||
assert controller.selectedPort == ""
|
||||
@@ -142,7 +145,7 @@ def test_parse_and_save_data_and_get_chart_data(controller):
|
||||
|
||||
controller.parsedDataReady.connect(on_parsed)
|
||||
controller.parseAndSaveData("P", "COM1")
|
||||
|
||||
|
||||
assert emitted_result is not None
|
||||
assert emitted_result.get("success") is True
|
||||
assert controller.dataRowCount == 1
|
||||
@@ -159,16 +162,16 @@ def test_logging_handler(controller):
|
||||
assert any("Hello QML Activity Log" in line for line in controller._activity_log)
|
||||
|
||||
def test_fresh_session_on_startup(mock_settings):
|
||||
import tempfile
|
||||
import shutil
|
||||
|
||||
import tempfile
|
||||
|
||||
# Configure mock settings with some data to simulate previous session
|
||||
mock_settings.activity_log = ["[12:00:00] Old message"]
|
||||
mock_settings.selected_port = "COM9"
|
||||
mock_settings.last_wafer_info = {"familyCode": "P", "serialNumber": "P00002"}
|
||||
mock_settings.data_row_count = 50
|
||||
mock_settings.data_col_count = 244
|
||||
|
||||
|
||||
temp_dir = tempfile.mkdtemp()
|
||||
try:
|
||||
new_controller = DeviceController(mock_settings, temp_dir)
|
||||
@@ -187,19 +190,19 @@ def test_detect_wafer_clears_old_session(controller):
|
||||
controller._data_row_count = 10
|
||||
controller._data_col_count = 244
|
||||
controller._activity_log.append("[12:00:00] Previous message")
|
||||
|
||||
|
||||
# We mock detect_all_ports to not run long or fail
|
||||
controller._service.detect_all_ports = MagicMock(return_value=(None, None))
|
||||
|
||||
with patch("threading.Thread") as mock_thread:
|
||||
|
||||
with patch("threading.Thread"):
|
||||
controller.detectWafer()
|
||||
|
||||
|
||||
# Verify it cleared all session variables and logs immediately at start of detect
|
||||
assert controller.selectedPort == ""
|
||||
assert controller.lastWaferInfo == ["", "", 0, "", 0, 0]
|
||||
assert controller.dataRowCount == 0
|
||||
assert controller.dataColCount == 0
|
||||
|
||||
|
||||
# Log should only contain "Scanning all ports for wafer ..."
|
||||
assert len(controller._activity_log) == 1
|
||||
assert "Scanning all ports" in controller._activity_log[0]
|
||||
@@ -227,6 +230,6 @@ def test_device_service_port_caching(controller):
|
||||
|
||||
# Clear cache and scan again should invoke subprocess
|
||||
service.clear_port_scan_cache()
|
||||
ports3 = service.enumerate_ports()
|
||||
service.enumerate_ports()
|
||||
assert mock_run.call_count == 2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user