Skip to content
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

Add more unit tests for settings module #14

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math

import pytest

from fastboot.settings import PREF_DEF_REGISTRY, AppPreferences, Preference
Expand Down Expand Up @@ -38,26 +40,50 @@ class DummyPreference(Preference):
default = "default_value"
validator = text_is_not_empty

class DummyPreferenceWithCallableValue(Preference):
name = "dummy_preference_with_callable_value"
default = math.sqrt
desc = """\
This is a dummy preference with a method passed as value
"""


def teardown_module(module):
"""teardown any state that was previously setup with a setup_module method."""

# Remove dummy registered preferences
PREF_DEF_REGISTRY[:] = [pref for pref in PREF_DEF_REGISTRY if pref.__class__.__name__ not in ["DummyPreference"]]
PREF_DEF_REGISTRY[:] = [
pref for pref in PREF_DEF_REGISTRY if not pref.__class__.__name__.startswith("DummyPreference")
]


@pytest.fixture
def preferences() -> AppPreferences:
yield AppPreferences()


# Definition --------------------------------------


def test_prefs_are_registered() -> None:
"""Test if the preferences are registered properly or not"""

# At least one preference must be registered
assert len(PREF_DEF_REGISTRY) > 0, "No preference registered"


def test_invalid_pref_definition() -> None:
"""Test that error is raised if preference definition is invalid"""

with pytest.raises(TypeError):
# Declare a invalid preference definition
class InvalidPreference(Preference):
desc = "This is invalid definition and must throw exception"


# App Preferences ----------------------------------


def test_app_preference_getter_and_setters(preferences: AppPreferences):
"""Test if getting and setting preference is properly working or not."""

Expand Down
Loading