Created
January 7, 2010 10:50
-
-
Save bebraw/271158 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PluginLoader: | |
def load(self, directory): | |
ret = [] | |
for plugin in directory.children: | |
plugin_file = plugin.find(name=plugin.name, type='py') | |
plugin_class = plugin_file.classes[plugin.name] | |
ret.append(plugin_class) | |
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_dir.name = 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