from pathlib import Path import pytest import yaml from excel_import.config import ImportConfig @pytest.fixture def config_file(tmp_path: Path) -> Path: cfg = { "dsn": "postgresql+psycopg2://u:p@localhost/db", "sheets": [ { "sheet": "Artikel", "header_row": 0, "target_table": "artikel", "mode": "replace", "columns": [ {"source": "Artikelnummer", "target": "art_nr", "dtype": "VARCHAR(50)"}, {"source": "Preis", "target": "preis"}, ], } ], } path = tmp_path / "config.yaml" path.write_text(yaml.dump(cfg)) return path def test_load_from_yaml(config_file: Path): cfg = ImportConfig.from_yaml(config_file) assert cfg.dsn == "postgresql+psycopg2://u:p@localhost/db" assert len(cfg.sheets) == 1 sheet = cfg.sheets[0] assert sheet.sheet == "Artikel" assert sheet.target_table == "artikel" assert sheet.mode == "replace" assert len(sheet.columns) == 2 assert sheet.columns[0].dtype == "VARCHAR(50)"