示例#1
0
def test_unload_plugin():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    j.load_plugin(j.get_manifest("Basic Test"))
    j.unload_plugin("Basic Test")
    assert not j.get_plugin_loaded("Basic Test")
示例#2
0
def test_loading_manifests():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    assert j.get_manifest("Basic Test") is not None
    assert j.get_manifest("Dependency Test") is not None
    assert j.get_manifest("Missing Dependency Test") is not None
示例#3
0
def test_getting_module_of_missing_plugin():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    with pytest.raises(AttributeError):
        assert not issubclass(
            j.get_module("This should never exist").Plugin,
            jigsaw.JigsawPlugin)
示例#4
0
def test_loading_dependencies():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    j.load_plugin(j.get_manifest("Dependency Test"))
    assert j.get_plugin_loaded("Dependency Test")
    assert j.get_plugin_loaded("Basic Test")
示例#5
0
 def __init__(self, bot):
     self.bot = bot  # type: Bot.Bot
     paths = self.bot.config.get("plugin_paths", ["plugins"])
     for path in paths:
         if not os.path.isdir(path):
             os.mkdir(path)
     self._jigsaw = jigsaw.PluginLoader(plugin_paths=tuple(paths))
示例#6
0
def test_loading_specific_manifest():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifest(
        os.path.abspath(
            os.path.join(os.path.abspath(__file__), "..", "plugins",
                         "BasicTest")))
    assert j.get_manifest("Basic Test") is not None
示例#7
0
def test_load_invalid_plugin_manifest():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifest(
        os.path.abspath(
            os.path.join(os.path.abspath(__file__), "..", "plugins",
                         "InvalidManifestTest")))
    assert j.get_manifest("Invalid Manifest Test") is None
示例#8
0
def test_error_on_plugin_load():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    j.load_plugin(j.get_manifest("Error Test"))
    assert os.path.isfile(
        os.path.abspath(
            os.path.join(os.path.abspath(__file__), "..", "plugins",
                         "ErrorTest", "error.log")))
示例#9
0
def test_getting_all_plugins():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    j.load_plugins()
    for item in j.get_all_plugins():
        if item["manifest"]["name"] in [
                "Missing Dependency Test", "Invalid Baseclass Test",
                "Error Test"
        ]:
            assert isinstance(item["manifest"], dict)
            assert not isinstance(item["plugin"], jigsaw.JigsawPlugin)
        else:
            assert isinstance(item["manifest"], dict)
            assert isinstance(item["plugin"], jigsaw.JigsawPlugin)
示例#10
0
def test_oserror_on_load_plugin_manifest():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    os.mkdir(
        os.path.abspath(
            os.path.join(os.path.abspath(__file__), "..", "plugins",
                         "OSErrorTest", "plugin.json")))
    j.load_manifest(
        os.path.abspath(
            os.path.join(os.path.abspath(__file__), "..", "plugins",
                         "OSErrorTest")))
    os.rmdir(
        os.path.abspath(
            os.path.join(os.path.abspath(__file__), "..", "plugins",
                         "OSErrorTest", "plugin.json")))
    assert j.get_manifest("OS Error Test") is None
示例#11
0
def test_getting_missing_plugin():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    assert not isinstance(j.get_plugin("This should never exist"),
                          jigsaw.JigsawPlugin)
示例#12
0
def test_getting_plugin():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    j.load_plugin(j.get_manifest("Basic Test"))
    assert isinstance(j.get_plugin("Basic Test"), jigsaw.JigsawPlugin)
示例#13
0
def test_initializing_jigsaw_with_no_plugin_path_specified():
    j = jigsaw.PluginLoader()
    assert j.plugin_paths == (os.path.join(os.getcwd(), "plugins"), )
示例#14
0
def test_getting_manifest_for_missing_plugin():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    assert j.get_manifest("This should never exist") is None
示例#15
0
def test_quickload():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.quickload()
    assert j.get_plugin_loaded("Basic Test")
示例#16
0
def test_reload_all_manifests():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    j.reload_all_manifests()
    assert j.get_manifest("Basic Test") is not None
示例#17
0
def test_reload_all_plugins():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    j.load_plugins()
    j.reload_all_plugins()
示例#18
0
def test_initializing_jigsaw_with_custom_plugin_path():
    j = jigsaw.PluginLoader((os.path.join(os.getcwd(), "custom_plugins"), ))
    assert j.plugin_paths == (os.path.join(os.getcwd(), "custom_plugins"), )
示例#19
0
def test_getting_module():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    j.load_plugin(j.get_manifest("Basic Test"))
    assert issubclass(j.get_module("Basic Test").Plugin, jigsaw.JigsawPlugin)
示例#20
0
def test_invalid_baseclass():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    j.load_plugin(j.get_manifest("Invalid Baseclass Test"))
    assert not j.get_plugin_loaded("Invalid Baseclass Test")
示例#21
0
def test_loading_plugin_already_loaded():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    j.load_plugin(j.get_manifest("Basic Test"))
    j.load_plugin(j.get_manifest("Basic Test"))
示例#22
0
def test_reload_specific_plugin():
    j = jigsaw.PluginLoader((os.path.abspath(
        os.path.join(os.path.abspath(__file__), "..", "plugins")), ))
    j.load_manifests()
    j.load_plugin(j.get_manifest("Basic Test"))
    j.reload_plugin("Basic Test")