Skip to content

Commit aaf70d9

Browse files
committed
fix tests
1 parent d75fab7 commit aaf70d9

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

test/controller/sub_controllers/test_camera_view.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def setup_class(self, dummy_controller):
9393
"number_z_steps": np.random.randint(0, 100),
9494
"stack_cycling_mode": "per_stack",
9595
"selected_channels": 3,
96+
"image_mode": "z-stack"
9697
}
9798

9899
def test_init(self):
@@ -403,8 +404,12 @@ def test_digital_zoom(self):
403404

404405
@pytest.mark.parametrize("onoff", [True, False])
405406
def test_left_click(self, onoff):
406-
407407
self.camera_view.add_crosshair = MagicMock()
408+
self.camera_view.digital_zoom = MagicMock()
409+
self.camera_view.detect_saturation = MagicMock()
410+
self.camera_view.down_sample_image = MagicMock()
411+
self.camera_view.transpose_image = MagicMock()
412+
self.camera_view.scale_image_intensity = MagicMock()
408413
self.camera_view.apply_lut = MagicMock()
409414
self.camera_view.populate_image = MagicMock()
410415
event = MagicMock()
@@ -415,7 +420,6 @@ def test_left_click(self, onoff):
415420
self.camera_view.left_click(event)
416421

417422
self.camera_view.add_crosshair.assert_called()
418-
self.camera_view.apply_lut.assert_called()
419423
self.camera_view.populate_image.assert_called()
420424
assert self.camera_view.apply_cross_hair == (not onoff)
421425

@@ -564,8 +568,8 @@ def mocked_PhotoImage(img):
564568
def test_initialize_non_live_display(self):
565569
# Create test buffer and microscope_state
566570
camera_parameters = {
567-
"x_pixels": np.random.randint(1, 200),
568-
"y_pixels": np.random.randint(1, 200),
571+
"img_x_pixels": np.random.randint(1, 200),
572+
"img_y_pixels": np.random.randint(1, 200),
569573
}
570574

571575
# Call the function
@@ -587,10 +591,10 @@ def test_initialize_non_live_display(self):
587591
== self.camera_view.number_of_channels * self.camera_view.number_of_slices
588592
)
589593
assert self.camera_view.original_image_width == int(
590-
camera_parameters["x_pixels"]
594+
camera_parameters["img_x_pixels"]
591595
)
592596
assert self.camera_view.original_image_height == int(
593-
camera_parameters["y_pixels"]
597+
camera_parameters["img_y_pixels"]
594598
)
595599
assert self.camera_view.canvas_width_scale == float(
596600
self.camera_view.original_image_width / self.camera_view.canvas_width
@@ -610,16 +614,20 @@ def test_retrieve_image_slice_from_volume(self):
610614
@pytest.mark.parametrize("transpose", [True, False])
611615
def test_display_image(self, transpose):
612616
self.camera_view.initialize_non_live_display(
613-
self.microscope_state, {"x_pixels": 100, "y_pixels": 100}
617+
self.microscope_state, {"img_x_pixels": 100, "img_y_pixels": 100}
614618
)
615-
619+
self.camera_view.digital_zoom = MagicMock()
620+
self.camera_view.detect_saturation = MagicMock()
621+
self.camera_view.down_sample_image = MagicMock()
622+
self.camera_view.scale_image_intensity = MagicMock()
623+
self.camera_view.apply_lut = MagicMock()
624+
self.camera_view.populate_image = MagicMock()
616625
images = np.random.rand(10, 100, 100)
617626

618627
self.camera_view.transpose = transpose
619628
count = 0
620629
self.camera_view.image_count = count
621630
self.camera_view.image_metrics = {"Channel": MagicMock()}
622-
self.camera_view.process_image = MagicMock()
623631
self.camera_view.update_max_counts = MagicMock()
624632
self.camera_view.flip_flags = {"x": False, "y": False}
625633

@@ -661,22 +669,20 @@ def test_display_image(self, transpose):
661669
def test_add_crosshair(self):
662670

663671
# Arrange
664-
image = np.random.rand(500, 500)
665-
self.camera_view.down_sampled_image = image
672+
x = self.camera_view.canvas_width
673+
y = self.camera_view.canvas_height
674+
image = np.random.rand(x, y)
666675
self.camera_view.apply_cross_hair = True
667-
num = np.random.randint(1, 50)
668-
self.camera_view.crosshair_x = num
669-
self.camera_view.crosshair_y = num
670676

671677
# Act
672-
self.camera_view.add_crosshair()
678+
image2 = self.camera_view.add_crosshair(image)
673679

674680
# Assert
675681
assert np.all(
676-
self.camera_view.cross_hair_image[:, self.camera_view.crosshair_x] == 1
682+
image2[:, self.camera_view.zoom_rect[0][1]//2] == 1
677683
)
678684
assert np.all(
679-
self.camera_view.cross_hair_image[self.camera_view.crosshair_y, :] == 1
685+
image2[self.camera_view.zoom_rect[1][1]//2, :] == 1
680686
)
681687

682688
def test_apply_LUT(self):
@@ -691,10 +697,9 @@ def test_update_LUT(self):
691697
def test_detect_saturation(self):
692698
test_image = np.random.randint(0, 2**16, size=(100, 100))
693699
test_image[:50, :50] = 2**16 - 1 # set top left corner to saturation value
694-
self.camera_view.zoom_image = test_image
695700

696701
# Call the function to detect saturation
697-
self.camera_view.detect_saturation()
702+
self.camera_view.detect_saturation(test_image)
698703

699704
# Assert that the saturated pixels were correctly detected
700705
assert np.all(self.camera_view.saturated_pixels == 2**16 - 1)

test/controller/test_controller.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from types import SimpleNamespace
33
from unittest.mock import MagicMock, ANY
44
import pytest
5+
import numpy
56

67

78
class DummySplashScreen:
@@ -500,11 +501,24 @@ def test_execute_random(controller):
500501

501502

502503
def test_capture_image(controller):
504+
505+
count = 0
506+
def get_image_id():
507+
nonlocal count
508+
count += 1
509+
if count >= 10:
510+
return "stop"
511+
return numpy.random.randint(0, 10)
512+
513+
width = controller.configuration["experiment"]["CameraParameters"]["img_x_pixels"]
514+
height = controller.configuration["experiment"]["CameraParameters"]["img_y_pixels"]
515+
images = numpy.random.rand(10, width, height)
516+
controller.data_buffer = images
503517
work_thread = MagicMock()
504518
work_thread.join = MagicMock()
505519
controller.threads_pool.createThread = MagicMock()
506520
controller.threads_pool.createThread.return_value = work_thread
507-
controller.show_img_pipe.recv = MagicMock()
521+
controller.show_img_pipe.recv = get_image_id
508522
controller.show_img_pipe.poll = MagicMock()
509523
controller.show_img_pipe.poll.return_value = False
510524

0 commit comments

Comments
 (0)