Esempio n. 1
0
File: main.py Progetto: vartec/devpi
def get_pluginmanager(load_entry_points=True):
    pm = PluginManager("devpiclient", implprefix="devpiclient_")
    pm.add_hookspecs(hookspecs)
    if load_entry_points:
        pm.load_setuptools_entrypoints("devpi_client")
    pm.check_pending()
    return pm
Esempio n. 2
0
class WebView(object):
    def __init__(self, driver, timeout, pm=None):
        self.driver = driver
        self.driver_adapter = IDriver(driver)
        self.timeout = timeout
        self.pm = pm
        if self.pm is None:
            self.pm = PluginManager("pypom", implprefix="pypom_")
            self.pm.add_hookspecs(hooks)
            self.pm.load_setuptools_entrypoints("pypom.plugin")
            self.pm.check_pending()
        self.wait = self.driver_adapter.wait_factory(self.timeout)

    @property
    def selenium(self):
        """Backwards compatibility attribute"""
        warn("use driver instead", DeprecationWarning, stacklevel=2)
        return self.driver

    def find_element(self, strategy, locator):
        return self.driver_adapter.find_element(strategy, locator)

    def find_elements(self, strategy, locator):
        """Finds elements on the page.

        :param strategy: Location strategy to use. See :py:class:`~selenium.webdriver.common.by.By` or :py:attr:`~pypom.splinter_driver.ALLOWED_STRATEGIES`.
        :param locator: Location of target elements.
        :type strategy: str
        :type locator: str
        :return: List of :py:class:`~selenium.webdriver.remote.webelement.WebElement` or :py:class:`~splinter.element_list.ElementList`
        :rtype: list

        """
        return self.driver_adapter.find_elements(strategy, locator)

    def is_element_present(self, strategy, locator):
        """Checks whether an element is present.

        :param strategy: Location strategy to use. See :py:class:`~selenium.webdriver.common.by.By` or :py:attr:`~pypom.splinter_driver.ALLOWED_STRATEGIES`.
        :param locator: Location of target element.
        :type strategy: str
        :type locator: str
        :return: ``True`` if element is present, else ``False``.
        :rtype: bool

        """
        return self.driver_adapter.is_element_present(strategy, locator)

    def is_element_displayed(self, strategy, locator):
        """Checks whether an element is displayed.

        :param strategy: Location strategy to use. See :py:class:`~selenium.webdriver.common.by.By` or :py:attr:`~pypom.splinter_driver.ALLOWED_STRATEGIES`.
        :param locator: Location of target element.
        :type strategy: str
        :type locator: str
        :return: ``True`` if element is displayed, else ``False``.
        :rtype: bool

        """
        return self.driver_adapter.is_element_displayed(strategy, locator)
Esempio n. 3
0
def get_pluginmanager():
    pm = PluginManager("devpiserver", implprefix="devpiserver_")
    pm.add_hookspecs(hookspecs)
    # XXX load internal plugins here
    pm.load_setuptools_entrypoints("devpi_server")
    pm.check_pending()
    return pm
Esempio n. 4
0
def get_pluginmanager(load_entry_points=True):
    pm = PluginManager("devpipasswdreset", implprefix="devpipasswdreset_")
    pm.add_hookspecs(hookspecs)
    if load_entry_points:
        pm.load_setuptools_entrypoints("devpi_passwd_reset")
    pm.check_pending()
    return pm
def get_pluggin_manager(load_entrypoints=True):
    pm = PluginManager('banana', implprefix='banana_')
    pm.add_hookspecs(hookspecs)
    if load_entrypoints:
        pm.load_setuptools_entrypoints('banana')
    pm.check_pending()
    return pm
Esempio n. 6
0
def test_hookrelay_registration_by_specname_raises(pm: PluginManager) -> None:
    """Verify using specname still raises the types of errors during registration as it
    would have without using specname."""
    class Api:
        @hookspec
        def hello(self, arg: object) -> None:
            "api hook 1"

    pm.add_hookspecs(Api)

    # make sure a bad signature still raises an error when using specname
    class Plugin:
        @hookimpl(specname="hello")
        def foo(self, arg: int, too, many, args) -> int:
            return arg + 1

    with pytest.raises(PluginValidationError):
        pm.register(Plugin())

    # make sure check_pending still fails if specname doesn't have a
    # corresponding spec.  EVEN if the function name matches one.
    class Plugin2:
        @hookimpl(specname="bar")
        def hello(self, arg: int) -> int:
            return arg + 1

    pm.register(Plugin2())
    with pytest.raises(PluginValidationError):
        pm.check_pending()
Esempio n. 7
0
def test_prefix_hookimpl_dontmatch_module():
    pm = PluginManager(hookspec.project_name, "hello_")

    class BadPlugin(object):
        hello_module = __import__('email')

    pm.register(BadPlugin())
    pm.check_pending()
Esempio n. 8
0
def get_pluginmanager(load_entrypoints=True):
    pm = PluginManager("devpiserver", implprefix="devpiserver_")
    pm.add_hookspecs(hookspecs)
    # XXX load internal plugins here
    if load_entrypoints:
        pm.load_setuptools_entrypoints("devpi_server")
    pm.check_pending()
    return pm
Esempio n. 9
0
def get_pluginmanager(config, load_entry_points=True):
    pm = PluginManager("devpiweb")
    # support old plugins, but emit deprecation warnings
    pm._implprefix = "devpiweb_"
    pm.add_hookspecs(hookspecs)
    if load_entry_points:
        pm.load_setuptools_entrypoints("devpi_web")
    pm.check_pending()
    return pm
Esempio n. 10
0
def test_prefix_hookimpl_dontmatch_module():
    with pytest.deprecated_call():
        pm = PluginManager(hookspec.project_name, "hello_")

    class BadPlugin(object):
        hello_module = __import__("email")

    pm.register(BadPlugin())
    pm.check_pending()
Esempio n. 11
0
def get_pluginmanager(load_entrypoints=True):
    pm = PluginManager("devpiserver")
    # support old plugins, but emit deprecation warnings
    pm._implprefix = "devpiserver_"
    pm.add_hookspecs(hookspecs)
    # XXX load internal plugins here
    if load_entrypoints:
        pm.load_setuptools_entrypoints("devpi_server")
    pm.check_pending()
    return pm
Esempio n. 12
0
def test_register_mismatch_method(he_pm: PluginManager) -> None:
    class hello:
        @hookimpl
        def he_method_notexists(self):
            pass

    plugin = hello()

    he_pm.register(plugin)
    with pytest.raises(PluginValidationError) as excinfo:
        he_pm.check_pending()
    assert excinfo.value.plugin is plugin
Esempio n. 13
0
def get_pluginmanager(config, load_entry_points=True):
    # lookup cached value
    pm = getattr(config, 'devpiweb_pluginmanager', None)
    if pm is not None:
        return pm
    pm = PluginManager("devpiweb")
    # support old plugins, but emit deprecation warnings
    pm._implprefix = "devpiweb_"
    pm.add_hookspecs(hookspecs)
    if load_entry_points:
        pm.load_setuptools_entrypoints("devpi_web")
    pm.check_pending()
    # cache the expensive setup
    config.devpiweb_pluginmanager = pm
    return pm