Exemplo n.º 1
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_17_subtype_ordering():
    system = pyitect.get_system()

    for sub in system.iter_component_subtypes("a"):
        tools.ok_(sub in ("a.b", "a.b.c"))

    for prov in system.iter_component_providers("a"):
        tools.eq_(len(prov), 3)
        tools.ok_(prov[0] in ("a", "a.b", "a.b.c"))
        tools.eq_(prov[1], "subtype_plugin")

    def key1(prov):
        return (prov[0].split(".")[-1])

    def key2(prov):
        return (0 if prov[0] == "a.b" else 1)

    a = system.load("a")
    tools.eq_(a(), "A")

    a = system.load("a", key=key1, reverse=True)
    tools.eq_(a(), "ABC")

    a = system.load("a", key=key2)
    tools.eq_(a(), "AB")
Exemplo n.º 2
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_15_unique_module_names():
    system = pyitect.get_system()

    TestClass = system.load("TestClass")

    print(TestClass.__module__)
    tools.assert_not_equal(
        TestClass.__module__, "relative_plugin.relative_test")
Exemplo n.º 3
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_02_search_plugins():
    system = pyitect.get_system()
    global folder_path

    tools.ok_(not system.plugins)

    system.search(os.path.join(folder_path, "plugins"))

    tools.ok_(len(system.plugins) > 0)
Exemplo n.º 4
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_01_bind_events():
    system = pyitect.get_system()
    tools.ok_(not system.events)

    def onPluginFound(path, plugin):
        """
        path : the full path to the folder containing the plugin
        plugin : plugin version string (ie 'plugin_name:version')
        """
        global pluginFoundTriggered
        print("plugin `%s` found at `%s`" % (plugin, path))
        pluginFoundTriggered = True

    def onPluginLoad(plugin, plugin_required, component_needed):
        """
        plugin : plugin version string (ie 'plugin_name:version')
        plugin_required: version string of the plugin that required the loaded
            plugin (version string ie 'plugin_name:version') (might be None)
        component_needed: the name of the component needed by the requesting
        plugin
        """
        global pluginLoadTriggered
        print(
            "plugin `%s` was loaded by plugin `%s` "
            "during a request for the `%s` component"
            % (plugin, plugin_required, component_needed)
            )
        pluginLoadTriggered = True

    def onComponentLoad(component, plugin_required, plugin_loaded):
        """
        component : the name of the component loaded
        plugin_required : version string of the plugin that required the loaded
            component (version string ie 'plugin_name:version') (might be None)
        plugin_loaded : version string of the plugin that the component was
        loaded
            from (version string ie 'plugin_name:version')
        """
        global componentLoadTriggered
        print(
            "Component `%s` loaded, required by `%s`, loaded from `%s`"
            % (component, plugin_required, plugin_loaded)
            )
        componentLoadTriggered = True

    system.bind_event('plugin_found', onPluginFound)
    system.bind_event('plugin_loaded', onPluginLoad)
    system.bind_event('component_loaded', onComponentLoad)

    tools.ok_('plugin_found' in system.events)
    tools.ok_('plugin_loaded' in system.events)
    tools.ok_('component_loaded' in system.events)
Exemplo n.º 5
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_03_enable_plugins():
    system = pyitect.get_system()

    tools.ok_(not system.components)
    tools.ok_(not system.enabled_plugins)

    plugins_filter = ["bad_plugin"]
    # get all plugin configs that arn't named dead_plugin
    # collect plugins[<name>][<version_str>] for all names n in plugins for all
    # versions v in plugins[n] if name not in filter
    plugins = [
        system.plugins[n][v]
        for n in system.plugins
        for v in system.plugins[n]
        if n not in plugins_filter
        ]

    system.enable_plugins(plugins)

    tools.ok_(len(system.component_map) > 0)
    tools.ok_(len(system.enabled_plugins) > 0)
Exemplo n.º 6
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_09_components_subtypes():
    system = pyitect.get_system()
    versions = []
    components = []

    subtypes = ("test.test1", "test.test2", "test.test3")

    for subtype in system.iter_component_subtypes("test"):
        tools.ok_(subtype in subtypes)

    for prov in system.iter_component_providers("test", subs=True):
        comp, plugin, version = prov
        version_string = comp + ":" + plugin + ":" + str(version)

        tools.ok_(version_string not in versions)

        versions.append(version_string)

        test = system.load_component(comp, plugin, version)

        tools.ok_(inspect.isfunction(test))
        tools.ok_(test not in components)

        components.append(test)
Exemplo n.º 7
0
Arquivo: test.py Projeto: Ryex/pyitect
 def enable_plugin():
     system = pyitect.get_system()
     system.load_plugin("bad_plugin", "0.0.1")
Exemplo n.º 8
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_13_yaml_plugin():
    system = pyitect.get_system()
    foo_yaml = system.load("foo_yaml")
    tools.eq_(foo_yaml("testmessage"), "testmessageyaml")
Exemplo n.º 9
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_11_fetch_plugin_module():
    system = pyitect.get_system()
    module = system.get_plugin_module("provide_plugin")
    tools.ok_(inspect.ismodule(module))
Exemplo n.º 10
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_10_relative_import():
    system = pyitect.get_system()
    TestClass = system.load("TestClass")
    tools.ok_(inspect.isclass(TestClass))
    T = TestClass("testmessage")
    tools.eq_(T.hello(), "testmessage")
Exemplo n.º 11
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_08_consume_foo():
    system = pyitect.get_system()
    foobar = system.load("foobar")
    tools.ok_(inspect.isfunction(foobar))
    tools.eq_(foobar(), "foobar")
Exemplo n.º 12
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_07_provide_foov2():
    system = pyitect.get_system()
    foo = system.load("foo", {"foo": "provide_plugin:==2.0.0"})
    tools.ok_(inspect.isfunction(foo))
    tools.eq_(foo(), "foo2")
Exemplo n.º 13
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_06_provide_foo():
    system = pyitect.get_system()
    foo = system.load("foo")
    tools.ok_(inspect.isfunction(foo))
    tools.eq_(foo(), "foo")
Exemplo n.º 14
0
Arquivo: test.py Projeto: Ryex/pyitect
 def load_component(name):
     system = pyitect.get_system()
     return system.load(name)
Exemplo n.º 15
0
Arquivo: test.py Projeto: Ryex/pyitect
def test_04_filter_plugins():
    system = pyitect.get_system()
    tools.ok_("bad_plugin" in system.plugins)
    tools.ok_("bad_plugin" not in system.enabled_plugins)