Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Replace deprecated implprefix from pluggy with HookimplMarker #92

Merged
merged 2 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ Then, in your package implement one or more of the plugin :ref:`hooks` provided
by PyPOM. The following example will take a screenshot whenever a page or
region has finished loading::


from pypom import hookimpl

@hookimpl
def pypom_after_wait_for_page_to_load(page):
page.selenium.get_screenshot_as_file(page.__class__.__name__ + '.png')


@hookimpl
def pypom_after_wait_for_region_to_load(region):
region.root.screenshot(region.__class__.__name__ + '.png')

Expand Down
3 changes: 3 additions & 0 deletions src/pypom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .page import Page # noqa
from .region import Region # noqa

import pluggy
import selenium # noqa

# register selenium support
Expand All @@ -16,3 +17,5 @@
from .splinter_driver import register as registerSplinter

registerSplinter()

hookimpl = pluggy.HookimplMarker("pypom")
18 changes: 18 additions & 0 deletions src/pypom/newsfragments/90.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Replace use of ``implprefix`` with ``HookimplMarker`` due to deprecation.

Existing PyPOM plugins will need to be updated to import the `hookimpl` and use
it to decorate hook implementations rather than rely on the prefix of the
function names.

Before::

def pypom_after_wait_for_page_to_load(page):
pass

After::

from pypom import hookimpl

@hookimpl
def pypom_after_wait_for_page_to_load(page):
pass
2 changes: 1 addition & 1 deletion src/pypom/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, driver, timeout, pm=None):
self.timeout = timeout
self.pm = pm
if self.pm is None:
self.pm = PluginManager("pypom", implprefix="pypom_")
self.pm = PluginManager("pypom")
self.pm.add_hookspecs(hooks)
self.pm.load_setuptools_entrypoints("pypom.plugin")
self.pm.check_pending()
Expand Down
4 changes: 3 additions & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
# 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 pypom import Region
from pypom import Region, hookimpl


def test_after_wait_for_page_to_load(page):
log = []

class Plugin:
@hookimpl
def pypom_after_wait_for_page_to_load(self, page):
log.append(1)

@hookimpl
def pypom_after_wait_for_region_to_load(self, region):
log.append(2)

Expand Down