Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
class PluginLoader:
def load(self, directory):
ret = []
for plugin in directory.children:
plugin_file = plugin.find(, type='py')
plugin_class = plugin_file.classes[]
return ret
from mock import Mock
from placidity.plugin_loader import PluginLoader
class TestPluginLoader:
def test_load_plugins(self):
class Plugin1: pass
class Plugin2: pass
plugin_dir = Mock()
plugin1_dir = self.create_plugin_dir('plugin1', Plugin1)
plugin2_dir = self.create_plugin_dir('plugin2', Plugin2)
plugin_dir.children = (plugin1_dir, plugin2_dir)
plugin_loader = PluginLoader()
assert plugin_loader.load(plugin_dir) == [Plugin1, Plugin2]
def create_plugin_dir(self, plugin_name, plugin_class):
plugin_dir = Mock() = plugin_name
plugin_dir.children = Mock()
plugin_file = self.create_plugin_file(plugin_name, plugin_class)
def find(name, type):
assert type == 'py'
if name is plugin_name:
return plugin_file
plugin_dir.find = find
return plugin_dir
def create_plugin_file(self, name, klass):
plugin_file = Mock()
plugin_file.classes = {name: klass, }
return plugin_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment