def he_pm(request, pm: PluginManager) -> PluginManager: hookspec = HookspecMarker("example") class Hooks: @hookspec def he_method1(self, arg: int) -> int: return arg + 1 pm.add_hookspecs(request.param(Hooks)) return pm
def he_pm(request, pm): from pluggy import HookspecMarker hookspec = HookspecMarker("example") class Hooks(object): @hookspec def he_method1(self, arg): return arg + 1 pm.add_hookspecs(request.param(Hooks)) return pm
class MyPlugin(object): hookspec = HookspecMarker("pytest") def __init__(self): Logger.log('Automation Suite Execution Starts...') @pytest.hookimpl(tryfirst=True, hookwrapper=True) def pytest_runtest_makereport(item, call): outcome = yield rep = outcome.get_result() if rep.when == 'call' or (rep.when == 'setup' and rep.outcome in ['failed', 'skipped']): classRunning = str(rep).split('::')[1] testCaseName = str(rep).split('::')[-1].split( 'when')[0].rstrip().replace("'", '') status = rep.outcome timeTaken = rep.duration executionInfo = call.excinfo screenshot = '' if status == 'failed': path = constant.config['logDir'] + '/' + str( testCaseName) + '.png' if os.path.exists(path): screenshot = str(testCaseName) + '.png' if executionInfo is None: executionInfo = '' else: executionInfo = str(executionInfo) if constant.config['validataionMessage'] != []: #executionInfo += '\n'.join(set(constant.config['validataionMessage'])) executionInfo = str(executionInfo) resultDict = { classRunning: { testCaseName: { 'status': status, 'time': str(timeTaken), 'validataionMessage': executionInfo, 'screenshot': screenshot, 'comments': '' } } } Logger.logCollectorRequest(resultDict, 'result') setattr(item, "rep_" + rep.when, rep)
from _pytest.fixtures import FixtureDef from _pytest.fixtures import SubRequest from _pytest.main import Session from _pytest.nodes import Collector from _pytest.nodes import Item from _pytest.outcomes import Exit from _pytest.python import Function from _pytest.python import Metafunc from _pytest.python import Module from _pytest.python import PyCollector from _pytest.reports import CollectReport from _pytest.reports import TestReport from _pytest.runner import CallInfo from _pytest.terminal import TerminalReporter hookspec = HookspecMarker("pytest") # ------------------------------------------------------------------------- # Initialization hooks called for every plugin # ------------------------------------------------------------------------- @hookspec(historic=True) def pytest_addhooks(pluginmanager: "PytestPluginManager") -> None: """Called at plugin registration time to allow adding new hooks via a call to ``pluginmanager.add_hookspecs(module_or_class, prefix)``. :param _pytest.config.PytestPluginManager pluginmanager: pytest plugin manager. .. note:: This hook is incompatible with ``hookwrapper=True``.
from pluggy import HookimplMarker from pluggy import HookspecMarker hookspec = HookspecMarker('datasette') hookimpl = HookimplMarker('datasette') @hookspec def prepare_connection(conn): "Modify SQLite connection in some way e.g. register custom SQL functions" @hookspec def prepare_jinja2_environment(env): "Modify Jinja2 template environment e.g. register custom template tags" @hookspec def extra_css_urls(): "Extra CSS URLs added by this plugin" @hookspec def extra_js_urls(): "Extra JavaScript URLs added by this plugin"
""" Hook specifications for tox. """ from pluggy import HookspecMarker, HookimplMarker hookspec = HookspecMarker("tox") hookimpl = HookimplMarker("tox") @hookspec def tox_addoption(parser): """ add command line options to the argparse-style parser object.""" @hookspec def tox_configure(config): """ called after command line options have been parsed and the ini-file has been read. Please be aware that the config object layout may change as its API was not designed yet wrt to providing stability (it was an internal thing purely before tox-2.0). """ @hookspec(firstresult=True) def tox_get_python_executable(envconfig): """ return a python executable for the given python base name. The first plugin/hook which returns an executable path will determine it. ``envconfig`` is the testenv configuration which contains per-testenv configuration, notably the ``.envname`` and ``.basepython`` setting.
# -*- coding: utf-8 -*- """ flaskbb.plugins.spec ~~~~~~~~~~~~~~~~~~~~~~~ This module provides the core FlaskBB plugin hook definitions :copyright: (c) 2017 by the FlaskBB Team. :license: BSD, see LICENSE for more details. """ from pluggy import HookspecMarker spec = HookspecMarker("flaskbb") # Setup Hooks @spec def flaskbb_extensions(app): """Hook for initializing any plugin loaded extensions.""" @spec def flaskbb_load_translations(): """Hook for registering translation folders.""" @spec def flaskbb_load_migrations(): """Hook for registering additional migrations."""
from pluggy import HookspecMarker hookspec = HookspecMarker("devpiserver") @hookspec def devpiserver_add_parser_options(parser): """ called before command line parsing to allow plugins to add options through a call to parser.add_argument(). """ @hookspec(firstresult=True) def devpiserver_cmdline_run(xom): """ return an integer with a success code (0 == no errors) if you handle the command line invocation, otherwise None. When the first plugin returns an integer, the remaining plugins are not called.""" @hookspec def devpiserver_get_features(): """ return set containing strings with ids of supported features. This is returned in the result of /+api to allow devpi-client to use functionality provided by newer devpi-server versions or added by plugins. """ @hookspec def devpiserver_storage_backend(settings):
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from pluggy import HookspecMarker hookspec = HookspecMarker('pypom') @hookspec def pypom_after_wait_for_page_to_load(page): """Called after waiting for the page to load""" @hookspec def pypom_after_wait_for_region_to_load(region): """Called after waiting for the region to load"""
import logging from datetime import datetime import pathlib import sys import os from pathlib import Path from pluggy import HookspecMarker, HookimplMarker, PluginManager from baangt.base.PathManagement import ManagedPaths hook_spec = HookspecMarker("baangt") hook_impl = HookimplMarker("baangt") plugin_manager = PluginManager("baangt") from baangt.hookSpecs import baangtHookSpec plugin_manager.add_hookspecs(baangtHookSpec) from baangt.base.TestRun.hookImpls import TestRunHookImpl from baangt.base.BrowserHandling.hookImpls import BrowserDriverHookImpl from baangt.base.Timing.hookImpls import TimingHookImpl from baangt.base.ExportResults.hookImpls import \ (ExportResultsHookImpl, ExcelSheetHelperFunctionsHookImpl, ExportTimingHookImpl) plugin_manager.register(plugin=TestRunHookImpl()) plugin_manager.register(plugin=BrowserDriverHookImpl()) plugin_manager.register(plugin=TimingHookImpl()) plugin_manager.register(plugin=ExportResultsHookImpl()) plugin_manager.register(plugin=ExcelSheetHelperFunctionsHookImpl()) plugin_manager.register(plugin=ExportTimingHookImpl()) # fixme: Parameter für Logfile should include stage and browser()
# ScanCode should be considered or used as legal advice. Consult an Attorney # for any legal advice. # ScanCode is a free software code scanning tool from nexB Inc. and others. # Visit https://github.com/nexB/scancode-toolkit/ for support and download. from __future__ import absolute_import from __future__ import unicode_literals from collections import OrderedDict import sys from pluggy import HookimplMarker from pluggy import HookspecMarker from pluggy import PluginManager pre_scan_spec = HookspecMarker('pre_scan') pre_scan_impl = HookimplMarker('pre_scan') @pre_scan_spec class PreScanPlugin(object): """ A pre-scan plugin layout class to be extended by the pre_scan plugins. Docstring of a plugin class will be used as the plugin option's help text """ # attributes to be used while creating the option for this plugin. option_attrs = {} def __init__(self, user_input): self.user_input = user_input
from pluggy import HookspecMarker, HookimplMarker hookspec = HookspecMarker("mpeb") hookimpl = HookimplMarker("mpeb") @hookspec() def mpeb_setup(): """just a place to handle pre confit stuff""" @hookspec() def mpeb_addsubparser(parser): """register subcommands""" @hookspec() def mpeb_addoption(parser): """register arparse-style options""" @hookspec() def mpeb_cmdline_main(config): """the run loop""" @hookspec() def mpeb_prerun_main(config): """wrap things here"""
# ScanCode should be considered or used as legal advice. Consult an Attorney # for any legal advice. # ScanCode is a free software code scanning tool from nexB Inc. and others. # Visit https://github.com/nexB/scancode-toolkit/ for support and download. from __future__ import absolute_import from __future__ import unicode_literals from collections import OrderedDict import sys from pluggy import HookimplMarker from pluggy import HookspecMarker from pluggy import PluginManager post_scan_spec = HookspecMarker('post_scan') post_scan_impl = HookimplMarker('post_scan') @post_scan_spec def post_scan_handler(active_scans, results): """ Process the scanned files and yield the modified results. Parameters: - `active_scans`: a list of scanners names requested in the current run. - `results`: an iterable of scan results for each file or directory. """ pass post_scan_plugins = PluginManager('post_scan')
from pluggy import HookspecMarker spec = HookspecMarker('app') @spec def app_load_blueprints(app): """Hook for registering blueprints."""
""" hook specifications for stemcode plugins, invoked from main.py and builtin plugins. """ from pluggy import HookspecMarker hookspec = HookspecMarker("stemcode") # ------------------------------------------------------------------------- # Initialization hooks called for every plugin # ------------------------------------------------------------------------- @hookspec(historic=True) def stemcode_addhooks(pluginmanager): """called at plugin registration time to allow adding new hooks via a call to ``pluginmanager.add_hookspecs(module_or_class, prefix)``. :param _stemcode.config.StemcodePluginManager pluginmanager: stemcode plugin manager .. note:: This hook is incompatible with ``hookwrapper=True``. """ @hookspec(historic=True) def stemcode_namespace(): """ (**Deprecated**) this hook causes direct monkeypatching on stemcode, its use is strongly discouraged return dict of name->object to be made globally available in the stemcode namespace.
from pluggy import HookspecMarker hookspec = HookspecMarker("devpiclient") @hookspec(firstresult=True) def devpiclient_get_password(url, username): """Called when password is needed for login. Returns the password if there is one, or None if no match is found. """
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # pylint: disable=C0103,W0613 """ Hook specifications for ``PyDeployer```. .. moduleauthor:: Joseph Benden <*****@*****.**> :copyright: (c) Copyright 2018 by Joseph Benden. :license: Apache License 2.0, see LICENSE for full details. """ from pluggy import HookspecMarker hookspec = HookspecMarker("deployer") @hookspec def deployer_register(registry): # noqa: D401 """A hook available for a plug-in to perform its' registration."""
""" hook specifications for kgen_lang plugins, invoked from main.py and builtin plugins. """ from pluggy import HookspecMarker hookspec = HookspecMarker("kgen_lang") # ------------------------------------------------------------------------- # Initialization hooks called for every plugin # ------------------------------------------------------------------------- @hookspec(historic=True) def kgen_lang_addhooks(pluginmanager): """called at plugin registration time to allow adding new hooks via a call to ``pluginmanager.add_hookspecs(module_or_class, prefix)``. :param _kgen_lang.config.KGenLangPluginManager pluginmanager: kgen_lang plugin manager .. note:: This hook is incompatible with ``hookwrapper=True``. """ @hookspec(historic=True) def kgen_lang_namespace(): """ (**Deprecated**) this hook causes direct monkeypatching on kgen_lang, its use is strongly discouraged return dict of name->object to be made globally available in the kgen_lang namespace.
from pluggy import HookspecMarker, HookimplMarker hookspec = HookspecMarker("allure") hookimpl = HookimplMarker("allure") class AllureUserHooks(object): @hookspec def decorate_as_title(self, test_title): """ title """ @hookspec def add_title(self, test_title): """ title """ @hookspec def decorate_as_description(self, test_description): """ description """ @hookspec def add_description(self, test_description): """ description """ @hookspec def decorate_as_description_html(self, test_description_html): """ description html""" @hookspec def add_description_html(self, test_description_html): """ description html"""
"""Tag plugger.""" from pluggy import HookspecMarker, HookimplMarker, PluginManager hookspec = HookspecMarker('Tag Plug') environment_hooks = PluginManager('Tag Plug') tag_behavior = HookimplMarker("Tag Plug") class BDDHooks: @hookspec def before_all(self, context): ... @hookspec def before_feature(self, context, feature): ... @hookspec def before_scenario(self, context, scenario): ... @hookspec def before_tag(self, context, tag): ... @hookspec def before_step(self, context, step): ... @hookspec def after_all(self, context):
from pluggy import HookimplMarker from pluggy import HookspecMarker hookspec = HookspecMarker("datasette") hookimpl = HookimplMarker("datasette") @hookspec def startup(datasette): """Fires directly after Datasette first starts running""" @hookspec def get_metadata(datasette, key, database, table): """Return metadata to be merged into Datasette's metadata dictionary""" @hookspec def asgi_wrapper(datasette): """Returns an ASGI middleware callable to wrap our ASGI application with""" @hookspec def prepare_connection(conn, database, datasette): """Modify SQLite connection in some way e.g. register custom SQL functions""" @hookspec def prepare_jinja2_environment(env): """Modify Jinja2 template environment e.g. register custom template tags"""
import pytest from napari_plugins import HookimplMarker from pluggy import HookspecMarker from napari.plugins.manager import PluginManager dummy_hook_implementation = HookimplMarker("dummy") dummy_hook_specification = HookspecMarker("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: @dummy_hook_implementation def myhook(self):
# -*- coding: utf-8 -*- """ flaskbb.plugins.spec ~~~~~~~~~~~~~~~~~~~~~~~ This module provides the core FlaskBB plugin hook definitions :copyright: (c) 2017 by the FlaskBB Team. :license: BSD, see LICENSE for more details. """ from pluggy import HookspecMarker spec = HookspecMarker('flaskbb') # Setup Hooks @spec def flaskbb_extensions(app): """Hook for initializing any plugin loaded extensions.""" @spec def flaskbb_load_translations(): """Hook for registering translation folders.""" @spec def flaskbb_load_migrations(): """Hook for registering additional migrations."""
# for any legal advice. # ScanCode is a free software code scanning tool from nexB Inc. and others. # Visit https://github.com/nexB/scancode-toolkit/ for support and download. from __future__ import absolute_import from __future__ import print_function from __future__ import unicode_literals from collections import OrderedDict import sys from pluggy import HookimplMarker from pluggy import HookspecMarker from pluggy import PluginManager scan_output_spec = HookspecMarker('scan_output_writer') scan_output_writer = HookimplMarker('scan_output_writer') # FIXME: simplify the hooskpec @scan_output_spec def write_output(files_count, version, notice, scanned_files, options, input, output_file, _echo): """ Write the `scanned_files` scan results in the format supplied by the --format command line option. Parameters: - `file_count`: the number of files and directories scanned. - `version`: ScanCode version - `notice`: ScanCode notice - `scanned_files`: an iterable of scan results for each file
""" ``PluginManager`` unit and public API testing. """ import pytest import types import sys from pluggy import ( PluginManager, PluginValidationError, HookCallError, HookimplMarker, HookspecMarker, ) hookspec = HookspecMarker("example") hookimpl = HookimplMarker("example") def test_plugin_double_register(pm): """Registering the same plugin more then once isn't allowed""" pm.register(42, name="abc") with pytest.raises(ValueError): pm.register(42, name="abc") with pytest.raises(ValueError): pm.register(42, name="def") def test_pm(pm): """Basic registration with objects""" class A(object): pass
from typing import List from typing import Union from pluggy import HookspecMarker from alfasim_sdk import ErrorMessage from alfasim_sdk import WarningMessage from alfasim_sdk._internal.context import Context from alfasim_sdk._internal.variables import SecondaryVariable hookspec = HookspecMarker("ALFAsim") @hookspec def alfasim_get_data_model_type(): """ This hook allows the creation of models in ALFAsim, models can: - Customize items on ALFAsim application, by adding new components over the Tree. - Hold input data information to be accessed from the solver. - Validate input data or configuration made on ALFAsim, to ensure that the plugin has all configuration necessary to be run successfully. This hook needs to return a class decorated with one of the following options: - :func:`alfasim_sdk.models.container_model` - :func:`alfasim_sdk.models.data_model` The image below shows the locations where a custom model can be inserted implementing the hook. .. image:: /_static/images/hooks/tree_plugin_marker.png :scale: 80%
from pluggy import HookspecMarker hookspec = HookspecMarker("devpiweb") @hookspec def devpiweb_get_status_info(request): """Called on every request to gather status information. Returns a list of dictionaries with keys ``status`` and ``msg``, where status is ``warn`` or ``fatal``. """
# -*- coding: utf-8 -*- """ flaskpet.plugins.spec ~~~~~~~~~~~~~~~~~~~~~~~ This module provides the core FlaskPet plugin hook definitions :copyright: (c) 2017 by the FlaskPet Team. :license: BSD, see LICENSE for more details. """ from pluggy import HookspecMarker spec = HookspecMarker("flaskpet") # Setup Hooks @spec def flaskpet_extensions(app): """Hook for initializing any plugin loaded extensions.""" @spec def flaskpet_load_translations(): """Hook for registering translation folders.""" @spec def flaskpet_load_migrations(): """Hook for registering additional migrations."""
from pluggy import HookspecMarker spec = HookspecMarker("flaskshop") @spec def flaskshop_load_blueprints(app): """Hook for registering blueprints. :param app: The application object. """ @spec def flaskbb_tpl_user_nav_loggedin_before(): """Hook for registering additional user navigational items which are only shown when a user is logged in. in :file:`templates/layout.html`. """
from typing import Dict from pluggy import HookspecMarker from cfripper.rules.base_rules import Rule hookspec = HookspecMarker("cfripper") @hookspec def cfripper_get_rules() -> Dict[str, Rule]: pass