Skip to content

Add a proper test suite - #1553

Merged
frenck merged 2 commits into
mainfrom
frenck/test-suite
Sep 30, 2026
Merged

frenck merged 2 commits into
mainfrom
frenck/test-suite

Conversation

@frenck

@frenck frenck commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Breaking change

None. Tests only.

Proposed change

The client had a single request test. Coverage on radio_browser.py was 35%, and the 60% floor was only met thanks to the models. This adds a real test suite and lets covdefaults enforce 100% coverage.

The setup follows python-fumis and python-elgato: shared fixtures in conftest.py (an aioresponses fixture, a client fixture, load_fixture, and the aiohttp stream_writer compatibility patch for aioresponses).

One thing specific to this library: the DNS SRV lookup for the API host is now mocked for every test. A failed request forgets the host, so without that mock a retry resolved the real Radio Browser servers. The suite now runs fine without any network access.

What is covered:

  • Request handling: headers, boolean query values, non-JSON responses, timeouts and connection errors, the five retries with backoff, recovering after a failure, the host lookup and its caching, and internal versus external sessions.
  • Every endpoint, with syrupy snapshots: stats, stations, a single station, station clicks, search, countries, languages and tags.
  • Country name resolution (including Kosovo and unknown codes), the name sort, language title casing, and the models.

The fixtures are real API responses, trimmed to a few items each. Tests describe the current behavior. Two known quirks are visible in the snapshots on purpose (station_count comes out as a string, and empty comma separated fields become ['']); the upcoming bugfix PR will update those snapshots.

Type of change

  • Dependency or tooling upgrade
  • Bugfix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Deprecation (replaces or removes a feature, with a migration path)
  • Breaking change (a fix or feature that changes existing behavior)
  • Code quality, refactor, or test-only change
  • Documentation only

Additional information

Checklist

  • I fully understand the code in this pull request and can explain every line, including any AI-assisted changes.
  • The change is covered by tests, and poetry run pytest passes locally. A pull request cannot be merged unless CI is green.
  • poetry run prek run --all-files passes (lint, format, and type checks).
  • No commented-out or dead code is left in the pull request.

The client had a single request test and 35% coverage on radio_browser.py,
kept above the 60% floor by the models alone.

- Share fixtures in conftest.py, like python-fumis and python-elgato: an
  aioresponses fixture, a client fixture, load_fixture, and the aiohttp
  stream_writer compatibility patch.
- Mock the DNS SRV lookup for every test. A failed request forgets the
  host, so a retry used to resolve the real API servers.
- Add fixtures captured from the live API, trimmed to a few items each.
- Cover every endpoint with snapshots, the error paths, retries, the host
  lookup, session handling and the models.
- Drop the 60% floor, so covdefaults enforces 100% coverage.
@frenck frenck added the maintenance Generic maintenance tasks. label Sep 30, 2026
SLF001 is already ignored for all tests in tests/ruff.toml.
@frenck
frenck merged commit bf19f30 into main Sep 30, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Generic maintenance tasks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant