Пример #1
0
 def wrap(func):
     project = test_plugin_manager.project_name
     HookImplementationMarker(project)(
         tryfirst=tryfirst,
         trylast=trylast,
         hookwrapper=hookwrapper,
         specname=specname,
     )(func)
     _specname = specname or func.__name__
     hook_caller = getattr(test_plugin_manager.hook, _specname, None)
     assert hook_caller, f"No hook with with name: {_specname}"
     opts = getattr(func, HookImplementation.format_tag(project))
     hook_caller._add_hookimpl(HookImplementation(func, **opts))
     return func
Пример #2
0
 def wrap(func, specname=None, *, tryfirst=True, trylast=None):
     project = test_plugin_manager.project_name
     marker = HookImplementationMarker(project)
     marker(tryfirst=tryfirst, trylast=trylast, specname=specname)(func)
     _specname = specname or func.__name__
     hook_caller = getattr(test_plugin_manager.hook, _specname, None)
     assert hook_caller, f"No hook with with name: {_specname}"
     opts = getattr(func, HookImplementation.format_tag(project))
     impl = HookImplementation(func, **opts)
     hook_caller._add_hookimpl(impl)
     try:
         yield hook_caller
     finally:
         if impl in hook_caller._nonwrappers:
             hook_caller._nonwrappers.remove(impl)
         if impl in hook_caller._wrappers:
             hook_caller._wrappers.remove(impl)
         assert impl not in hook_caller.get_hookimpls()
Пример #3
0
import pytest

from napari_plugin_engine import (
    HookImplementationMarker,
    HookSpecificationMarker,
    PluginManager,
)

dummy_hook_implementation = HookImplementationMarker("dummy")
dummy_hook_specification = HookSpecificationMarker("dummy")


class MySpec:
    @dummy_hook_specification
    def myhook(self):
        pass


class Plugin_1:
    @dummy_hook_implementation
    def myhook(self):
        return "p1"


class Plugin_2:
    @dummy_hook_implementation(tryfirst=True)
    def myhook(self):
        return "p2"


class Plugin_3:
import warnings

import pytest

from napari_plugin_engine import (
    HookImplementationMarker,
    HookSpecificationMarker,
    PluginManager,
)

hookspec = HookSpecificationMarker("example")
hookimpl = HookImplementationMarker("example")


def test_warn_when_deprecated_specified(recwarn):
    warning = DeprecationWarning("foo is deprecated")

    class Spec:
        @hookspec(warn_on_impl=warning)
        def foo(self):
            pass

    class Plugin:
        @hookimpl
        def foo(self):
            pass

    pm = PluginManager(hookspec.project_name)
    pm.add_hookspecs(Spec)

    with pytest.warns(DeprecationWarning) as records:
Пример #5
0
import pytest

from napari_plugin_engine import (
    HookCallError,
    HookImplementation,
    HookImplementationMarker,
    HookSpecificationMarker,
)
from napari_plugin_engine.callers import _multicall

hookspec = HookSpecificationMarker("example")
example_implementation = HookImplementationMarker("example")


def multicall(methods, kwargs, firstresult=False):
    """utility function to execute the hook implementations loop"""
    caller = _multicall
    hookfuncs = []
    for method in methods:
        f = HookImplementation(method, **method.example_impl)
        hookfuncs.append(f)
    # our _multicall function returns our own HookResult object.
    # so to make these pluggy tests pass, we have to access .result to mimic
    # the old behavior (that directly returns results).
    return caller(hookfuncs, kwargs, firstresult=firstresult).result


def test_multicall_passing():
    class Plugin1:
        @example_implementation
        def method(self, x):