Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bieniu committed Apr 22, 2024
1 parent 897b2dd commit 955a84c
Show file tree
Hide file tree
Showing 9 changed files with 962 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ repos:
- id: pretty-format-json
args:
- --no-sort-keys
- --indent=4
- --autofix
- id: no-commit-to-branch
args:
- --branch=master
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ lint.ignore = [
"example.py" = [
"T201", # `print` found
]
"tests/*" = [
"S101", # Use of `assert` detected
]


[tool.ruff.lint.mccabe]
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for imgw-pib package."""
40 changes: 40 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Set up some common test helper things."""

import json
from pathlib import Path
from typing import Any, Self, cast

import pytest
from syrupy.assertion import SnapshotAssertion
from syrupy.extensions.amber import AmberSnapshotExtension
from syrupy.location import PyTestLocation


@pytest.fixture()
def weather_stations() -> list[dict[str, Any]]:
"""Return weather stations data from the fixture file."""
with Path.open("tests/fixtures/weather_stations.json", encoding="utf-8") as file:
return cast(list[dict[str, Any]], json.load(file))


@pytest.fixture()
def weather_station() -> dict[str, Any]:
"""Return weather station data from the fixture file."""
with Path.open("tests/fixtures/weather_station.json", encoding="utf-8") as file:
return cast(dict[str, Any], json.load(file))


@pytest.fixture()
def snapshot(snapshot: SnapshotAssertion) -> SnapshotAssertion:
"""Return snapshot assertion fixture."""
return snapshot.use_extension(SnapshotExtension)


class SnapshotExtension(AmberSnapshotExtension):
"""Extension for Syrupy."""

@classmethod
def dirname(cls: Self, *, test_location: PyTestLocation) -> str:
"""Return the directory for the snapshot files."""
test_dir = Path(test_location.filepath).parent
return str(test_dir.joinpath("snapshots"))
12 changes: 12 additions & 0 deletions tests/fixtures/weather_station.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id_stacji": "12600",
"stacja": "Bielsko Bia\u0142a",
"data_pomiaru": "2024-04-22",
"godzina_pomiaru": "7",
"temperatura": "0.8",
"predkosc_wiatru": "1",
"kierunek_wiatru": "310",
"wilgotnosc_wzgledna": "93.0",
"suma_opadu": "18.1",
"cisnienie": "1022.1"
}
Loading

0 comments on commit 955a84c

Please sign in to comment.