Got tests for settings.
Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
import dataclasses
|
||||
import datetime
|
||||
import functools
|
||||
import getpass
|
||||
import pathlib
|
||||
|
||||
import yaml
|
||||
@@ -22,9 +23,7 @@ class CredentialSettings(base.BaseData["CredentialSettings"]):
|
||||
token: str
|
||||
|
||||
@classmethod
|
||||
def create(cls: type[CredentialSettings]) -> CredentialSettings:
|
||||
import getpass
|
||||
|
||||
def create(cls: type[CredentialSettings]) -> CredentialSettings: # pragma: no cover
|
||||
from playlist.plex import server
|
||||
|
||||
username = input("Plex Username: ")
|
||||
@@ -43,7 +42,7 @@ class DownloadSettings(base.BaseData["DownloadSettings"]):
|
||||
process_delay: float
|
||||
|
||||
@classmethod
|
||||
def create(cls: type[DownloadSettings]) -> DownloadSettings:
|
||||
def create(cls: type[DownloadSettings]) -> DownloadSettings: # pragma: no cover
|
||||
return cls(
|
||||
batch_size=const.DEFAULTS.BATCH_SIZE,
|
||||
process_delay=const.DEFAULTS.PROCESS_DELAY,
|
||||
@@ -57,7 +56,7 @@ class TrackSettings(base.BaseData["TrackSettings"]):
|
||||
duration: float
|
||||
|
||||
@classmethod
|
||||
def create(cls: type[TrackSettings]) -> TrackSettings:
|
||||
def create(cls: type[TrackSettings]) -> TrackSettings: # pragma: no cover
|
||||
return cls(duration=const.DEFAULTS.DURATION)
|
||||
|
||||
|
||||
@@ -69,7 +68,7 @@ class PlaylistSettings(base.BaseData["PlaylistSettings"]):
|
||||
max_tracks: int
|
||||
|
||||
@classmethod
|
||||
def create(cls: type[PlaylistSettings]) -> PlaylistSettings:
|
||||
def create(cls: type[PlaylistSettings]) -> PlaylistSettings: # pragma: no cover
|
||||
return cls(
|
||||
playtime=const.DEFAULTS.PLAYTIME,
|
||||
max_tracks=const.DEFAULTS.MAX_TRACKS,
|
||||
@@ -119,7 +118,7 @@ class Settings(base.BaseData["Settings"]):
|
||||
|
||||
|
||||
@functools.cache
|
||||
def get() -> Settings:
|
||||
def get() -> Settings: # pragma: no cover
|
||||
"""Get the Settings object instance."""
|
||||
instance: Settings
|
||||
filepath = const.PATHS.CONFIG / const.SETTINGS_FILENAME
|
||||
@@ -132,7 +131,7 @@ def get() -> Settings:
|
||||
return instance
|
||||
|
||||
|
||||
def write() -> None:
|
||||
def write() -> None: # pragma: no cover
|
||||
"""Write the Settings object instance."""
|
||||
filepath = const.PATHS.CONFIG / const.SETTINGS_FILENAME
|
||||
get().yaml_write(filepath)
|
||||
|
||||
30
tests/data/test_settings.py
Normal file
30
tests/data/test_settings.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""Tests for validating the Settings object."""
|
||||
import pathlib
|
||||
|
||||
import pytest # type: ignore [import]
|
||||
|
||||
from playlist.data import settings # type: ignore [import]
|
||||
|
||||
|
||||
@pytest.fixture # type: ignore [misc]
|
||||
def example_settings() -> settings.Settings:
|
||||
"""Make testable Settings object."""
|
||||
return settings.Settings(
|
||||
creds=settings.CredentialSettings(baseurl="http://nowhere.huh", token="12345"),
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture # type: ignore [misc]
|
||||
def settings_filepath(tmp_path: pathlib.Path) -> pathlib.Path:
|
||||
"""Get the path to use for the settings file."""
|
||||
return tmp_path / "fake_settings.yaml"
|
||||
|
||||
|
||||
def test_yaml(
|
||||
example_settings: settings.Settings,
|
||||
settings_filepath: pathlib.Path,
|
||||
) -> None:
|
||||
"""Test the YAML read/write operations."""
|
||||
example_settings.yaml_write(settings_filepath)
|
||||
result = example_settings.yaml_read(settings_filepath)
|
||||
assert result == example_settings
|
||||
Reference in New Issue
Block a user