示例#1
0
    def test_only_kwargs(self):
        pm = PluginManager("he")

        class Api:
            def hello(self, arg):
                "api hook 1"

        pm.addhooks(Api)
        pytest.raises(TypeError, lambda: pm.hook.hello(3))
示例#2
0
    def test_only_kwargs(self):
        pm = PluginManager("he")

        class Api:
            def hello(self, arg):
                "api hook 1"

        pm.addhooks(Api)
        pytest.raises(TypeError, lambda: pm.hook.hello(3))
示例#3
0
    def test_argmismatch(self):
        class Api:
            def hello(self, arg):
                "api hook 1"
        pm = PluginManager("he")
        pm.addhooks(Api)

        class Plugin:
            def hello(self, argwrong):
                pass

        with pytest.raises(PluginValidationError) as exc:
            pm.register(Plugin())
        assert "argwrong" in str(exc.value)
示例#4
0
    def test_firstresult_definition(self):
        class Api:
            def hello(self, arg):
                "api hook 1"
            hello.firstresult = True
        pm = PluginManager("he")
        pm.addhooks(Api)

        class Plugin:
            def hello(self, arg):
                return arg + 1

        pm.register(Plugin())
        res = pm.hook.hello(arg=3)
        assert res == 4
示例#5
0
    def test_argmismatch(self):
        class Api:
            def hello(self, arg):
                "api hook 1"

        pm = PluginManager("he")
        pm.addhooks(Api)

        class Plugin:
            def hello(self, argwrong):
                pass

        with pytest.raises(PluginValidationError) as exc:
            pm.register(Plugin())
        assert "argwrong" in str(exc.value)
示例#6
0
    def test_firstresult_definition(self):
        class Api:
            def hello(self, arg):
                "api hook 1"

            hello.firstresult = True

        pm = PluginManager("he")
        pm.addhooks(Api)

        class Plugin:
            def hello(self, arg):
                return arg + 1

        pm.register(Plugin())
        res = pm.hook.hello(arg=3)
        assert res == 4
示例#7
0
    def test_hapmypath(self):
        class Api:
            def hello(self, arg):
                "api hook 1"
        pm = PluginManager("he")
        pm.addhooks(Api)
        hook = pm.hook
        assert hasattr(hook, 'hello')
        assert repr(hook.hello).find("hello") != -1

        class Plugin:
            def hello(self, arg):
                return arg + 1

        plugin = Plugin()
        pm.register(plugin)
        l = hook.hello(arg=3)
        assert l == [4]
        assert not hasattr(hook, 'world')
        pm.unregister(plugin)
        assert hook.hello(arg=3) == []
示例#8
0
    def test_hapmypath(self):
        class Api:
            def hello(self, arg):
                "api hook 1"

        pm = PluginManager("he")
        pm.addhooks(Api)
        hook = pm.hook
        assert hasattr(hook, 'hello')
        assert repr(hook.hello).find("hello") != -1

        class Plugin:
            def hello(self, arg):
                return arg + 1

        plugin = Plugin()
        pm.register(plugin)
        l = hook.hello(arg=3)
        assert l == [4]
        assert not hasattr(hook, 'world')
        pm.unregister(plugin)
        assert hook.hello(arg=3) == []