Skip to content

Commit

Permalink
adding test for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bandophahita committed Mar 1, 2024
1 parent a304db5 commit 0fa6c60
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions screenpy_selenium/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions tests/test_settings.py
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(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

0 comments on commit 0fa6c60

Please sign in to comment.