-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Actionchain speedup #55
Merged
bandophahita
merged 7 commits into
ScreenPyHQ:trunk
from
bandophahita:actionchain_speedup
Mar 8, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a304db5
adding the ability to adjust the duration of ActionChains
bandophahita 1d6799a
adding test for settings
bandophahita 8ae8140
fixing namespace test
bandophahita 4cfd7f1
using keyword for argument
bandophahita 58bdbcd
adding documentation for settings
bandophahita cb4eb63
adding pydantic reqs
bandophahita 0036051
docs section correction
bandophahita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -29,3 +29,4 @@ to :class:`~screenpy_selenium.abilities.BrowseTheWeb`! | |
targets | ||
cookbook | ||
deprecations | ||
settings |
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,55 @@ | ||
======== | ||
Settings | ||
======== | ||
|
||
To configure ScreenPy Selenium, | ||
we provide some settings | ||
through `Pydantic's settings management <https://docs.pydantic.dev/usage/settings/>`__. | ||
|
||
Settings can be configured through these ways: | ||
|
||
* In your test configuration file (like conftest.py). | ||
* Using environment variables. | ||
* In the ``[tool.screenpy.selenium]`` section in your ``pyproject.toml``. | ||
|
||
The above options are in order of precedence; | ||
that is, | ||
setting the values directly in your configuration file will override environment variables, | ||
any environment variables will override any ``pyproject.toml`` settings, | ||
and any ``pyproject.toml`` settings will override the defaults. | ||
|
||
To demonstrate, | ||
here is how we can change the default actionchain duration | ||
used by things like :class:`screenpy_selenium.actions.Chain`:: | ||
|
||
# in your conftest.py | ||
from screenpy_selenium import settings | ||
|
||
settings.CHAIN_DURATION = 50 | ||
|
||
.. code-block:: bash | ||
|
||
$ # environment variables in your shell | ||
$ SCREENPY_SELENIUM_CHAIN_DURATION=50 pytest | ||
|
||
.. code-block:: toml | ||
|
||
# in your pyproject.toml file | ||
[tool.screenpy.selenium] | ||
CHAIN_DURATION = 50 | ||
|
||
The environment variable approach | ||
works particularly well with `python-dotenv <https://pypi.org/project/python-dotenv/>`__! | ||
|
||
|
||
|
||
Default Settings | ||
---------------- | ||
|
||
These are the default settings included in ScreenPy Selenium. | ||
|
||
ScreenPy Selenium Default Settings | ||
++++++++++++++++++++++++++++++++++ | ||
|
||
.. autopydantic_settings:: screenpy_selenium.configuration.ScreenPySeleniumSettings | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,24 @@ | ||
"""Define settings for the StdOutAdapter.""" | ||
|
||
from pydantic_settings import SettingsConfigDict | ||
from screenpy.configuration import ScreenPySettings | ||
|
||
|
||
class ScreenPySeleniumSettings(ScreenPySettings): | ||
"""Settings for the ScreenPySelenium. | ||
|
||
To change these settings using environment variables, use the prefix | ||
``SCREENPY_SELENIUM_``, like so:: | ||
|
||
SCREENPY_SELENIUM_CHAIN_DURATION=50 # sets the actionchain duration to 50ms | ||
""" | ||
|
||
_tool_path = "screenpy.selenium" | ||
model_config = SettingsConfigDict(env_prefix="SCREENPY_SELENIUM_") | ||
|
||
CHAIN_DURATION: int = 10 | ||
"""Default duration of ActionChains in milleseconds""" | ||
Comment on lines
+7
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it nice how easy this is? |
||
|
||
|
||
# initialized instance | ||
settings = ScreenPySeleniumSettings() |
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,44 @@ | ||
import os | ||
from unittest import mock | ||
|
||
from screenpy_selenium import settings as screenpy_selenium_settings | ||
from screenpy_selenium.configuration import ScreenPySeleniumSettings | ||
|
||
|
||
class TestSettings: | ||
def test_pyproject_overwrites_initial(self) -> None: | ||
mock_open = mock.mock_open( | ||
read_data=b"[tool.screenpy.selenium]\nCHAIN_DURATION = 500" | ||
) | ||
|
||
with mock.patch("pathlib.Path.open", mock_open): | ||
settings = ScreenPySeleniumSettings() | ||
|
||
assert settings.CHAIN_DURATION == 500 | ||
|
||
def test_env_overwrites_pyproject(self) -> None: | ||
mock_open = mock.mock_open( | ||
read_data=b"[tool.screenpy.selenium]\nCHAIN_DURATION = 500" | ||
) | ||
mock_env = {"SCREENPY_SELENIUM_CHAIN_DURATION": "1337"} | ||
|
||
with mock.patch("pathlib.Path.open", mock_open): # noqa: SIM117 | ||
with mock.patch.dict(os.environ, mock_env): | ||
settings = ScreenPySeleniumSettings() | ||
|
||
assert settings.CHAIN_DURATION == 1337 | ||
|
||
def test_init_overwrites_env(self) -> None: | ||
mock_env = {"SCREENPY_SELENIUM_CHAIN_DURATION": "1337"} | ||
|
||
with mock.patch.dict(os.environ, mock_env): | ||
settings = ScreenPySeleniumSettings(CHAIN_DURATION=9001) | ||
|
||
assert settings.CHAIN_DURATION == 9001 | ||
|
||
def test_can_be_changed_at_runtime(self) -> None: | ||
try: | ||
screenpy_selenium_settings.CHAIN_DURATION = 100 | ||
except TypeError as exc: | ||
msg = "ScreenPySeleniumSettings could not be changed at runtime." | ||
raise AssertionError(msg) from exc |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to also link to ScreenPy's settings here?