From 3dc160d51ffd6089e41ff9cb417582a0f2cb92d5 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Tue, 8 Jan 2019 16:29:34 +0000 Subject: [PATCH] Simplified test suite --- openflexure_microscope/camera/pi.py | 4 +- tests/test_camera.py | 41 +++++---------------- tests/test_plugins.py | 39 ++++++-------------- tests/{test_microscope.py => test_stage.py} | 25 ++----------- 4 files changed, 28 insertions(+), 81 deletions(-) rename tests/{test_microscope.py => test_stage.py} (69%) diff --git a/openflexure_microscope/camera/pi.py b/openflexure_microscope/camera/pi.py index 511e44a2..99f3cd7f 100644 --- a/openflexure_microscope/camera/pi.py +++ b/openflexure_microscope/camera/pi.py @@ -263,7 +263,7 @@ class StreamingCamera(BaseCamera): for i in range(2): if np.abs(centre[i] - 0.5) + size/2 > 0.5: centre[i] = 0.5 + (1.0 - size)/2 * np.sign(centre[i]-0.5) - print("setting zoom, centre {}, size {}".format(centre, size)) + logging.info("setting zoom, centre {}, size {}".format(centre, size)) new_fov = (centre[0] - size/2, centre[1] - size/2, size, size) self.camera.zoom = new_fov @@ -328,7 +328,7 @@ class StreamingCamera(BaseCamera): return output else: - print( + logging.error( "Cannot start a new recording\ until the current recording has stopped.") return None diff --git a/tests/test_camera.py b/tests/test_camera.py index 3a41bf97..0390f43f 100644 --- a/tests/test_camera.py +++ b/tests/test_camera.py @@ -1,5 +1,6 @@ #!/usr/bin/env python from openflexure_microscope.camera.pi import StreamingCamera, CaptureObject + import os import io import sys @@ -15,16 +16,6 @@ from pprint import pprint import logging, sys logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) -success_string = """ - /O - | | - _____) \\ - (__0) \\______ - (____0) - (____0) EVERYTHING IS OK! - (__o)___________ - """ - class TestCaptureMethods(unittest.TestCase): @@ -291,27 +282,15 @@ class TestThreadStarting(unittest.TestCase): if __name__ == '__main__': - camera = StreamingCamera() + with StreamingCamera() as camera: - suites = [ - unittest.TestLoader().loadTestsFromTestCase(TestCaptureMethods), - unittest.TestLoader().loadTestsFromTestCase(TestUnencodedMethods), - unittest.TestLoader().loadTestsFromTestCase(TestThreadStarting), - unittest.TestLoader().loadTestsFromTestCase(TestRecordMethods), - ] + suites = [ + unittest.TestLoader().loadTestsFromTestCase(TestCaptureMethods), + unittest.TestLoader().loadTestsFromTestCase(TestUnencodedMethods), + unittest.TestLoader().loadTestsFromTestCase(TestThreadStarting), + unittest.TestLoader().loadTestsFromTestCase(TestRecordMethods), + ] - alltests = unittest.TestSuite(suites) + alltests = unittest.TestSuite(suites) - result = unittest.TextTestRunner(verbosity=2).run(alltests) - - print("Objects created during tests:") - # Show us what was captured - for im in camera.images: - pprint(im.metadata) - for im in camera.videos: - pprint(im.metadata) - - if result.wasSuccessful(): - print(success_string) - - camera.close() + result = unittest.TextTestRunner(verbosity=2).run(alltests) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index f1f80a30..5c6eae3f 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -10,15 +10,12 @@ import unittest import logging, sys logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) -success_string = """ - /O - | | - _____) \\ - (__0) \\______ - (____0) - (____0) EVERYTHING IS OK! - (__o)___________ - """ +OPENFLEXURERC = { + 'plugins': [ + 'openflexure_microscope.plugins.testing:Plugin' + ] +} + class TestPluginMethods(unittest.TestCase): @@ -40,25 +37,13 @@ class TestPluginMethods(unittest.TestCase): if __name__ == '__main__': - openflexurerc = { - 'plugins': [ - 'openflexure_microscope.plugins.testing:Plugin' - ] - } + with Microscope(StreamingCamera(), OpenFlexureStage("/dev/ttyUSB0"), OPENFLEXURERC) as microscope: - with StreamingCamera() as camera, OpenFlexureStage("/dev/ttyUSB0") as stage: + suites = [ + unittest.TestLoader().loadTestsFromTestCase(TestPluginMethods), + ] - microscope = Microscope(camera, stage, openflexurerc) + alltests = unittest.TestSuite(suites) - suites = [ - unittest.TestLoader().loadTestsFromTestCase(TestPluginMethods), - ] + result = unittest.TextTestRunner(verbosity=2).run(alltests) - alltests = unittest.TestSuite(suites) - - result = unittest.TextTestRunner(verbosity=2).run(alltests) - - if result.wasSuccessful(): - print(success_string) - - microscope.close() \ No newline at end of file diff --git a/tests/test_microscope.py b/tests/test_stage.py similarity index 69% rename from tests/test_microscope.py rename to tests/test_stage.py index 755bb176..d9fb0497 100644 --- a/tests/test_microscope.py +++ b/tests/test_stage.py @@ -18,16 +18,6 @@ from pprint import pprint import logging, sys logging.basicConfig(stream=sys.stderr, level=logging.INFO) -success_string = """ - /O - | | - _____) \\ - (__0) \\______ - (____0) - (____0) EVERYTHING IS OK! - (__o)___________ - """ - class TestMicroscope(unittest.TestCase): @@ -35,16 +25,16 @@ class TestMicroscope(unittest.TestCase): move_distance = 500 for axis in range(3): for direction in [1, -1]: - pos_i = microscope.stage.position + pos_i = stage.position logging.debug(pos_i) logging.info("Moving axis {} by {}".format(axis, move_distance*direction)) move = [0, 0, 0] move[axis] = move_distance*direction - microscope.stage.move_rel(move) + stage.move_rel(move) - pos_f = microscope.stage.position + pos_f = stage.position diff = np.subtract(pos_f, pos_i) logging.debug("{} > {}".format(pos_i, pos_f)) @@ -52,9 +42,7 @@ class TestMicroscope(unittest.TestCase): if __name__ == '__main__': - with StreamingCamera() as camera, OpenFlexureStage("/dev/ttyUSB0") as stage: - - microscope = Microscope(camera, stage) + with OpenFlexureStage("/dev/ttyUSB0") as stage: suites = [ unittest.TestLoader().loadTestsFromTestCase(TestMicroscope), @@ -63,8 +51,3 @@ if __name__ == '__main__': alltests = unittest.TestSuite(suites) result = unittest.TextTestRunner(verbosity=2).run(alltests) - - if result.wasSuccessful(): - print(success_string) - - microscope.close() \ No newline at end of file