Tests for playlist.data.base implemented.
Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
@@ -1,2 +0,0 @@
|
|||||||
[pytest]
|
|
||||||
addopts = --cov=xdh --cov-report term-missing:skip-covered
|
|
||||||
@@ -7,7 +7,7 @@ import functools
|
|||||||
import typing
|
import typing
|
||||||
|
|
||||||
import desert # type: ignore [import]
|
import desert # type: ignore [import]
|
||||||
import marshmallow.schema # type: ignore [import]
|
import marshmallow # type: ignore [import]
|
||||||
|
|
||||||
|
|
||||||
DataSub = typing.TypeVar("DataSub")
|
DataSub = typing.TypeVar("DataSub")
|
||||||
@@ -25,7 +25,7 @@ class DataMeta(type):
|
|||||||
|
|
||||||
@property # type: ignore [no-redef,misc]
|
@property # type: ignore [no-redef,misc]
|
||||||
@functools.cache
|
@functools.cache
|
||||||
def Schema(cls: DataMeta) -> marshmallow.schema.Schema: # noqa: N802
|
def Schema(cls: DataMeta) -> marshmallow.Schema: # noqa: N802
|
||||||
"""The marshmallow Schema object for this data class."""
|
"""The marshmallow Schema object for this data class."""
|
||||||
return desert.schema(cls)
|
return desert.schema(cls)
|
||||||
|
|
||||||
|
|||||||
0
src/playlist/data/py.typed
Normal file
0
src/playlist/data/py.typed
Normal file
0
src/playlist/plex/py.typed
Normal file
0
src/playlist/plex/py.typed
Normal file
88
tests/data/test_base.py
Normal file
88
tests/data/test_base.py
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
"""Tests for the playlist.data.base module."""
|
||||||
|
import dataclasses
|
||||||
|
import datetime
|
||||||
|
import typing
|
||||||
|
|
||||||
|
import marshmallow # type: ignore [import]
|
||||||
|
import pytest # type: ignore [import]
|
||||||
|
|
||||||
|
from playlist.data import base # type: ignore [import]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclasses.dataclass
|
||||||
|
class Dummy(base.BaseData["Dummy"]): # type: ignore [misc]
|
||||||
|
"""Dummy class for tests."""
|
||||||
|
|
||||||
|
name: str
|
||||||
|
some_id: int
|
||||||
|
calc: float
|
||||||
|
flag: bool
|
||||||
|
modified: datetime.datetime
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture # type: ignore [misc]
|
||||||
|
def dummyannotations() -> dict[str, typing.Any]:
|
||||||
|
"""Make a dummy annotation dict for testing."""
|
||||||
|
return {
|
||||||
|
"name": str,
|
||||||
|
"some_id": int,
|
||||||
|
"calc": float,
|
||||||
|
"flag": bool,
|
||||||
|
"modified": str,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture # type: ignore [misc]
|
||||||
|
def modified_date() -> datetime.datetime:
|
||||||
|
"""Make a reusable datetime for testing."""
|
||||||
|
return datetime.datetime.now()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture # type: ignore [misc]
|
||||||
|
def dummydict(modified_date: datetime.datetime) -> dict[str, typing.Any]:
|
||||||
|
"""Make a dummy dictionary for testing."""
|
||||||
|
return {
|
||||||
|
"name": "Something",
|
||||||
|
"some_id": 1,
|
||||||
|
"calc": 0.1,
|
||||||
|
"flag": True,
|
||||||
|
"modified": "T".join(str(modified_date).split(" ")),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture # type: ignore [misc]
|
||||||
|
def dummyobj(modified_date: datetime.datetime) -> Dummy:
|
||||||
|
"""Make a dummy object for testing."""
|
||||||
|
return Dummy(
|
||||||
|
name="Something",
|
||||||
|
some_id=1,
|
||||||
|
calc=0.1,
|
||||||
|
flag=True,
|
||||||
|
modified=modified_date,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_schema() -> None:
|
||||||
|
"""Validate that <data class>.Schema works."""
|
||||||
|
result = isinstance(Dummy.Schema, marshmallow.Schema)
|
||||||
|
|
||||||
|
assert result
|
||||||
|
|
||||||
|
|
||||||
|
def test_dict(dummyannotations: dict[str, typing.Any]) -> None:
|
||||||
|
"""Validate that <data class>.Dict works."""
|
||||||
|
result = Dummy.Dict.__annotations__ == dummyannotations
|
||||||
|
|
||||||
|
assert result
|
||||||
|
|
||||||
|
|
||||||
|
def test_load(dummydict: dict[str, typing.Any], dummyobj: Dummy) -> None:
|
||||||
|
"""Validate that <data class>.load() works."""
|
||||||
|
result = Dummy.load(dummydict)
|
||||||
|
assert result == dummyobj
|
||||||
|
|
||||||
|
|
||||||
|
def test_dump(dummydict: dict[str, typing.Any], dummyobj: Dummy) -> None:
|
||||||
|
"""Validate that <data class instance>.dump() works."""
|
||||||
|
result = dummyobj.dump()
|
||||||
|
assert result == dummydict
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
"""Tests for the data models."""
|
|
||||||
# import pytest
|
|
||||||
Reference in New Issue
Block a user