-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: napari init attrib bug, and add unit tests (#102)
This makes sure the attribute is always set regardless of the config. It also adds a basic unit test mechanism for the gui / business logic code that we can start using to test all this stuff. Tested by: Unit tests
- Loading branch information
Showing
4 changed files
with
180 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import os | ||
import pathlib | ||
|
||
import control.core.core | ||
import control.microcontroller | ||
import control.lighting | ||
import control.camera | ||
import squid.stage.cephla | ||
from squid.config import get_stage_config | ||
import squid.abc | ||
import git | ||
|
||
import control._def | ||
|
||
|
||
def get_test_microcontroller() -> control.microcontroller.Microcontroller: | ||
return control.microcontroller.Microcontroller(control.microcontroller.SimSerial(), True) | ||
|
||
|
||
def get_test_camera(): | ||
return control.camera.Camera_Simulation() | ||
|
||
|
||
def get_test_live_controller( | ||
camera, microcontroller, config_manager, illumination_controller | ||
) -> control.core.core.LiveController: | ||
controller = control.core.core.LiveController(camera, microcontroller, config_manager, illumination_controller) | ||
controller.set_microscope_mode(config_manager.configurations[0]) | ||
|
||
return controller | ||
|
||
|
||
def get_test_stage(microcontroller): | ||
return squid.stage.cephla.CephlaStage(microcontroller=microcontroller, stage_config=get_stage_config()) | ||
|
||
|
||
def get_repo_root() -> pathlib.Path: | ||
git_repo = git.Repo(os.getcwd(), search_parent_directories=True) | ||
git_root = git_repo.git.rev_parse("--show-toplevel") | ||
|
||
return pathlib.Path(git_root).absolute() | ||
|
||
|
||
def get_test_configuration_manager_path() -> pathlib.Path: | ||
return get_repo_root() / "channel_configurations.xml" | ||
|
||
|
||
def get_test_configuration_manager() -> control.core.core.ConfigurationManager: | ||
return control.core.core.ConfigurationManager(get_test_configuration_manager_path()) | ||
|
||
|
||
def get_test_illumination_controller( | ||
microcontroller: control.microcontroller.Microcontroller, | ||
) -> control.lighting.IlluminationController: | ||
return control.lighting.IlluminationController( | ||
microcontroller=microcontroller, | ||
intensity_control_mode=control.lighting.IntensityControlMode.Software, | ||
shutter_control_mode=control.lighting.ShutterControlMode.Software, | ||
) | ||
|
||
|
||
def get_test_autofocus_controller( | ||
camera, | ||
stage: squid.abc.AbstractStage, | ||
live_controller: control.core.core.LiveController, | ||
microcontroller: control.microcontroller.Microcontroller, | ||
): | ||
return control.core.core.AutoFocusController( | ||
camera=camera, stage=stage, liveController=live_controller, microcontroller=microcontroller | ||
) | ||
|
||
|
||
def get_test_scan_coordinates( | ||
objective_store: control.core.core.ObjectiveStore, | ||
navigation_viewer: control.core.core.NavigationViewer, | ||
stage: squid.abc.AbstractStage, | ||
): | ||
return control.core.core.ScanCoordinates(objective_store, navigation_viewer, stage) | ||
|
||
|
||
def get_test_objective_store(): | ||
return control.core.core.ObjectiveStore( | ||
objectives_dict=control._def.OBJECTIVES, default_objective=control._def.DEFAULT_OBJECTIVE | ||
) | ||
|
||
|
||
def get_test_navigation_viewer(objective_store: control.core.core.ObjectiveStore): | ||
return control.core.core.NavigationViewer(objective_store) | ||
|
||
|
||
def get_test_multi_point_controller() -> control.core.core.MultiPointController: | ||
microcontroller = get_test_microcontroller() | ||
camera = get_test_camera() | ||
stage = get_test_stage(microcontroller) | ||
config_manager = get_test_configuration_manager() | ||
live_controller = get_test_live_controller( | ||
camera, microcontroller, config_manager, get_test_illumination_controller(microcontroller) | ||
) | ||
objective_store = get_test_objective_store() | ||
|
||
multi_point_controller = control.core.core.MultiPointController( | ||
camera=camera, | ||
stage=stage, | ||
microcontroller=microcontroller, | ||
liveController=live_controller, | ||
autofocusController=get_test_autofocus_controller(camera, stage, live_controller, microcontroller), | ||
configurationManager=get_test_configuration_manager(), | ||
scanCoordinates=get_test_scan_coordinates(objective_store, get_test_navigation_viewer(objective_store), stage), | ||
) | ||
|
||
multi_point_controller.set_base_path("/tmp/") | ||
multi_point_controller.start_new_experiment("unit test experiment") | ||
|
||
return multi_point_controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import control.core.core | ||
from control._def import * | ||
|
||
import tests.control.gui_test_stubs as gts | ||
|
||
|
||
# Make sure we can create a multi point controller and worker with out default config | ||
def test_multi_point_worker_with_default_config(qtbot): | ||
multi_point_controller = gts.get_test_multi_point_controller() | ||
multi_point_controller.run_acquisition() | ||
multi_point_controller.request_abort_aquisition() | ||
|
||
|
||
def test_multi_point_worker_init_bugs(qtbot): | ||
# We don't always init all our fields in __init__, which leads to some paths | ||
# for some configs whereby we use instance attributes before initialization. This | ||
# test documents cases of those by writing tests that hit them (then subsequent PR that | ||
# fix them to make this test pass). | ||
|
||
# The init_napari_layers field is dependent on USE_NAPARI_FOR_MULTIPOINT, | ||
# so make sure that it is initialized regardless of that config value. | ||
|
||
USE_NAPARI_FOR_MULTIPOINT = False | ||
multi_point_controller_for_false = gts.get_test_multi_point_controller() | ||
multi_point_controller_for_false.run_acquisition() | ||
multi_point_controller_for_false.request_abort_aquisition() | ||
# This will throw if the attribute doesn't exist | ||
napari_layer_for_false = multi_point_controller_for_false.multiPointWorker.init_napari_layers | ||
|
||
USE_NAPARI_FOR_MULTIPOINT = True | ||
multi_point_controller_for_true = gts.get_test_multi_point_controller() | ||
multi_point_controller_for_true.run_acquisition() | ||
multi_point_controller_for_true.request_abort_aquisition() | ||
# This will throw if the attribute doesn't exist | ||
napari_layer_for_true = multi_point_controller_for_true.multiPointWorker.init_napari_layers |