33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
import pytest
|
|
from utils import store_to_disk
|
|
|
|
# tmp_path ist ein pytest-Fixture — d.h. pytest stellt ihn automatisch bereit, ohne dass man ihn importieren muss.
|
|
# pytest startet
|
|
# → sieht Parameter "tmp_path" in der Funktionssignatur
|
|
# → erstellt automatisch ein temporäres Verzeichnis (z.B. /tmp/pytest-123/test_store_0/)
|
|
# → übergibt es als Path-Objekt an die Testfunktion
|
|
# → löscht es nach dem Test wieder
|
|
|
|
def test_store_to_disk_creates_file(tmp_path):
|
|
"""Stellt sicher, dass store_to_disk eine lesbare JSON-Datei erstellt."""
|
|
import json
|
|
|
|
elements = [
|
|
{"type": "node", "id": 1, "lat": 46.1835291, "lon": 6.8346732, "tags": {"name": "Jakobshorn"}},
|
|
{"type": "way", "id": 2, "lat": 46.1772269, "lon": 6.8402226, "tags": {"name": "Parsenn"}},
|
|
]
|
|
|
|
saved_path = store_to_disk(
|
|
results=elements,
|
|
poi_type="bergbahn",
|
|
output_dir=tmp_path,
|
|
)
|
|
|
|
assert saved_path.exists()
|
|
assert saved_path.name == "bergbahn_results.json"
|
|
|
|
with saved_path.open(encoding="utf-8") as f:
|
|
loaded = json.load(f)
|
|
|
|
assert loaded == elements # Inhalt identisch
|
|
assert len(loaded) == 2 |