Spaces:
Runtime error
Runtime error
Download tests/test_parser.py from Archaeo/rheinpegel-python-WebApp: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/spaces/Archaeo/rheinpegel-python-WebApp/resolve/82b65ffa2a6825cd788222fcf6fecfe68dbb2283/tests/test_parser.py
- Command line
-
hf download hf://spaces/Archaeo/rheinpegel-python-WebApp@82b65ffa2a6825cd788222fcf6fecfe68dbb2283/tests/test_parser.py
-
curl -L -o test_parser.py https://huggingface.co/spaces/Archaeo/rheinpegel-python-WebApp/resolve/82b65ffa2a6825cd788222fcf6fecfe68dbb2283/tests/test_parser.py
1.68 kB
| from datetime import datetime | |
| from zoneinfo import ZoneInfo | |
| import pytest | |
| from app.config import Settings | |
| from app.fetcher import _build_measurement_from_payload, _build_measurement_from_xml | |
| from app.models import Measurement, Trend | |
| def settings() -> Settings: | |
| return Settings( | |
| source_url="https://example.com", | |
| refresh_seconds=120, | |
| tz="Europe/Berlin", | |
| port=8000, | |
| ) | |
| def test_parse_json_payload(settings: Settings) -> None: | |
| previous = Measurement( | |
| level_cm=350, | |
| timestamp=datetime(2024, 1, 1, 11, 0, tzinfo=ZoneInfo("Europe/Berlin")), | |
| trend=Trend.STABLE, | |
| ) | |
| payload = { | |
| "level": 356.4, | |
| "timestamp": "2024-01-01T10:00:00Z", | |
| } | |
| measurement = _build_measurement_from_payload(payload, settings, previous) | |
| assert measurement.level_cm == 356 | |
| assert measurement.trend == Trend.RISING | |
| assert measurement.timestamp.tzinfo is not None | |
| assert measurement.timestamp.tzinfo.key == "Europe/Berlin" | |
| def test_parse_xml_payload(settings: Settings) -> None: | |
| previous = Measurement( | |
| level_cm=410, | |
| timestamp=datetime(2024, 1, 1, 12, 0, tzinfo=ZoneInfo("Europe/Berlin")), | |
| trend=Trend.STABLE, | |
| ) | |
| xml = """ | |
| <root> | |
| <Wasserstand>404.2</Wasserstand> | |
| <Messzeit>2024-01-01T10:00:00Z</Messzeit> | |
| </root> | |
| """ | |
| measurement = _build_measurement_from_xml(xml, settings, previous) | |
| assert measurement.level_cm == 404 | |
| assert measurement.trend == Trend.FALLING | |
| assert measurement.timestamp.astimezone(ZoneInfo("Europe/Berlin")).hour == 11 | |