Simplified test suite

This commit is contained in:
Joel Collins 2019-01-08 16:29:34 +00:00
parent eb5c9c3fee
commit 3dc160d51f
4 changed files with 28 additions and 81 deletions

View file

@ -263,7 +263,7 @@ class StreamingCamera(BaseCamera):
for i in range(2): for i in range(2):
if np.abs(centre[i] - 0.5) + size/2 > 0.5: 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) 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) new_fov = (centre[0] - size/2, centre[1] - size/2, size, size)
self.camera.zoom = new_fov self.camera.zoom = new_fov
@ -328,7 +328,7 @@ class StreamingCamera(BaseCamera):
return output return output
else: else:
print( logging.error(
"Cannot start a new recording\ "Cannot start a new recording\
until the current recording has stopped.") until the current recording has stopped.")
return None return None

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
from openflexure_microscope.camera.pi import StreamingCamera, CaptureObject from openflexure_microscope.camera.pi import StreamingCamera, CaptureObject
import os import os
import io import io
import sys import sys
@ -15,16 +16,6 @@ from pprint import pprint
import logging, sys import logging, sys
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
success_string = """
/O
| |
_____) \\
(__0) \\______
(____0)
(____0) EVERYTHING IS OK!
(__o)___________
"""
class TestCaptureMethods(unittest.TestCase): class TestCaptureMethods(unittest.TestCase):
@ -291,27 +282,15 @@ class TestThreadStarting(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
camera = StreamingCamera() with StreamingCamera() as camera:
suites = [ suites = [
unittest.TestLoader().loadTestsFromTestCase(TestCaptureMethods), unittest.TestLoader().loadTestsFromTestCase(TestCaptureMethods),
unittest.TestLoader().loadTestsFromTestCase(TestUnencodedMethods), unittest.TestLoader().loadTestsFromTestCase(TestUnencodedMethods),
unittest.TestLoader().loadTestsFromTestCase(TestThreadStarting), unittest.TestLoader().loadTestsFromTestCase(TestThreadStarting),
unittest.TestLoader().loadTestsFromTestCase(TestRecordMethods), unittest.TestLoader().loadTestsFromTestCase(TestRecordMethods),
] ]
alltests = unittest.TestSuite(suites) alltests = unittest.TestSuite(suites)
result = unittest.TextTestRunner(verbosity=2).run(alltests) 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()

View file

@ -10,15 +10,12 @@ import unittest
import logging, sys import logging, sys
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
success_string = """ OPENFLEXURERC = {
/O 'plugins': [
| | 'openflexure_microscope.plugins.testing:Plugin'
_____) \\ ]
(__0) \\______ }
(____0)
(____0) EVERYTHING IS OK!
(__o)___________
"""
class TestPluginMethods(unittest.TestCase): class TestPluginMethods(unittest.TestCase):
@ -40,25 +37,13 @@ class TestPluginMethods(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
openflexurerc = { with Microscope(StreamingCamera(), OpenFlexureStage("/dev/ttyUSB0"), OPENFLEXURERC) as microscope:
'plugins': [
'openflexure_microscope.plugins.testing:Plugin'
]
}
with StreamingCamera() as camera, OpenFlexureStage("/dev/ttyUSB0") as stage: suites = [
unittest.TestLoader().loadTestsFromTestCase(TestPluginMethods),
]
microscope = Microscope(camera, stage, openflexurerc) alltests = unittest.TestSuite(suites)
suites = [ result = unittest.TextTestRunner(verbosity=2).run(alltests)
unittest.TestLoader().loadTestsFromTestCase(TestPluginMethods),
]
alltests = unittest.TestSuite(suites)
result = unittest.TextTestRunner(verbosity=2).run(alltests)
if result.wasSuccessful():
print(success_string)
microscope.close()

View file

@ -18,16 +18,6 @@ from pprint import pprint
import logging, sys import logging, sys
logging.basicConfig(stream=sys.stderr, level=logging.INFO) logging.basicConfig(stream=sys.stderr, level=logging.INFO)
success_string = """
/O
| |
_____) \\
(__0) \\______
(____0)
(____0) EVERYTHING IS OK!
(__o)___________
"""
class TestMicroscope(unittest.TestCase): class TestMicroscope(unittest.TestCase):
@ -35,16 +25,16 @@ class TestMicroscope(unittest.TestCase):
move_distance = 500 move_distance = 500
for axis in range(3): for axis in range(3):
for direction in [1, -1]: for direction in [1, -1]:
pos_i = microscope.stage.position pos_i = stage.position
logging.debug(pos_i) logging.debug(pos_i)
logging.info("Moving axis {} by {}".format(axis, move_distance*direction)) logging.info("Moving axis {} by {}".format(axis, move_distance*direction))
move = [0, 0, 0] move = [0, 0, 0]
move[axis] = move_distance*direction 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) diff = np.subtract(pos_f, pos_i)
logging.debug("{} > {}".format(pos_i, pos_f)) logging.debug("{} > {}".format(pos_i, pos_f))
@ -52,9 +42,7 @@ class TestMicroscope(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
with StreamingCamera() as camera, OpenFlexureStage("/dev/ttyUSB0") as stage: with OpenFlexureStage("/dev/ttyUSB0") as stage:
microscope = Microscope(camera, stage)
suites = [ suites = [
unittest.TestLoader().loadTestsFromTestCase(TestMicroscope), unittest.TestLoader().loadTestsFromTestCase(TestMicroscope),
@ -63,8 +51,3 @@ if __name__ == '__main__':
alltests = unittest.TestSuite(suites) alltests = unittest.TestSuite(suites)
result = unittest.TextTestRunner(verbosity=2).run(alltests) result = unittest.TextTestRunner(verbosity=2).run(alltests)
if result.wasSuccessful():
print(success_string)
microscope.close()