import json, pathlib, pandas as pd, numpy as np from traite import synth ROOT = pathlib.Path(__file__).resolve().parents[3] def test_generation_deterministe(tmp_path, monkeypatch): monkeypatch.setattr(synth, "OUT", tmp_path) a = synth.ecrire_tout(); b = synth.ecrire_tout() pd.testing.assert_frame_equal(a["cas1"]["ventes"], b["cas1"]["ventes"]) pd.testing.assert_frame_equal(a["cas3"]["comparables"], b["cas3"]["comparables"]) assert (tmp_path / "README.md").exists() and (tmp_path / "calibration_journal.csv").exists() def test_coherence_interne(): v = pd.read_csv(ROOT / "data/synthetic/cas1_gatineau_ventes.csv") assert (v.prix_vente > 50_000).all() and (v.superficie_habitable_m2 > 40).all() and v.id_vente.is_unique q = pd.read_csv(ROOT / "data/synthetic/cas2_quebec_ventes_plex.csv") assert np.allclose(q.taux_global, (q.rne / q.prix_vente).round(4)) and np.allclose(q.mrb, (q.prix_vente / q.revenu_brut_potentiel).round(2)) m = pd.read_csv(ROOT / "data/synthetic/cas3_montreal_comparables.csv") assert m.taux_global.between(0.025, 0.09).all() e = pd.read_csv(ROOT / "data/synthetic/cas3_montreal_etat_locatif.csv") assert len(e) == 12 and (e.loyer_mensuel_contrat <= e.loyer_mensuel_marche + 1).all() c = pd.read_csv(ROOT / "data/synthetic/cas1_gatineau_couts.csv") assert np.allclose(c.montant, (c.quantite * c.prix_unitaire).round(2)) p = pd.read_csv(ROOT / "data/synthetic/cas4_portefeuille.csv"); s = pd.read_csv(ROOT / "data/synthetic/cas4_portefeuille_series.csv") assert set(p.id_immeuble) == set(s.id_immeuble) and (p.dette <= p.valeur_2026).all()