test(ci): add coverage for static-checks

Runs mypy and ruff. Add basic test.

- Update pyproject.toml dependencies groups
  - PDM can use top-level [dependency-groups] (PEP 735), support was added in pdm 2.20.0 (October 2024)
- Fix Ruff warnings
This commit is contained in:
Götz 2026-03-01 09:39:13 -05:00
parent 49a75f8118
commit b922d34db8
6 changed files with 299 additions and 35 deletions

39
.github/runtime/action.yml vendored Normal file
View file

@ -0,0 +1,39 @@
---
name: Install runtime
description: Install the required runtime and related base dependencies
inputs:
python:
description: "Install Python"
default: "true"
outputs:
python:
description: "Resolved version"
value: ${{ steps.get_version.outputs.python }}
runs:
using: "composite"
steps:
- name: Determine version
id: get_version
shell: bash -eo pipefail {0}
run: |
python="$(grep -E '^requires-python\s*=\s*\"' pyproject.toml | sed -E 's/.*\"[^0-9]*([0-9]+\.[0-9]+).*/\1/' | head -n1)"
if [ -z "$python" ]; then
exit 1
fi
echo "python=${python}" >> "$GITHUB_OUTPUT"
- name: Install Python
if: ${{ inputs.python == 'true' }}
uses: actions/setup-python@v6
with:
python-version: ${{ steps.get_version.outputs.python }}
- name: Show tooling information
shell: bash -eo pipefail {0}
run: |
set -x
python --version

67
.github/workflows/static-checks.yml vendored Normal file
View file

@ -0,0 +1,67 @@
name: Static Checks
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
concurrency:
group: static-checks-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
lint-and-typecheck:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install runtime
id: runtime
uses: ./.github/runtime
- name: Set up PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ steps.runtime.outputs.python }}
cache: true
- name: Install dependencies
run: pdm sync -dG:all
- name: Ruff
run: pdm run ruff check src
- name: Mypy
run: pdm run mypy -p mpd_now_playable
tests:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install runtime
id: runtime
uses: ./.github/runtime
- name: Set up PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ steps.runtime.outputs.python }}
cache: true
- name: Install dependencies
run: pdm sync -dG:all
- name: Run tests
run: pdm run pytest tests

99
pdm.lock generated
View file

