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

@@ -4,8 +4,8 @@ import sys
from pathlib import Path
from textwrap import dedent
import nox # type: ignore [import]
from nox_poetry import Session # type: ignore [import]
import nox
from nox_poetry import Session
from nox_poetry import session
@@ -33,7 +33,7 @@ def activate_virtualenv_in_precommit_hooks(session: Session) -> None: # noqa: C
session: The Session object.
"""
if session.bin is None:
return
return # type: ignore [unreachable]
virtualenv = session.env.get("VIRTUAL_ENV")
if virtualenv is None:
@@ -73,7 +73,7 @@ def activate_virtualenv_in_precommit_hooks(session: Session) -> None: # noqa: C
hook.write_text("\n".join(lines))
@session(name="pre-commit", python="3.9") # type: ignore [misc]
@session(name="pre-commit", python="3.9")
def precommit(session: Session) -> None:
"""Lint using pre-commit."""
args = session.posargs or ["run", "--all-files", "--show-diff-on-failure"]
@@ -95,7 +95,7 @@ def precommit(session: Session) -> None:
activate_virtualenv_in_precommit_hooks(session)
@session(python="3.9") # type: ignore [misc]
@session(python="3.9")
def safety(session: Session) -> None:
"""Scan dependencies for insecure packages."""
requirements = session.poetry.export_requirements()
@@ -103,7 +103,7 @@ def safety(session: Session) -> None:
session.run("safety", "check", f"--file={requirements}", "--bare")
@session(python=python_versions) # type: ignore [misc]
@session(python=python_versions)
def mypy(session: Session) -> None:
"""Type-check using mypy."""
args = session.posargs or ["src", "tests", "docs/conf.py"]
@@ -114,7 +114,7 @@ def mypy(session: Session) -> None:
session.run("mypy", f"--python-executable={sys.executable}", "noxfile.py")
@session(python=python_versions) # type: ignore [misc]
@session(python=python_versions)
def tests(session: Session) -> None:
"""Run the test suite."""
session.install(".")
@@ -132,7 +132,7 @@ def tests(session: Session) -> None:
session.notify("coverage")
@session # type: ignore [misc]
@session
def coverage(session: Session) -> None:
"""Produce the coverage report."""
# Do not use session.posargs unless this is the only session.
@@ -148,7 +148,7 @@ def coverage(session: Session) -> None:
session.run("coverage", *args)
@session(python=python_versions) # type: ignore [misc]
@session(python=python_versions)
def typeguard(session: Session) -> None:
"""Runtime type checking using Typeguard."""
session.install(".")
@@ -156,7 +156,7 @@ def typeguard(session: Session) -> None:
session.run("pytest", f"--typeguard-packages={package}", *session.posargs)
@session(python=python_versions) # type: ignore [misc]
@session(python=python_versions)
def xdoctest(session: Session) -> None:
"""Run examples with xdoctest."""
args = session.posargs or ["all"]
@@ -165,7 +165,7 @@ def xdoctest(session: Session) -> None:
session.run("python", "-m", "xdoctest", package, *args)
@session(name="docs-build", python="3.8") # type: ignore [misc]
@session(name="docs-build", python="3.8")
def docs_build(session: Session) -> None:
"""Build the documentation."""
args = session.posargs or ["docs", "docs/_build"]
@@ -179,7 +179,7 @@ def docs_build(session: Session) -> None:
session.run("sphinx-build", *args)
@session(python="3.8") # type: ignore [misc]
@session(python="3.8")
def docs(session: Session) -> None:
"""Build and serve the documentation with live reloading on file changes."""
args = session.posargs or ["--open-browser", "docs", "docs/_build"]

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",