refactor(backend): clean up package re-exports, settings model properties, and unused signals
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
|
||||
from pygui.backend.visualization.chart_geometry import index_to_pixel, value_to_pixel
|
||||
|
||||
|
||||
def test_value_to_pixel_min_maps_to_bottom():
|
||||
assert value_to_pixel(0.0, 0.0, 100.0, pixel_start=10.0, pixel_span=200.0) == pytest.approx(210.0)
|
||||
|
||||
|
||||
def test_value_to_pixel_max_maps_to_top():
|
||||
assert value_to_pixel(100.0, 0.0, 100.0, pixel_start=10.0, pixel_span=200.0) == pytest.approx(10.0)
|
||||
|
||||
|
||||
def test_value_to_pixel_midpoint():
|
||||
assert value_to_pixel(50.0, 0.0, 100.0, pixel_start=0.0, pixel_span=200.0) == pytest.approx(100.0)
|
||||
|
||||
|
||||
def test_value_to_pixel_degenerate_range_centers():
|
||||
assert value_to_pixel(5.0, 5.0, 5.0, pixel_start=0.0, pixel_span=200.0) == pytest.approx(100.0)
|
||||
|
||||
|
||||
def test_index_to_pixel_first_and_last():
|
||||
assert index_to_pixel(0, 5, pixel_start=0.0, pixel_span=100.0) == pytest.approx(0.0)
|
||||
assert index_to_pixel(4, 5, pixel_start=0.0, pixel_span=100.0) == pytest.approx(100.0)
|
||||
|
||||
|
||||
def test_index_to_pixel_single_point_centers():
|
||||
assert index_to_pixel(0, 1, pixel_start=0.0, pixel_span=100.0) == pytest.approx(50.0)
|
||||
@@ -0,0 +1,61 @@
|
||||
import pytest
|
||||
|
||||
from pygui.backend.data.local_settings import LocalSettings
|
||||
from pygui.backend.data.local_settings_model import LocalSettingsModel
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def shared_settings():
|
||||
return LocalSettings()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def model(qapp, tmp_path, shared_settings):
|
||||
return LocalSettingsModel(shared_settings, tmp_path)
|
||||
|
||||
|
||||
def test_save_mutates_the_shared_instance_in_place(model, shared_settings):
|
||||
# This is the bug candidate 1 fixes: DeviceController holds the same
|
||||
# LocalSettings object, so a save here must be visible to it without
|
||||
# a reload — no throwaway copy, no stale read until restart.
|
||||
model.chamberId = "7"
|
||||
model.waferReadTimeout = 45000
|
||||
model.saveSettings()
|
||||
|
||||
assert shared_settings.chamber_id == "7"
|
||||
assert shared_settings.wafer_read_timeout == 45000
|
||||
|
||||
|
||||
def test_save_persists_to_disk_and_reload_round_trips(tmp_path, qapp, shared_settings):
|
||||
model = LocalSettingsModel(shared_settings, tmp_path)
|
||||
model.chamberId = "9"
|
||||
model.waferRetries = 3
|
||||
model.saveSettings()
|
||||
|
||||
reloaded_settings = LocalSettings.read_settings(str(tmp_path))
|
||||
other_model = LocalSettingsModel(reloaded_settings, tmp_path)
|
||||
other_model.loadSettings()
|
||||
|
||||
assert other_model.chamberId == "9"
|
||||
assert other_model.waferRetries == 3
|
||||
|
||||
|
||||
def test_revert_restores_last_saved_values(model):
|
||||
model.chamberId = "2"
|
||||
model.saveSettings()
|
||||
|
||||
model.chamberId = "unsaved-edit"
|
||||
assert model.isDirty is True
|
||||
|
||||
model.revertChanges()
|
||||
assert model.chamberId == "2"
|
||||
assert model.isDirty is False
|
||||
|
||||
|
||||
def test_invalid_chamber_id_blocks_save(model, shared_settings):
|
||||
shared_settings.chamber_id = "before"
|
||||
model.chamberId = ""
|
||||
model.saveSettings()
|
||||
|
||||
assert model.saveStatus.startswith("error:")
|
||||
assert shared_settings.chamber_id == "before" # unsaved, shared instance untouched
|
||||
@@ -1,7 +1,10 @@
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from pygui.backend.controllers.session_controller import SessionController
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def controller():
|
||||
return SessionController()
|
||||
@@ -9,7 +12,7 @@ def controller():
|
||||
def test_initial_default(controller):
|
||||
assert controller.mode == "review"
|
||||
assert controller.state == "idle"
|
||||
assert controller.recording == False
|
||||
assert not controller.recording
|
||||
|
||||
def test_playback_flow(controller):
|
||||
controller.loadFile("tests/fixtures/sample_stream.csv")
|
||||
@@ -119,10 +122,10 @@ Item {
|
||||
def test_recording_toggle(controller, tmp_path):
|
||||
csv_path = str(tmp_path / "rec" / "live_test.csv")
|
||||
controller.startRecording(csv_path, "SN123")
|
||||
assert controller.recording == True
|
||||
assert controller.recording
|
||||
|
||||
controller.stopRecording()
|
||||
assert controller.recording == False
|
||||
assert not controller.recording
|
||||
|
||||
# Header written with wafer serial
|
||||
content = open(csv_path).read()
|
||||
|
||||
Reference in New Issue
Block a user