diff --git a/screenpy_selenium/configuration.py b/screenpy_selenium/configuration.py index 4292cd9..274edce 100644 --- a/screenpy_selenium/configuration.py +++ b/screenpy_selenium/configuration.py @@ -13,11 +13,11 @@ class ScreenPySeleniumSettings(ScreenPySettings): SCREENPY_SELENIUM_CHAIN_DURATION=50 # sets the indent char to 50 """ - _tool_path = "screenpy_selenium" + _tool_path = "screenpy.selenium" model_config = SettingsConfigDict(env_prefix="SCREENPY_SELENIUM_") CHAIN_DURATION: int = 10 - """Whether or not to use indentation in logging.""" + """Default duration of ActionChains in milleseconds""" # initialized instance diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 0000000..611b945 --- /dev/null +++ b/tests/test_settings.py @@ -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(TIMEOUT=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