Skip to content

Add pytest unit tests for opensensemap_api#12

Merged
fabaff merged 1 commit intomasterfrom
copilot/add-unittest-with-pytest
Apr 6, 2026
Merged

Add pytest unit tests for opensensemap_api#12
fabaff merged 1 commit intomasterfrom
copilot/add-unittest-with-pytest

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

No tests existed for the opensensemap_api package. This adds a full pytest suite using unittest.mock (no external HTTP mocking library required).

Changes

  • pyproject.toml — adds [project.optional-dependencies] test (pytest>=7, pytest-asyncio>=0.21) and configures asyncio_mode = "auto"
  • tests/conftest.py — shared mock data: a full MOCK_STATION_DATA response with all sensor types, and a MOCK_STATION_DATA_MINIMAL for edge cases
  • tests/test_opensensemap.py — 41 tests across four classes:
Class Coverage
TestInitialization base_url construction, empty initial data
TestProperties All metadata properties; None fallbacks for optional keys
TestSensorValues All 13 sensor value properties; missing sensor → None
TestGetValue Exact-title lookup, case-insensitivity, all _TITLES language aliases, empty/missing lastMeasurement
TestGetData Successful fetch; TimeoutError, ClientError, socket.gaierror each raise OpenSenseMapConnectionError
pip install -e ".[test]"
pytest tests/

@fabaff fabaff marked this pull request as ready for review April 6, 2026 23:58
@fabaff fabaff merged commit d6c8bdc into master Apr 6, 2026
@fabaff fabaff deleted the copilot/add-unittest-with-pytest branch April 6, 2026 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants