This project includes comprehensive unit tests for the Koa Sonos StreamDeck controller.
-
sonos_streamdeck.py: Main StreamDeck controller logic (29 tests)- Network utilities (IP detection)
- Sonos playback control (toggle loop, podcast playback)
- StreamDeck UI (button images, volume display)
- Event handlers (button presses, dial turns)
-
fetch_podcasts.py: Podcast RSS feed management (20 tests)- Text slugification
- Episode downloading
- Directory management
- Cleanup of old episodes
python3 -m pytest -vpython3 -m pytest tests/test_sonos_streamdeck.py -v
python3 -m pytest tests/test_fetch_podcasts.py -vpython3 -m pytest tests/test_sonos_streamdeck.py::test_toggle_loop_starts_playback_when_stopped -vpython3 -m pytest -k "dial" -v # Run all dial-related tests
python3 -m pytest -k "podcast" -v # Run all podcast-related testsThe tests mock out hardware dependencies to run without actual hardware:
- StreamDeck: Mocked in
conftest.py- no physical StreamDeck device required - Sonos Speaker: Mocked with a
MockSpeakerclass that simulates volume control and playback - Network Requests: Mocked using
requests-mockfor podcast downloads
mock_speaker: Simulated Sonos speaker with volume controlmock_deck: Simulated StreamDeck devicetemp_podcast_dir: Temporary directory for testing file operationsrequests_mock: HTTP request mocking for podcast downloads
tests/: Test directory containing all test filesconftest.py: Shared test configuration and hardware mocking setuptest_sonos_streamdeck.py: Tests for StreamDeck control and Sonos integrationtest_fetch_podcasts.py: Tests for podcast feed parsing and downloading__init__.py: Package initialization
- Hardware Independence: Tests run completely without hardware - StreamDeck and Sonos are fully mocked
- Test Isolation: Each test runs independently with fresh fixtures
- No Side Effects: Tests use temporary directories and don't modify actual files
- Fast Execution: Full test suite runs in ~0.1 seconds
These tests ensure that functionality remains intact when refactoring or adding features. Always run the test suite before and after making changes:
# Before changes
python3 -m pytest -v
# Make your changes...
# After changes
python3 -m pytest -vIf tests fail, the output will show exactly which functionality broke, making debugging much easier.