Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- add more tests for cases settings are not found and not evaluated
  • Loading branch information
devkral committed Jan 7, 2025
1 parent a722929 commit 03b491b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/targets/module_disabled_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FakeApp:
is_fake_app: bool = True


__all__ = ["foo", "stringify_all"] # noqa
__all__ = ["foo"] # noqa
monkay = Monkay(
globals(),
with_extensions=True,
Expand Down
23 changes: 23 additions & 0 deletions tests/targets/module_notevaluated_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from monkay import Monkay

extras = {"foo": lambda: "foo"}


def __getattr__(name: str):
try:
return extras[name]
except KeyError as exc:
raise AttributeError from exc


class FakeApp:
is_fake_app: bool = True


__all__ = ["foo"] # noqa
monkay = Monkay(
globals(),
with_extensions=True,
with_instance=True,
settings_path="tests.targets.not_existing_settings_path:Settings",
)
25 changes: 25 additions & 0 deletions tests/targets/module_notfound_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from monkay import Monkay

extras = {"foo": lambda: "foo"}


def __getattr__(name: str):
try:
return extras[name]
except KeyError as exc:
raise AttributeError from exc


class FakeApp:
is_fake_app: bool = True


__all__ = ["foo"] # noqa
monkay = Monkay(
globals(),
with_extensions=True,
with_instance=True,
settings_path="tests.targets.not_existing_settings_path:Settings",
settings_preloads_name="preloads",
settings_extensions_name="extensions",
)
25 changes: 25 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ def test_disabled_settings():
mod.monkay.settings # noqa


def test_notfound_settings():
import tests.targets.module_notfound_settings as mod

assert not mod.monkay.settings_evaluated

mod.monkay.evaluate_settings_once()
assert not mod.monkay.settings_evaluated

with pytest.raises(ImportError):
mod.monkay.evaluate_settings_once(ignore_import_errors=False)


def test_notevaluated_settings():
import tests.targets.module_notevaluated_settings as mod

assert mod.monkay.settings_evaluated

mod.monkay.evaluate_settings_once()
mod.monkay.evaluate_settings_once(ignore_import_errors=False)

# now evaluate settings
with pytest.raises(ImportError):
mod.monkay.settings # noqa


@pytest.mark.parametrize("value", [False, None, ""])
def test_unset_settings(value):
import tests.targets.module_full as mod
Expand Down

0 comments on commit 03b491b

Please sign in to comment.