Coverage for tests/cim_converter/unit/test_converter_run.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-11-13 17:34 -0800

1# tests/unit/test_converter_run.py 

2import pandas as pd 

3from pathlib import Path 

4from distopf.cim_importer import CIMToCSVConverter 

5 

6 

7def test_converter_end_to_end(tmp_path): 

8 # Use repository's cim file which exists in the repo 

9 project_root = Path(__file__).resolve().parents[3] 

10 test_cim = project_root / "tests" / "cim_converter" / "data" / "IEEE13.xml" 

11 assert test_cim.exists(), f"Expected test CIM at {test_cim}" 

12 outdir = tmp_path / "csvout" 

13 conv = CIMToCSVConverter(cim_file=str(test_cim)) 

14 # Do not validate (avoids validator interacting with full network) 

15 results = conv.convert(validate=False) 

16 conv.save(results, output_dir=str(outdir)) 

17 # Ensure dataframes present in result 

18 assert "branch_data" in results and "bus_data" in results 

19 # Ensure CSV files were written 

20 for fname in ["branch_data.csv", "bus_data.csv"]: 

21 p = outdir / fname 

22 assert p.exists() 

23 df = pd.read_csv(p) 

24 assert not df.empty 

25 branch_df = results["branch_data"] 

26 bus_df = results["bus_data"] 

27 assert len(branch_df) >= max(0, len(bus_df) - 1)