Got the Typeguard thing to finally stop complaining.
Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
@@ -3,7 +3,6 @@ import dataclasses
|
||||
import datetime
|
||||
import typing
|
||||
|
||||
import marshmallow
|
||||
import pytest
|
||||
|
||||
from playlist.data import base
|
||||
@@ -21,62 +20,30 @@ class Dummy(base.BaseData):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
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
|
||||
def modified_date() -> datetime.datetime:
|
||||
"""Make a reusable datetime for testing."""
|
||||
return datetime.datetime.now()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
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
|
||||
def dummyobj(modified_date: datetime.datetime) -> Dummy:
|
||||
def dummyobj() -> Dummy:
|
||||
"""Make a dummy object for testing."""
|
||||
return Dummy(
|
||||
name="Something",
|
||||
some_id=1,
|
||||
calc=0.1,
|
||||
flag=True,
|
||||
modified=modified_date,
|
||||
modified=datetime.datetime.now(),
|
||||
)
|
||||
|
||||
|
||||
def test_schema() -> None:
|
||||
"""Validate that <data class>.Schema works."""
|
||||
result = isinstance(Dummy.Schema, marshmallow.Schema)
|
||||
|
||||
assert result
|
||||
@pytest.fixture
|
||||
def dummydict(dummyobj: Dummy) -> dict[str, object]:
|
||||
"""Make a dummy dictionary for testing."""
|
||||
return {
|
||||
"name": dummyobj.name,
|
||||
"some_id": dummyobj.some_id,
|
||||
"calc": dummyobj.calc,
|
||||
"flag": dummyobj.flag,
|
||||
"modified": "T".join(str(dummyobj.modified).split(" ")),
|
||||
}
|
||||
|
||||
|
||||
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: base.DataDict, dummyobj: Dummy) -> None:
|
||||
def test_load(dummydict: dict[str, object], dummyobj: Dummy) -> None:
|
||||
"""Validate that <data class>.load() works."""
|
||||
result: Dummy = Dummy.load(dummydict)
|
||||
assert result == dummyobj
|
||||
|
||||
@@ -88,7 +88,7 @@ def test_get_creds(mocker): # type: ignore [no-untyped-def]
|
||||
mock_plex._baseurl = "Not a valid URL"
|
||||
mock_plex._token = "Fake token"
|
||||
|
||||
expected = settings.CredentialSettings.Dict(
|
||||
expected = settings.CredentialSettings(
|
||||
baseurl=mock_plex._baseurl,
|
||||
token=mock_plex._token,
|
||||
)
|
||||
@@ -120,9 +120,9 @@ async def test_downloader(mocker): # type: ignore [no-untyped-def]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_trackdict(fake_plextrack): # type: ignore [no-untyped-def]
|
||||
def fake_track(fake_plextrack): # type: ignore [no-untyped-def]
|
||||
"""Make a fake track dict object."""
|
||||
return models.Track.Dict(
|
||||
return models.Track(
|
||||
plex_id=fake_plextrack.ratingKey,
|
||||
track_num=fake_plextrack.index,
|
||||
title=fake_plextrack.title,
|
||||
@@ -133,22 +133,20 @@ def fake_trackdict(fake_plextrack): # type: ignore [no-untyped-def]
|
||||
duration=fake_plextrack.duration,
|
||||
rating=fake_plextrack.userRating,
|
||||
comments=fake_plextrack.summary,
|
||||
added=str(fake_plextrack.addedAt),
|
||||
added=fake_plextrack.addedAt,
|
||||
play_count=fake_plextrack.viewCount,
|
||||
played=str(fake_plextrack.lastViewedAt)
|
||||
if fake_plextrack.lastViewedAt is not None
|
||||
else None,
|
||||
played=fake_plextrack.lastViewedAt,
|
||||
)
|
||||
|
||||
|
||||
def test_get_track_batch(mocker, fake_trackdict): # type: ignore [no-untyped-def]
|
||||
def test_get_track_batch(mocker, fake_track): # type: ignore [no-untyped-def]
|
||||
"""Test _get_track_batch function."""
|
||||
mock_plexapi_server = mocker.patch("playlist.plex.server.plexapi.server")
|
||||
mock_server = mock_plexapi_server.PlexServer.return_value
|
||||
mock_search_tracks = mock_server.library.section.return_value.searchTracks
|
||||
mock_search_tracks.return_value = ["Not a track."]
|
||||
mock_track_dump = mocker.patch("playlist.plex.server._track_dump")
|
||||
mock_track_dump.return_value = fake_trackdict
|
||||
mock_track_dump.return_value = fake_track
|
||||
|
||||
result = server._get_track_batch(1, 1)
|
||||
|
||||
@@ -178,12 +176,11 @@ def fake_plextrack(): # type: ignore [no-untyped-def]
|
||||
return mock_track
|
||||
|
||||
|
||||
def test_track_dump(fake_plextrack, fake_trackdict): # type: ignore [no-untyped-def]
|
||||
def test_track_dump(fake_plextrack, fake_track): # type: ignore [no-untyped-def]
|
||||
"""Test the _track_dump function."""
|
||||
print(models.Track.Dict.__annotations__)
|
||||
result = server._track_dump(fake_plextrack)
|
||||
|
||||
assert result == fake_trackdict
|
||||
assert result == fake_track
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user