Example #1
0
def test_discover_ignore_txt():
    """test that files ending with .txt are ignored if not told."""
    discoverer = PluginDiscoverer([TEST_TXT_PLUGIN_PATH], extensions=[".py"])
    assert discoverer.loaded == 0
    assert discoverer.enabled == 0
    discoverer.load_plugins()
    assert discoverer.loaded == 0
    assert discoverer.enabled == 0
Example #2
0
def test_ignore_errors_true():
    """test ignore_errors=true argument for PluginDiscoverer()"""
    discoverer = PluginDiscoverer([TEST_ERROR_PLUGIN_PATH], ignore_errors=True)
    discoverer.load_plugins()
    assert discoverer.loaded > 0
    assert discoverer.enabled > 0
    assert discoverer.errors > 0
    assert len(discoverer.error_paths) == 1
    assert "not_working_plugin.py" in discoverer.error_paths[0]
Example #3
0
def test_discover_include_txt():
    """test that files ending with .txt are loaded if specified."""
    discoverer = PluginDiscoverer([TEST_TXT_PLUGIN_PATH], extensions=[".txt"])
    discoverer.load_plugins()
    loaded = discoverer.loaded
    enabled = discoverer.enabled
    assert loaded > 0
    assert enabled > 0
    plugin = discoverer.get_implementation(ITestPlugin)
    assert ITestPlugin.implementedBy(plugin)
    pi = plugin()
    assert pi.get_id() == "test_txt_plugin"
Example #4
0
def test_load_compiled():
    """test for loading .pyc plugins."""
    discoverer = PluginDiscoverer(paths=[TEST_PYC_PLUGIN_PATH],
                                  extensions=[".pyc", ".pyo"])

    # if old compiled module exists, delete it
    outpath = TEST_PYC_RAW_PLUGIN_PATH + "c"  # see py_compile.compile() defaults
    if os.path.exists(outpath):
        os.remove(outpath)

    # test that .py wont be loaded
    discoverer.load_plugins(max_depth=0)
    assert discoverer.loaded == 0
    assert discoverer.enabled == 0

    # compile module
    py_compile.compile(TEST_PYC_RAW_PLUGIN_PATH, cfile=outpath)

    # test that .pyc will be loaded
    discoverer.load_plugins(max_depth=0)
    assert discoverer.loaded > 0
    assert discoverer.enabled > 0

    # test plugin
    plugin = discoverer.get_implementation(ITestPlugin,
                                           exclude=[TestPluginForExlusion])
    pi = plugin()
    assert pi.get_id() == "test_pyc_plugin"
Example #5
0
def test_ignore_errors_false():
    """test ignore_errors=False argument for PluginDiscoverer()"""
    discoverer = PluginDiscoverer([TEST_ERROR_PLUGIN_PATH],
                                  ignore_errors=False)
    try:
        # this should fail
        discoverer.load_plugins()
    except (Exception, SyntaxError):
        # expected
        pass
    else:
        # test failed
        raise AssertionError(
            ".load_plugins() did not fail when loading faulty plugins with ignore_errors=False"
        )
    assert discoverer.errors > 0
    assert len(discoverer.error_paths) == 1
    assert "not_working_plugin.py" in discoverer.error_paths[0]
Example #6
0
def test_discover_include():
    """test that the include parameter for PluginDiscoverer works."""
    # 1. check that the plugin is not loaded anyways
    discoverer = PluginDiscoverer([TEST_PLUGIN_PATH])
    discoverer.load_plugins()
    loaded = discoverer.loaded
    enabled = discoverer.enabled
    assert loaded > 0
    assert enabled > 0
    plugins = discoverer.get_all_plugins(ITestPlugin)
    assert TestPluginForInclusion not in plugins
    # 2. repeat, but include plugin
    discoverer = PluginDiscoverer([TEST_PLUGIN_PATH],
                                  include=[TestPluginForInclusion])
    discoverer.load_plugins()
    loaded = discoverer.loaded
    enabled = discoverer.enabled
    assert loaded > 0
    assert enabled > 0
    plugins = discoverer.get_all_plugins(ITestPlugin)
    assert TestPluginForInclusion in plugins
Example #7
0
def test_test_plugin_integrity():
    """test to ensure the test plugins work (or not, if that is required)."""
    # main test plugins
    d1 = get_discoverer()
    d1.load_plugins()
    assert d1.loaded != 0
    assert d1.enabled != 0
    assert d1.errors == 0

    # txt test plugins
    d2 = PluginDiscoverer([TEST_TXT_PLUGIN_PATH], extensions=[".txt"])
    d2.load_plugins()
    assert d2.loaded != 0
    assert d2.enabled != 0
    assert d2.errors == 0

    # error test plugins
    d2 = PluginDiscoverer([TEST_ERROR_PLUGIN_PATH],
                          extensions=[".py"],
                          ignore_errors=True)
    d2.load_plugins()
    assert d2.loaded != 0
    assert d2.enabled != 0
    assert d2.errors != 0
Example #8
0
def get_discoverer():
    """returns a PluginDiscoverer."""
    discoverer = PluginDiscoverer([TEST_PLUGIN_PATH])
    return discoverer