@ -5,7 +5,7 @@
groups = ["default", "all", "dev", "memcached", "redis", "websockets"]
strategy = []
lock_version = "4.5.0"
content_hash = "sha256:b84a0925a81adb7c4ca5a1a947ccb0db6950a18955bd92f08a605ff06cd0c26c"
content_hash = "sha256:551970d3b5c9675e8edd582bf96f4b64476b4a2bb852a124439621a8df2075a4"
[[metadata.targets]]
requires_python = ">=3.12"
@ -96,6 +96,16 @@ files = [
{file = "class_doc-0.2.6-py3-none-any.whl", hash = "sha256:e6f2cea2dfbe93f76dee25de13d70dc0d2269698e8b849f751d98dc894c52ea5"},
]
[[package]]
name = "colorama"
version = "0.4.6"
requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
summary = "Cross-platform colored terminal text."
files = [
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
]
[[package]]
name = "idna"
version = "3.7"
@ -106,6 +116,16 @@ files = [
{file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"},
]
[[package]]
name = "iniconfig"
version = "2.3.0"
requires_python = ">=3.10"
summary = "brain-dead simple config-ini parsing"
files = [
{file = "iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12"},
{file = "iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730"},
]
[[package]]
name = "markdown-it-py"
version = "3.0.0"
@ -220,6 +240,26 @@ files = [
{file = "ormsgpack-1.7.0.tar.gz", hash = "sha256:6b4c98839cb7fc2a212037d2258f3a22857155249eb293d45c45cb974cfba834"},
]
[[package]]
name = "packaging"
version = "26.0"
requires_python = ">=3.8"
summary = "Core utilities for Python packages"
files = [
{file = "packaging-26.0-py3-none-any.whl", hash = "sha256:b36f1fef9334a5588b4166f8bcd26a14e521f2b55e6b9de3aaa80d3ff7a37529"},
{file = "packaging-26.0.tar.gz", hash = "sha256:00243ae351a257117b6a241061796684b084ed1c516a08c48a3f7e147a9d80b4"},
]
[[package]]
name = "pluggy"
version = "1.6.0"
requires_python = ">=3.9"
summary = "plugin and hook calling mechanisms for python"
files = [
{file = "pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746"},
{file = "pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3"},
]
[[package]]
name = "propcache"
version = "0.2.1"
@ -436,6 +476,25 @@ files = [
{file = "pyobjc_framework_quartz-11.0.tar.gz", hash = "sha256:3205bf7795fb9ae34747f701486b3db6dfac71924894d1f372977c4d70c3c619"},
]
[[package]]
name = "pytest"
version = "9.0.2"
requires_python = ">=3.10"
summary = "pytest: simple powerful testing with Python"
dependencies = [
"colorama>=0.4; sys_platform == \"win32\"",
"exceptiongroup>=1; python_version < \"3.11\"",
"iniconfig>=1.0.1",
"packaging>=22",
"pluggy<2,>=1.5",
"pygments>=2.7.2",
"tomli>=1; python_version < \"3.11\"",
]
files = [
{file = "pytest-9.0.2-py3-none-any.whl", hash = "sha256:711ffd45bf766d5264d487b917733b453d917afd2b0ad65223959f59089f875b"},
{file = "pytest-9.0.2.tar.gz", hash = "sha256:75186651a92bd89611d1d9fc20f0b4345fd827c41ccd5c299a868a05d70edf11"},
]
[[package]]
name = "python-mpd2"
version = "3.1.1"
@ -486,28 +545,28 @@ files = [
[[package]]
name = "ruff"
version = "0.9.2"
version = "0.15.4"
requires_python = ">=3.7"
summary = "An extremely fast Python linter and code formatter, written in Rust."
files = [
{file = "ruff-0.9.2-py3-none-linux_armv6l.whl", hash = "sha256:80605a039ba1454d002b32139e4970becf84b5fee3a3c3bf1c2af6f61a784347"},
{file = "ruff-0.9.2-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:b9aab82bb20afd5f596527045c01e6ae25a718ff1784cb92947bff1f83068b00"},
{file = "ruff-0.9.2-py3-none-macosx_11_0_arm64.whl", hash = "sha256:fbd337bac1cfa96be615f6efcd4bc4d077edbc127ef30e2b8ba2a27e18c054d4"},
{file = "ruff-0.9.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:82b35259b0cbf8daa22a498018e300b9bb0174c2bbb7bcba593935158a78054d"},
{file = "ruff-0.9.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:8b6a9701d1e371bf41dca22015c3f89769da7576884d2add7317ec1ec8cb9c3c"},
{file = "ruff-0.9.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9cc53e68b3c5ae41e8faf83a3b89f4a5d7b2cb666dff4b366bb86ed2a85b481f"},
{file = "ruff-0.9.2-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:8efd9da7a1ee314b910da155ca7e8953094a7c10d0c0a39bfde3fcfd2a015684"},
{file = "ruff-0.9.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:3292c5a22ea9a5f9a185e2d131dc7f98f8534a32fb6d2ee7b9944569239c648d"},
{file = "ruff-0.9.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:1a605fdcf6e8b2d39f9436d343d1f0ff70c365a1e681546de0104bef81ce88df"},
{file = "ruff-0.9.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c547f7f256aa366834829a08375c297fa63386cbe5f1459efaf174086b564247"},
{file = "ruff-0.9.2-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:d18bba3d3353ed916e882521bc3e0af403949dbada344c20c16ea78f47af965e"},
{file = "ruff-0.9.2-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:b338edc4610142355ccf6b87bd356729b62bf1bc152a2fad5b0c7dc04af77bfe"},
{file = "ruff-0.9.2-py3-none-musllinux_1_2_i686.whl", hash = "sha256:492a5e44ad9b22a0ea98cf72e40305cbdaf27fac0d927f8bc9e1df316dcc96eb"},
{file = "ruff-0.9.2-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:af1e9e9fe7b1f767264d26b1075ac4ad831c7db976911fa362d09b2d0356426a"},
{file = "ruff-0.9.2-py3-none-win32.whl", hash = "sha256:71cbe22e178c5da20e1514e1e01029c73dc09288a8028a5d3446e6bba87a5145"},
{file = "ruff-0.9.2-py3-none-win_amd64.whl", hash = "sha256:c5e1d6abc798419cf46eed03f54f2e0c3adb1ad4b801119dedf23fcaf69b55b5"},
{file = "ruff-0.9.2-py3-none-win_arm64.whl", hash = "sha256:a1b63fa24149918f8b37cef2ee6fff81f24f0d74b6f0bdc37bc3e1f2143e41c6"},
{file = "ruff-0.9.2.tar.gz", hash = "sha256:b5eceb334d55fae5f316f783437392642ae18e16dcf4f1858d55d3c2a0f8f5d0"},
{file = "ruff-0.15.4-py3-none-linux_armv6l.whl", hash = "sha256:a1810931c41606c686bae8b5b9a8072adac2f611bb433c0ba476acba17a332e0"},
{file = "ruff-0.15.4-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:5a1632c66672b8b4d3e1d1782859e98d6e0b4e70829530666644286600a33992"},
{file = "ruff-0.15.4-py3-none-macosx_11_0_arm64.whl", hash = "sha256:a4386ba2cd6c0f4ff75252845906acc7c7c8e1ac567b7bc3d373686ac8c222ba"},
{file = "ruff-0.15.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b2496488bdfd3732747558b6f95ae427ff066d1fcd054daf75f5a50674411e75"},
{file = "ruff-0.15.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:3f1c4893841ff2d54cbda1b2860fa3260173df5ddd7b95d370186f8a5e66a4ac"},
{file = "ruff-0.15.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:820b8766bd65503b6c30aaa6331e8ef3a6e564f7999c844e9a547c40179e440a"},
{file = "ruff-0.15.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c9fb74bab47139c1751f900f857fa503987253c3ef89129b24ed375e72873e85"},
{file = "ruff-0.15.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f80c98765949c518142b3a50a5db89343aa90f2c2bf7799de9986498ae6176db"},
{file = "ruff-0.15.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:451a2e224151729b3b6c9ffb36aed9091b2996fe4bdbd11f47e27d8f2e8888ec"},
{file = "ruff-0.15.4-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:a8f157f2e583c513c4f5f896163a93198297371f34c04220daf40d133fdd4f7f"},
{file = "ruff-0.15.4-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:917cc68503357021f541e69b35361c99387cdbbf99bd0ea4aa6f28ca99ff5338"},
{file = "ruff-0.15.4-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:e9737c8161da79fd7cfec19f1e35620375bd8b2a50c3e77fa3d2c16f574105cc"},
{file = "ruff-0.15.4-py3-none-musllinux_1_2_i686.whl", hash = "sha256:291258c917539e18f6ba40482fe31d6f5ac023994ee11d7bdafd716f2aab8a68"},
{file = "ruff-0.15.4-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:3f83c45911da6f2cd5936c436cf86b9f09f09165f033a99dcf7477e34041cbc3"},
{file = "ruff-0.15.4-py3-none-win32.whl", hash = "sha256:65594a2d557d4ee9f02834fcdf0a28daa8b3b9f6cb2cb93846025a36db47ef22"},
{file = "ruff-0.15.4-py3-none-win_amd64.whl", hash = "sha256:04196ad44f0df220c2ece5b0e959c2f37c777375ec744397d21d15b50a75264f"},
{file = "ruff-0.15.4-py3-none-win_arm64.whl", hash = "sha256:60d5177e8cfc70e51b9c5fad936c634872a74209f934c1e79107d11787ad5453"},
{file = "ruff-0.15.4.tar.gz", hash = "sha256:3412195319e42d634470cc97aa9803d07e9d5c9223b99bcb1518f0c725f26ae1"},
]
[[package]]

View file

@ -1,7 +1,7 @@
[project]
name = "mpd-now-playable"
dynamic = ["version"]
description = "Expose your MPD server as a 'now playable' app on MacOS"
description = "Expose your MPD server as a 'now playable' app on macOS"
authors = [
{name = "Danielle McLean", email = "dani@00dani.me"},
]
@ -52,6 +52,14 @@ mpd-now-playable = 'mpd_now_playable.cli:main'
requires = ["pdm-backend"]
build-backend = "pdm.backend"
[dependency-groups]
dev = [
"pytest>=8.0",
"mypy>=1.11",
"ruff>=0.15",
"class-doc>=0.2.6",
]
[tool.mypy]
mypy_path = 'stubs'
plugins = ['pydantic.mypy', 'mpd_now_playable.tools.schema.plugin']
@ -77,8 +85,13 @@ select = [
"C90",
]
ignore = [
"ANN101", # missing-type-self
"ANN102", # missing-type-cls
]
[tool.ruff.lint.per-file-ignores]
"src/corefoundationasyncio/eventloop.py" = [
"ANN",
"I001",
"S101",
]
[tool.ruff.lint.flake8-annotations]
@ -101,12 +114,3 @@ write_template = "__version__ = '{}'"
[tool.pdm.build]
excludes = ["**/.mypy_cache"]
[tool.pdm.dev-dependencies]
dev = [
"mypy>=1.11.0",
"ruff>=0.1.6",
"class-doc>=0.2.6",
]

View file

@ -2,7 +2,7 @@ import asyncio
import sys
from collections.abc import Iterable
from rich import print
from rich import print as rich_print
from .__version__ import __version__
from .config.load import loadConfig
@ -40,9 +40,9 @@ def main() -> None:
print(f"mpd-now-playable v{__version__}")
return
print(f"mpd-now-playable v{__version__}")
rich_print(f"mpd-now-playable v{__version__}")
config = loadConfig()
print(config)
rich_print(config)
listener = MpdStateListener(config.cache)
receivers = tuple(construct_receiver(rec_config) for rec_config in config.receivers)

95
tests/test_cli.py Normal file
View file

@ -0,0 +1,95 @@
from types import SimpleNamespace
import mpd_now_playable.cli as cli
def test_main_help_prints_usage(monkeypatch, capsys) -> None:
monkeypatch.setattr(cli.sys, "argv", ["mpd-now-playable", "--help"])
def fail_load() -> None:
raise AssertionError("loadConfig should not run for --help")
monkeypatch.setattr(cli, "loadConfig", fail_load)
cli.main()
output = capsys.readouterr().out
assert "Usage: mpd-now-playable [OPTIONS]" in output
assert "-h, --help" in output
assert "-v, --version" in output
def test_main_version_prints_version(monkeypatch, capsys) -> None:
monkeypatch.setattr(cli.sys, "argv", ["mpd-now-playable", "--version"])
def fail_load() -> None:
raise AssertionError("loadConfig should not run for --version")
monkeypatch.setattr(cli, "loadConfig", fail_load)
cli.main()
output = capsys.readouterr().out
assert output.strip() == f"mpd-now-playable v{cli.__version__}"
def test_main_starts_listener_and_receivers(monkeypatch) -> None:
receiver_cfg_1 = SimpleNamespace(kind="websockets")
receiver_cfg_2 = SimpleNamespace(kind="websockets")
config = SimpleNamespace(
cache="memory://",
mpd=SimpleNamespace(host="127.0.0.1", port=6600),
receivers=(receiver_cfg_1, receiver_cfg_2),
)
listener = object()
receiver_1 = object()
receiver_2 = object()
fake_coroutine = object()
seen = {}
def fake_load_config() -> SimpleNamespace:
return config
def fake_listener_ctor(cache: str) -> object:
seen["cache"] = cache
return listener
def fake_construct_receiver(rcfg: SimpleNamespace) -> object:
if rcfg is receiver_cfg_1:
return receiver_1
if rcfg is receiver_cfg_2:
return receiver_2
raise AssertionError(f"Unexpected receiver config: {rcfg!r}")
class FakeLoopFactory:
@staticmethod
def make_loop() -> object:
return object()
def fake_choose_loop_factory(receivers: tuple[object, ...]) -> type[FakeLoopFactory]:
seen["receivers"] = receivers
return FakeLoopFactory
def fake_listen(cfg: SimpleNamespace, lst: object, receivers: tuple[object, ...]) -> object:
seen["listen_args"] = (cfg, lst, receivers)
return fake_coroutine
def fake_run(coro: object, *, loop_factory: object, debug: bool) -> None:
seen["run"] = (coro, loop_factory, debug)
monkeypatch.setattr(cli.sys, "argv", ["mpd-now-playable"])
monkeypatch.setattr(cli, "loadConfig", fake_load_config)
monkeypatch.setattr(cli, "MpdStateListener", fake_listener_ctor)
monkeypatch.setattr(cli, "construct_receiver", fake_construct_receiver)
monkeypatch.setattr(cli, "choose_loop_factory", fake_choose_loop_factory)
monkeypatch.setattr(cli, "listen", fake_listen)
monkeypatch.setattr(cli.asyncio, "run", fake_run)
cli.main()
assert seen["cache"] == "memory://"
assert seen["receivers"] == (receiver_1, receiver_2)
assert seen["listen_args"] == (config, listener, (receiver_1, receiver_2))
assert seen["run"] == (fake_coroutine, FakeLoopFactory.make_loop, False)