"""Lettura di config.toml e del CSV: errori attesi.""" import pytest from conftest import RADICE from fitseg import config, dati def test_config_reale_valida(): assert config.leggi(RADICE / "config.toml")["dati"]["serie"] == ["T_C", "dT_C"] def test_chiave_mancante(tmp_path): (tmp_path / "c.toml").write_text("[dati]\ncolonna_tempo='t'\n") with pytest.raises(config.ErroreConfig, match="chiavi mancanti"): config.leggi(tmp_path / "c.toml") def test_modelli_per_tipo_incompleto(tmp_path): testo = (RADICE / "config.toml").read_text().replace('raffreddamento = ["esp_decad"]', "raffreddamento = []") (tmp_path / "c.toml").write_text(testo) with pytest.raises(config.ErroreConfig, match="raffreddamento"): config.leggi(tmp_path / "c.toml") def test_config_inesistente(): with pytest.raises(config.ErroreConfig, match="impossibile leggere"): config.leggi("/non/esiste.toml") def test_csv_valido(cfg, tmp_path): (tmp_path / "d.csv").write_text("t_ms,T_C,dT_C\n100,20.0,0.1\n250,20.1,0.2\n") t, serie = dati.leggi_csv(tmp_path / "d.csv", cfg) assert t.tolist() == [0.1, 0.25] and serie["T_C"].tolist() == [20.0, 20.1] def test_csv_colonna_mancante(cfg, tmp_path): (tmp_path / "d.csv").write_text("t_ms,T_C\n100,20.0\n") with pytest.raises(dati.ErroreDati, match="dT_C"): dati.leggi_csv(tmp_path / "d.csv", cfg) def test_csv_tempo_non_crescente(cfg, tmp_path): (tmp_path / "d.csv").write_text("t_ms,T_C,dT_C\n200,20,0\n100,20,0\n") with pytest.raises(dati.ErroreDati, match="crescente"): dati.leggi_csv(tmp_path / "d.csv", cfg)