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.
* adding the ability to adjust the duration of ActionChains * adding test for settings * fixing namespace test * using keyword for argument * adding documentation for settings * adding pydantic reqs * docs section correction
- Loading branch information
1 parent
4b7ea86
commit e9c2006
Showing
12 changed files
with
365 additions
and
205 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 |
---|---|---|
|
@@ -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""" | ||
|
||
|
||
# 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 |