forked from ScreenPyHQ/screenpy_selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* enabling ruff FBT (flake8-boolean-trap) and addressing ScreenPyHQ#44 * fixing 3.8/3.9 compatability with ParamSpec * fixing docstring capitalization * updated deprecation warning to inform users when the change will take place. * tests should assert reason for failure
- Loading branch information
1 parent
89b64d7
commit dd85ed2
Showing
11 changed files
with
269 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
============ | ||
Deprecations | ||
============ | ||
|
||
This page documents | ||
the major deprecations | ||
in ScreenPy Selenium's life, | ||
and how to adjust your tests | ||
to keep them up to date. | ||
|
||
4.1.0 Deprecations | ||
================== | ||
|
||
Boolean Positional Arguments Deprecation | ||
---------------------------------------- | ||
|
||
The following class constructors | ||
have been marked deprecated | ||
when using a positional boolean argument in the constructor. | ||
Starting with version 5.0.0 | ||
you will be required to provide keywords | ||
for the following boolean arguments. | ||
|
||
While our documentation does not explicitly outline using these Actions in this way, | ||
it's still possible to do so. | ||
If you are using Actions directly from their constructors | ||
like the below examples, | ||
here are the fixes you'll need to implement. | ||
|
||
|
||
:class:`~screenpy_selenium.actions.enter.Enter` | ||
|
||
Before: | ||
|
||
.. code-block:: python | ||
the_actor.will(Enter("foo", True).into_the(PASSWORD)) | ||
After: | ||
|
||
.. code-block:: python | ||
the_actor.will(Enter("foo", mask=True).into_the(PASSWORD)) | ||
:class:`~screenpy_selenium.actions.hold_down.HoldDown` | ||
|
||
Before: | ||
|
||
.. code-block:: python | ||
the_actor.will(Chain(HoldDown(None, True)) | ||
After: | ||
.. code-block:: python | ||
the_actor.will(Chain(HoldDown(None, lmb=True)) | ||
the_actor.will(Chain(HoldDown(lmb=True)) | ||
:class:`~screenpy_selenium.actions.release.Release` | ||
Before: | ||
.. code-block:: python | ||
the_actor.will(Release(None, True)) | ||
After: | ||
.. code-block:: python | ||
the_actor.will(Release(None, lmb=True)) | ||
the_actor.will(Release(lmb=True)) | ||
:class:`~screenpy_selenium.questions.selected.Selected` | ||
Before: | ||
.. code-block:: python | ||
the_actor.shall(See.the(Selected(TARGET, True), IsEmpty())) | ||
After: | ||
.. code-block:: python | ||
the_actor.shall(See.the(Selected(TARGET, multi=True), IsEmpty())) | ||
:class:`~screenpy_selenium.questions.text.Text` | ||
Before: | ||
.. code-block:: python | ||
the_actor.shall(See.the(Text(TARGET, True), IsEqual("foo")) | ||
After: | ||
.. code-block:: python | ||
the_actor.shall(See.the(Text(TARGET, multi=True), IsEqual("foo") | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ to :class:`~screenpy_selenium.abilities.BrowseTheWeb`! | |
extended_api | ||
targets | ||
cookbook | ||
deprecations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Module to hold shared objects.""" | ||
|
||
from __future__ import annotations | ||
|
||
import warnings | ||
from functools import wraps | ||
from typing import TYPE_CHECKING, Callable, TypeVar | ||
|
||
from typing_extensions import ParamSpec | ||
|
||
if TYPE_CHECKING: | ||
P = ParamSpec("P") | ||
T = TypeVar("T") | ||
Function = Callable[P, T] | ||
|
||
|
||
def pos_args_deprecated(*keywords: str) -> Function: | ||
"""Warn users which positional arguments should be called via keyword.""" | ||
|
||
def deprecated(func: Function) -> Function: | ||
argnames = func.__code__.co_varnames[: func.__code__.co_argcount] | ||
i = min([argnames.index(kw) for kw in keywords]) | ||
kw_argnames = argnames[i:] | ||
|
||
@wraps(func) | ||
def wrapper(*args: P.args, **kwargs: P.kwargs) -> Function: | ||
# call the function first, to make sure the signature matches | ||
ret_value = func(*args, **kwargs) | ||
|
||
args_that_should_be_kw = args[i:] | ||
if args_that_should_be_kw: | ||
posargnames = ", ".join(kw_argnames) | ||
|
||
msg = ( | ||
f"Warning: positional arguments `{posargnames}` for " | ||
f"`{func.__qualname__}` are deprecated " | ||
f"and will be removed in version 5. " | ||
f"Please use keyword arguments instead." | ||
) | ||
warnings.warn(msg, DeprecationWarning, stacklevel=2) | ||
|
||
return ret_value | ||
|
||
return wrapper | ||
|
||
return deprecated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.