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

18 statements  

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

1# tests/unit/test_cim_to_csv_linking.py 

2import pandas as pd 

3# import pytest 

4from distopf.cim_importer.cim_to_csv_converter import CIMToCSVConverter 

5 

6 

7def make_minimal_bus_df(): 

8 return pd.DataFrame( 

9 [ 

10 {"name": "sourcebus", "bus_type": "SWING", "mrid": "m1", "phases": "abc"}, 

11 {"name": "650", "bus_type": "PQ", "mrid": "m2", "phases": "abc"}, 

12 {"name": "rg60", "bus_type": "PQ", "mrid": "m3", "phases": "abc"}, 

13 ] 

14 ) 

15 

16 

17def make_minimal_branch_df(): 

18 return pd.DataFrame( 

19 [ 

20 {"from_name": "sourcebus", "to_name": "650", "name": "e1", "phases": "abc"}, 

21 {"from_name": "650", "to_name": "rg60", "name": "e2", "phases": "abc"}, 

22 ] 

23 ) 

24 

25 

26def test_link_dataframes_assigns_ids_and_maps_fb_tb(): 

27 conv = CIMToCSVConverter(cim_file="does_not_matter_for_test") 

28 bus_df = make_minimal_bus_df() 

29 branch_df = make_minimal_branch_df() 

30 data = dict( 

31 bus_data=bus_df, 

32 branch_data=branch_df, 

33 gen_data=pd.DataFrame(), 

34 cap_data=pd.DataFrame(), 

35 reg_data=pd.DataFrame(), 

36 ) 

37 data_out = conv._link_dataframes(data) 

38 bus_df_out = data_out["bus_data"] 

39 branch_df_out = data_out["branch_data"] 

40 # ids should be ints and start at 1 

41 assert set(bus_df_out["id"]) == set([1, 2, 3]) 

42 # fb and tb should exist and be ints on branch_df_out 

43 assert branch_df_out["fb"].dtype.kind in "iu" 

44 assert branch_df_out["tb"].dtype.kind in "iu" 

45 # The first node should be the swing bus id==1 

46 assert int(bus_df_out.loc[bus_df_out["name"] == "sourcebus", "id"].iloc[0]) == 1