Some tests for the new plugin core functionality

This commit is contained in:
Gina Häußge 2015-09-04 16:43:10 +02:00
parent 8abf152d40
commit c98f1332be
6 changed files with 52 additions and 12 deletions

View file

@ -0,0 +1,6 @@
def callback(*args, **kwargs):
pass
__plugin_hooks__ = {
"some.ordered.callback": (callback, 100)
}

View file

@ -7,4 +7,7 @@ def hook_startup():
__plugin_name__ = "Hook Plugin"
__plugin_description__ = "Test hook plugin"
__plugin_hooks__ = {'octoprint.core.startup': hook_startup}
__plugin_hooks__ = {
'octoprint.core.startup': hook_startup,
'some.ordered.callback': hook_startup
}

View file

@ -9,9 +9,13 @@ import octoprint.plugin
class TestMixedPlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.SettingsPlugin):
pass
def get_sorting_key(self, context=None):
if context == "sorting_test":
return 100
else:
return None
__plugin_name__ = "Mixed Plugin"
__plugin_description__ = "Test mixed plugin"
__plugin_implementation__ = TestMixedPlugin()
__plugin_implementation__ = TestMixedPlugin()

View file

@ -0,0 +1,6 @@
def callback(*args, **kwargs):
pass
__plugin_hooks__ = {
"some.ordered.callback": (callback, 10)
}

View file

@ -4,9 +4,13 @@ import octoprint.plugin
class TestStartupPlugin(octoprint.plugin.StartupPlugin):
pass
def get_sorting_key(self, context=None):
if context == "sorting_test":
return 10
else:
return None
__plugin_name__ = "Startup Plugin"
__plugin_description__ = "Test startup plugin"
__plugin_implementation__ = TestStartupPlugin()
__plugin_implementation__ = TestStartupPlugin()

View file

@ -23,8 +23,8 @@ class PluginTestCase(unittest.TestCase):
self.plugin_manager.initialize_implementations()
def test_plugin_loading(self):
self.assertEquals(5, len(self.plugin_manager.enabled_plugins))
self.assertEquals(1, len(self.plugin_manager.plugin_hooks))
self.assertEquals(7, len(self.plugin_manager.enabled_plugins))
self.assertEquals(2, len(self.plugin_manager.plugin_hooks))
self.assertEquals(4, len(self.plugin_manager.plugin_implementations))
self.assertEquals(3, len(self.plugin_manager.plugin_implementations_by_type))
@ -32,6 +32,10 @@ class PluginTestCase(unittest.TestCase):
self.assertTrue("octoprint.core.startup" in self.plugin_manager.plugin_hooks)
self.assertEquals(1, len(self.plugin_manager.plugin_hooks["octoprint.core.startup"]))
# ordered hook plugins
self.assertTrue("some.ordered.callback" in self.plugin_manager.plugin_hooks)
self.assertEquals(3, len(self.plugin_manager.plugin_hooks["some.ordered.callback"]))
# TestStartupPlugin & TestMixedPlugin
self.assertTrue(octoprint.plugin.StartupPlugin in self.plugin_manager.plugin_implementations_by_type)
self.assertEquals(2, len(self.plugin_manager.plugin_implementations_by_type[octoprint.plugin.StartupPlugin]))
@ -119,18 +123,31 @@ class PluginTestCase(unittest.TestCase):
hooks = self.plugin_manager.get_hooks("octoprint.printing.print")
self.assertEquals(0, len(hooks))
def test_get_implementation(self):
def test_sorted_hooks(self):
hooks = self.plugin_manager.get_hooks("some.ordered.callback")
self.assertEquals(3, len(hooks))
self.assertListEqual(["one_ordered_hook_plugin", "another_ordered_hook_plugin", "hook_plugin"], hooks.keys())
def test_get_implementations(self):
implementations = self.plugin_manager.get_implementations(octoprint.plugin.StartupPlugin)
self.assertEquals(2, len(implementations)) # startup_plugin, mixed_plugin
self.assertListEqual(["mixed_plugin", "startup_plugin"], map(lambda x: x._identifier, implementations))
implementations = self.plugin_manager.get_implementations(octoprint.plugin.SettingsPlugin)
self.assertEquals(2, len(implementations)) # settings_plugin, mixed_plugin
self.assertListEqual(["mixed_plugin", "settings_plugin"], map(lambda x: x._identifier, implementations))
implementations = self.plugin_manager.get_implementations(octoprint.plugin.StartupPlugin, octoprint.plugin.SettingsPlugin)
self.assertEquals(1, len(implementations)) # mixed_plugin
self.assertListEqual(["mixed_plugin"], map(lambda x: x._identifier, implementations))
implementations = self.plugin_manager.get_implementations(octoprint.plugin.AssetPlugin)
self.assertEquals(1, len(implementations)) # deprecated_plugin, but only first implementation!
self.assertListEqual(["deprecated_plugin"], map(lambda x: x._identifier, implementations))
def test_get_filtered_implementations(self):
implementations = self.plugin_manager.get_filtered_implementations(lambda x: x._identifier.startswith("startup"), octoprint.plugin.StartupPlugin)
self.assertEquals(1, len(implementations))
def test_get_sorted_implementations(self):
implementations = self.plugin_manager.get_implementations(octoprint.plugin.StartupPlugin, sorting_context="sorting_test")
self.assertListEqual(["startup_plugin", "mixed_plugin"], map(lambda x: x._identifier, implementations))
def test_client_registration(self):
def test_client(*args, **kwargs):