Updated simple plugin test

This commit is contained in:
Joel Collins 2019-01-08 16:15:39 +00:00
parent 4638071a00
commit eb5c9c3fee
3 changed files with 63 additions and 7 deletions

View file

@ -0,0 +1 @@
from .plugin import Plugin

View file

@ -0,0 +1,13 @@
from openflexure_microscope.plugins import MicroscopePlugin
class Plugin(MicroscopePlugin):
"""
A set of default plugins
"""
def identify(self):
"""
Tests for access to Microscope.camera, and Microscope.stage
"""
return (self.microscope.camera, self.microscope.stage)

View file

@ -4,19 +4,61 @@ from openflexure_stage import OpenFlexureStage
from openflexure_microscope import Microscope, config from openflexure_microscope import Microscope, config
import atexit import atexit
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 = """
/O
| |
_____) \\
(__0) \\______
(____0)
(____0) EVERYTHING IS OK!
(__o)___________
"""
class TestPluginMethods(unittest.TestCase):
def test_testplugin_load(self):
plugin_arr = microscope.plugin.plugins
plugin_names = [plugin[0] for plugin in plugin_arr]
self.assertTrue('testing' in plugin_names)
def test_camera_access(self):
identify = microscope.plugin.testing.identify()
self.assertTrue(identify[0] is microscope.camera)
def test_stage_access(self):
identify = microscope.plugin.testing.identify()
self.assertTrue(identify[1] is microscope.stage)
if __name__ == '__main__': if __name__ == '__main__':
openflexurerc = config.load_config()
print(openflexurerc) openflexurerc = {
'plugins': [
'openflexure_microscope.plugins.testing:Plugin'
]
}
microscope = Microscope(StreamingCamera(config=openflexurerc), OpenFlexureStage("/dev/ttyUSB0"), config=openflexurerc) with StreamingCamera() as camera, OpenFlexureStage("/dev/ttyUSB0") as stage:
print(microscope.plugin.plugins) microscope = Microscope(camera, stage, openflexurerc)
# Check that default tets plugins have loaded suites = [
print(microscope.plugin.default.identify()) unittest.TestLoader().loadTestsFromTestCase(TestPluginMethods),
]
microscope.close() alltests = unittest.TestSuite(suites)
result = unittest.TextTestRunner(verbosity=2).run(alltests)
if result.wasSuccessful():
print(success_string)
microscope.close()