Refactor DataSource classes and enhance testing framework

- Removed outdated comments and documentation from CsvSessionSource and DemoSource classes.
- Introduced new unit tests for CsvSource and DataSource functionalities, ensuring robust validation of CSV loading and session handling.
- Added UI smoke tests to verify window instantiation and menu actions without hardware dependencies.
- Implemented VisionEngine tests to validate demo snapshots and alignment state logic.
This commit is contained in:
Your Name
2026-05-28 11:09:53 -07:00
parent 81fd015520
commit 958fde9050
6 changed files with 311 additions and 66 deletions
+80
View File
@@ -0,0 +1,80 @@
from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from wafer_edge.Calibration import BaselineCalibration, load_baseline, save_baseline
from wafer_edge.VisionEngine import AlignmentThresholds, VisionEngine, fit_circle
class VisionEngineTests(unittest.TestCase):
def test_demo_snapshot_matches_beta_values(self) -> None:
snapshot = VisionEngine().demo_snapshot(BaselineCalibration())
self.assertEqual(snapshot.source_label, "User App - Simulated Data")
self.assertEqual(snapshot.system_status, "Ready")
self.assertAlmostEqual(snapshot.x_offset_mm, 2.3, places=6)
self.assertAlmostEqual(snapshot.y_offset_mm, -1.1, places=6)
self.assertAlmostEqual(snapshot.theta_offset_deg, 0.5, places=1)
self.assertLess(snapshot.sigma_mm, 0.001)
self.assertEqual(len(snapshot.camera_readings), 4)
self.assertEqual(snapshot.camera_readings[2].status, "ok")
def test_fit_circle_from_edge_points(self) -> None:
circle = fit_circle([(1.0, 0.0), (0.0, 1.0), (-1.0, 0.0), (0.0, -1.0)])
self.assertAlmostEqual(circle.center_mm[0], 0.0)
self.assertAlmostEqual(circle.center_mm[1], 0.0)
self.assertAlmostEqual(circle.radius_mm, 1.0)
def test_calibration_round_trip(self) -> None:
baseline = BaselineCalibration(
center_mm=(1.0, 2.0), radius_mm=3.0, theta_arm_mm=4.0
)
with tempfile.TemporaryDirectory() as temp_dir:
path = Path(temp_dir) / "baseline.json"
save_baseline(baseline, path)
loaded = load_baseline(path)
self.assertEqual(loaded, baseline)
class AlignmentStateTests(unittest.TestCase):
def test_ready_state(self)-> None:
engine = VisionEngine()
# offset ~ 0.07mm from (0.05, 0.05), sigma = 0.01
state = engine.get_alignment_state(0.05, 0.05, 0.01)
self.assertEqual(state, "ready")
def test_aligning_state(self)-> None:
engine = VisionEngine()
state = engine.get_alignment_state(0.20, 0.0, 0.10)
self.assertEqual(state, "aligning")
def test_fault_by_offset(self) -> None:
engine = VisionEngine()
state = engine.get_alignment_state(0.60, 0.0, 0.01)
self.assertEqual(state, "fault")
def test_fault_by_sigma(self) -> None:
engine = VisionEngine()
state = engine.get_alignment_state(0.05, 0.0, 0.25)
self.assertEqual(state, "fault")
def test_boundary_ready(self) -> None:
engine = VisionEngine()
state =engine.get_alignment_state(0.10, 0.0, 0.05)
self.assertEqual(state, "ready")
def test_demo_snapshot_alignment_state(self) -> None:
engine = VisionEngine()
snapshot = engine.demo_snapshot(BaselineCalibration())
self.assertEqual(snapshot.alignment_state, "fault")
class AlignmentThresholdInjectionTest(unittest.TestCase):
def test_loose_thresholds_make_demo_ready(self) -> None:
engine = VisionEngine(thresholds = AlignmentThresholds(
ready_offset_mm = 5.0, ready_sigma_mm = 5.0
))
snapshot = engine.demo_snapshot(BaselineCalibration())
self.assertEqual(snapshot.alignment_state, "ready")
if __name__ == "__main__":
unittest.main()