From 351a66a42cc3afe0bd3aea38b686b62cd99337bf Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Wed, 11 Feb 2026 10:05:31 +0000 Subject: [PATCH] Cleaning up workflows and fixing tests. --- .../scan_planners.py | 8 ++-- tests/unit_tests/test_scan_planners.py | 48 +++++++++++++------ 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/openflexure_microscope_server/scan_planners.py b/src/openflexure_microscope_server/scan_planners.py index c6975226..2ba4d6e9 100644 --- a/src/openflexure_microscope_server/scan_planners.py +++ b/src/openflexure_microscope_server/scan_planners.py @@ -318,9 +318,9 @@ class RectGridPlanner(ScanPlanner): def _parse(self, planner_settings: Optional[dict] = None) -> None: expected_keys = ["dx", "dy"] invalid_msg = "RectGridPlanner requires planner_settings with keys: " - if not planner_settings: - raise ValueError(invalid_msg + ",".join(expected_keys)) - if not all(k in planner_settings for k in expected_keys): + if not planner_settings or not all( + k in planner_settings for k in expected_keys + ): raise KeyError(invalid_msg + ",".join(expected_keys)) self._dx = int(planner_settings["dx"]) @@ -623,7 +623,7 @@ class RegularGridPlanner(RectGridPlanner): super()._parse(planner_settings) expected_keys = ["x_count", "y_count", "style"] - invalid_msg = "SnakeScan requires planner_settings with keys: " + invalid_msg = "RegularGrid requires planner_settings with keys: " if not planner_settings or not all( k in planner_settings for k in expected_keys ): diff --git a/tests/unit_tests/test_scan_planners.py b/tests/unit_tests/test_scan_planners.py index cf4c8acc..995aa761 100644 --- a/tests/unit_tests/test_scan_planners.py +++ b/tests/unit_tests/test_scan_planners.py @@ -89,8 +89,8 @@ def test_bad_smart_spiral_settings(): initial_position = (100, 50) # Class init should raise error if no planner_settings dictionary set - msg = "RectangleScan requires planner_settings with keys" - with pytest.raises(ValueError, match=msg): + msg = "RectGridPlanner requires planner_settings with keys" + with pytest.raises(KeyError, match=msg): scan_planners.SmartSpiral(initial_position=initial_position) planner_settings = {"dx": 50, "dy": 50, "max_dist": 10000} @@ -317,12 +317,18 @@ def test_example_smart_spiral(): assert planner.imaged_locations == expected_planner.imaged_locations -def test_snake_scan_basic_grid(): - """Check that SnakeScan generates a single point for a 1x1 scan.""" +def test_snake_planner_basic_grid(): + """Check that snake scan planner generates a single point for a 1x1 scan.""" initial_position = (100, 50) - planner_settings = {"dx": 100, "dy": 100, "x_count": 1, "y_count": 1} + planner_settings = { + "dx": 100, + "dy": 100, + "x_count": 1, + "y_count": 1, + "style": "snake", + } - planner = scan_planners.SnakeScan( + planner = scan_planners.RegularGridPlanner( initial_position=initial_position, planner_settings=planner_settings, ) @@ -352,11 +358,17 @@ def test_snake_scan_basic_grid(): def test_snake_scan_basic_length(): - """SnakeScan should generate the correct number of locations.""" + """Snake scan planner should generate the correct number of locations.""" initial_position = (100, 50) - planner_settings = {"dx": 100, "dy": 100, "x_count": 3, "y_count": 4} + planner_settings = { + "dx": 100, + "dy": 100, + "x_count": 3, + "y_count": 4, + "style": "snake", + } - planner = scan_planners.SnakeScan( + planner = scan_planners.RegularGridPlanner( initial_position=initial_position, planner_settings=planner_settings, ) @@ -369,9 +381,15 @@ def test_snake_scan_basic_length(): def test_snake_scan_ordering(): """Test that snake scan returns a path in the right order.""" initial_position = (0, 0) - planner_settings = {"dx": 10, "dy": 10, "x_count": 4, "y_count": 3} + planner_settings = { + "dx": 10, + "dy": 10, + "x_count": 4, + "y_count": 3, + "style": "snake", + } - planner = scan_planners.SnakeScan( + planner = scan_planners.RegularGridPlanner( initial_position=initial_position, planner_settings=planner_settings, ) @@ -399,9 +417,9 @@ def test_snake_scan_ordering(): def test_snake_scan_single_row(): """Test edge case of a single row scan.""" initial_position = (0, 0) - planner_settings = {"dx": 5, "dy": 5, "x_count": 4, "y_count": 1} + planner_settings = {"dx": 5, "dy": 5, "x_count": 4, "y_count": 1, "style": "snake"} - planner = scan_planners.SnakeScan( + planner = scan_planners.RegularGridPlanner( initial_position=initial_position, planner_settings=planner_settings, ) @@ -412,9 +430,9 @@ def test_snake_scan_single_row(): def test_snake_scan_single_column(): """Test edge case of a single column scan.""" initial_position = (0, 0) - planner_settings = {"dx": 5, "dy": 5, "x_count": 1, "y_count": 4} + planner_settings = {"dx": 5, "dy": 5, "x_count": 1, "y_count": 4, "style": "snake"} - planner = scan_planners.SnakeScan( + planner = scan_planners.RegularGridPlanner( initial_position=initial_position, planner_settings=planner_settings, )