"""Tests for src/pygui/backend/sensor_editor.py.""" from pygui.backend.models.sensor_editor import SensorEditor def test_replace_overrides_raw_value(): ed = SensorEditor() ed.set_replacement(2, 150.0) # index 2 forced to 150.0 regardless of raw assert ed.apply([149.0, 149.0, 99.0]) == [149.0, 149.0, 150.0] def test_offset_shifts_raw_value(): ed = SensorEditor() ed.set_offset(0, +0.5) assert ed.apply([149.0, 149.0]) == [149.5, 149.0] def test_replace_and_offset_apply_in_order(): """Replacement wins over raw, then offset is added on top.""" ed = SensorEditor() ed.set_replacement(2, 150.0) ed.set_offset(2, +1.0) # sensor 2: replace 99→150, then +1 → 151 ed.set_offset(0, +0.5) out = ed.apply([149.0, 149.0, 99.0, 149.0]) assert out == [149.5, 149.0, 151.0, 149.0] def test_clear_single_index_restores_only_that_sensor(): ed = SensorEditor() ed.set_replacement(0, 0.0) ed.set_replacement(1, 0.0) ed.clear(0) # clear only index 0 assert ed.apply([149.0, 149.0]) == [149.0, 0.0] def test_clear_restores_all(): ed = SensorEditor() ed.set_offset(0, 5.0) ed.set_replacement(1, 200.0) ed.clear() assert ed.apply([149.0, 149.0]) == [149.0, 149.0] def test_no_overrides_returns_copy(): ed = SensorEditor() original = [149.0, 149.0] result = ed.apply(original) assert result == original assert result is not original