- collecte : collecter_meteofrance, extraire_infoclimat, extraire_vp2, archiver_historique, importer_opendata ; WeatherLink allégé (alleger) - tests : meteofrance, infoclimat, vp2, archive, opendata (tous verts) - maquettes/accueil-carte : sources de la maquette (générateurs de tuiles, page, À propos, CGU, confidentialité) - forum : noyau local (rôles, droits, SQLite, serveur de test, 18 tests) - deploy : Caddyfile.vercors.me.v2 (non appliqué) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
32 lignes
1.2 KiB
Python
32 lignes
1.2 KiB
Python
"""Test de l'import open data : python -I tests/test_opendata.py"""
|
|
import gzip
|
|
import os
|
|
import sqlite3
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "collecte"))
|
|
import importer_opendata as io # noqa: E402
|
|
|
|
|
|
def test_import(tmp="test-od.csv.gz"):
|
|
lignes = ["NUM_POSTE;NOM_USUEL;AAAAMMJJHH;T;TN;TX;TD;U;FF;FXI;DD;RR1;PMER;NEIGETOT",
|
|
"38548001;VILLARD;2026010112;4.4;1.7;4.4;-3.3;58;1.8;3.9;220;0.0;;0",
|
|
"38548001;VILLARD;2026010113;;;;;;;;;;;",
|
|
"99999999;AUTRE;2026010112;9.9;;;;;;;;;;"]
|
|
with gzip.open(tmp, "wt", encoding="utf-8") as f:
|
|
f.write("\n".join(lignes) + "\n")
|
|
try:
|
|
db = sqlite3.connect(":memory:")
|
|
db.execute(io.SCHEMA)
|
|
assert io.importer_fichier(db, tmp) == 2 # le poste inconnu est ignoré
|
|
t, u, p = db.execute("SELECT t, u, pmer FROM horaire WHERE id = 'villard' ORDER BY ts LIMIT 1").fetchone()
|
|
assert (t, u, p) == (4.4, 58.0, None)
|
|
assert io.importer_fichier(db, tmp) == 2 and db.execute("SELECT COUNT(*) FROM horaire").fetchone()[0] == 2 # ré-import sans doublon
|
|
finally:
|
|
os.remove(tmp)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_import()
|
|
print("1 test OK")
|