File test/bind.py artifact bdb0475b8c part of check-in 8b8e58b0e7


# type: test
# title: bind loader
# description: simple loader mechanism
# version: 0.1
# 
# Utilize plugins/


import pytest
import logging
logging.basicConfig(level=logging.DEBUG)
import pluginconf
print(pluginconf.plugin_base)
import pluginconf.bind


def init(reset):
#    pluginconf.plugin_base = []
    import test.plugins
    pluginconf.bind.base(test.plugins)
    assert "test.plugins" in pluginconf.plugin_base
    assert test.plugins.__path__ != []

def test_first():
    assert pluginconf.plugin_meta(module="first").title == "first plugin"

def find_plugins():
    assert len(pluginconf.bind.find(type="stub")) == 3

def config_set():
    conf = {
        "first_run": 1,
        "plugins": {
        },
    }
    pluginconf.bind.defaults(conf)
    assert conf["injected"] is True  # converted from "1"
    assert conf["plugins"]["core"] == True  # priority core

def load_first():
    conf = {
        "plugins": {
            "first": True,
        },
    }
    for mod in pluginconf.bind.load_enabled(conf):
        assert mod.init

def context():
    with pluginconf.bind.isolated("test.plugins") as ext:
        assert len(ext.find(type="stub")) == 3
        assert ext.run.init() == 4

def tearDown(reset):
    pass