Skip to content

Commit bdfd7c2

Browse files
committed
TestImageGenerator.test_non_square_patterns_shape: test with SimulatedCamera.
Since d4cb3b35 SimulatedCamera can have any sensor shape, so we can now test the ImageGenerator as integrated in SimulatedCamera instead of via the private classes.
1 parent eba0dec commit bdfd7c2

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

microscope/testsuite/test_devices.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@
3737

3838
import unittest
3939
import unittest.mock
40+
from queue import Queue
4041

4142
import numpy
4243

4344
import microscope.testsuite.devices as dummies
4445
import microscope.testsuite.mock_devices as mocks
4546
from microscope import simulators
47+
from microscope.simulators.stage_aware_camera import StageAwareCamera
4648

4749

4850
class TestSerialMock(unittest.TestCase):
@@ -423,20 +425,20 @@ def setUp(self):
423425

424426
class TestImageGenerator(unittest.TestCase):
425427
def test_non_square_patterns_shape(self):
426-
# TODO: we should also be testing this via the camera but the
427-
# TestCamera is only square. In the mean time, we only test
428-
# directly the _ImageGenerator.
429428
width = 16
430429
height = 32
431-
generator = simulators._ImageGenerator()
432-
patterns = list(generator.get_methods())
433-
for i, pattern in enumerate(patterns):
434-
with self.subTest(pattern):
435-
generator.set_method(i)
436-
array = generator.get_image(width, height, 0, 255)
430+
camera = simulators.SimulatedCamera(sensor_shape=(width, height))
431+
buf = Queue()
432+
camera.set_client(buf)
433+
camera.enable()
434+
for idx, name in camera.describe_setting("image pattern")["values"]:
435+
with self.subTest(name):
436+
camera.set_setting("image pattern", idx)
437+
camera.trigger()
438+
image = buf.get()
437439
# In matplotlib, an M-wide by N-tall image has M columns
438440
# and N rows, so a shape of (N, M)
439-
self.assertEqual(array.shape, (height, width))
441+
self.assertEqual(image.shape, (height, width))
440442

441443

442444
class TestDummyController(unittest.TestCase, ControllerTests):

0 commit comments

Comments
 (0)