Fixing/debugging code for tests.

Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
2021-10-04 10:26:26 -04:00
parent efa8a469db
commit 8ce13a8ccf
4 changed files with 36 additions and 36 deletions

View File

@@ -3,14 +3,14 @@ import dataclasses
import datetime
import typing
import marshmallow # type: ignore [import]
import pytest # type: ignore [import]
import marshmallow
import pytest
from playlist.data import base # type: ignore [import]
from playlist.data import base
@dataclasses.dataclass
class Dummy(base.BaseData["Dummy"]): # type: ignore [misc]
class Dummy(base.BaseData["Dummy"]):
"""Dummy class for tests."""
name: str
@@ -20,7 +20,7 @@ class Dummy(base.BaseData["Dummy"]): # type: ignore [misc]
modified: datetime.datetime
@pytest.fixture # type: ignore [misc]
@pytest.fixture
def dummyannotations() -> dict[str, typing.Any]:
"""Make a dummy annotation dict for testing."""
return {
@@ -32,13 +32,13 @@ def dummyannotations() -> dict[str, typing.Any]:
}
@pytest.fixture # type: ignore [misc]
@pytest.fixture
def modified_date() -> datetime.datetime:
"""Make a reusable datetime for testing."""
return datetime.datetime.now()
@pytest.fixture # type: ignore [misc]
@pytest.fixture
def dummydict(modified_date: datetime.datetime) -> dict[str, typing.Any]:
"""Make a dummy dictionary for testing."""
return {
@@ -50,7 +50,7 @@ def dummydict(modified_date: datetime.datetime) -> dict[str, typing.Any]:
}
@pytest.fixture # type: ignore [misc]
@pytest.fixture
def dummyobj(modified_date: datetime.datetime) -> Dummy:
"""Make a dummy object for testing."""
return Dummy(
@@ -76,7 +76,7 @@ def test_dict(dummyannotations: dict[str, typing.Any]) -> None:
assert result
def test_load(dummydict: dict[str, typing.Any], dummyobj: Dummy) -> None:
def test_load(dummydict: base.DataDict, dummyobj: Dummy) -> None:
"""Validate that <data class>.load() works."""
result = Dummy.load(dummydict)
assert result == dummyobj

View File

@@ -12,7 +12,7 @@ def example_settings() -> settings.Settings:
return settings.Settings(
creds=settings.CredentialSettings(
baseurl="http://nowhere.huh",
token="Fake Token", # noqa: S105
token="Fake Token", # noqa: S106
),
)

View File

@@ -2,10 +2,10 @@
import asyncio
import unittest.mock
import pytest # type: ignore [import]
import pytest
from playlist.data import settings # type: ignore [import]
from playlist.plex import server # type: ignore [import]
from playlist.data import settings
from playlist.plex import server
def test_calc_delay(mocker): # type: ignore [no-untyped-def]
@@ -15,8 +15,8 @@ def test_calc_delay(mocker): # type: ignore [no-untyped-def]
mock_s = mock_settings.modify.return_value.__enter__.return_value
mock_const.MAX_PROCESSES = 1
times = [100, 100, 100]
weights = [100, 100, 100]
times: list[float] = [100, 100, 100]
weights: list[float] = [1, 1, 1]
server.calc_delay(times, weights)
@@ -63,8 +63,8 @@ async def test_gen_tracks(mocker): # type: ignore [no-untyped-def]
assert mock_calc_duration.called
@pytest.mark.asyncio # type: ignore [misc]
async def test_total_track_count(mocker: pytest.fixture) -> None:
@pytest.mark.asyncio
async def test_total_track_count(mocker): # type: ignore [no-untyped-def]
"""Test the total_track_count coroutine."""
mock_plexapi_server = mocker.patch("playlist.plex.server.plexapi.server")
mock_server = mock_plexapi_server.PlexServer.return_value
@@ -76,7 +76,7 @@ async def test_total_track_count(mocker: pytest.fixture) -> None:
assert result == 1
def test_get_creds(mocker: pytest.fixture) -> None:
def test_get_creds(mocker): # type: ignore [no-untyped-def]
"""Test the get_creds function."""
mock_plexapi_myplex = mocker.patch("playlist.plex.server.plexapi.myplex")
mock_input = mocker.patch("builtins.input")
@@ -98,8 +98,8 @@ def test_get_creds(mocker: pytest.fixture) -> None:
assert mock_getpass.getpass.called
@pytest.mark.asyncio # type: ignore [misc]
async def test_downloader(mocker: pytest.fixture) -> None:
@pytest.mark.asyncio
async def test_downloader(mocker): # type: ignore [no-untyped-def]
"""Test the _downloader coroutine."""
async def fake_run_in_executor(*args): # type: ignore
@@ -117,7 +117,7 @@ async def test_downloader(mocker: pytest.fixture) -> None:
assert process_time >= 0.1
def test_get_track_batch(mocker: pytest.fixture) -> None:
def test_get_track_batch(mocker): # 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
@@ -132,7 +132,7 @@ def test_get_track_batch(mocker: pytest.fixture) -> None:
assert mock_track_dump.called
def test_track_dump(mocker: pytest.fixture) -> None:
def test_track_dump(mocker): # type: ignore [no-untyped-def]
"""Test the _track_dump function."""
mock_track = unittest.mock.MagicMock()
mock_track.configure_mock(
@@ -156,8 +156,8 @@ def test_track_dump(mocker: pytest.fixture) -> None:
assert isinstance(result, dict)
@pytest.mark.asyncio # type: ignore [misc]
async def test_gen_batch_params(mocker: pytest.fixture) -> None:
@pytest.mark.asyncio
async def test_gen_batch_params(mocker): # type: ignore [no-untyped-def]
"""Test the _gen_batch_params asynchronous generator."""
mock_total_track_count = mocker.patch(
"playlist.plex.server.total_track_count",