Coverage for tests/cim_converter/unit/test_topology_validator.py: 100%
19 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-13 17:34 -0800
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-13 17:34 -0800
1# tests/unit/test_topology_validator.py
2import pandas as pd
3# import pytest
4from distopf.cim_importer.validators.topology_validator import TopologyValidator
7def test_validate_empty_branch_data():
8 tv = TopologyValidator()
9 empty = pd.DataFrame(columns=["from_name", "to_name"])
10 result = tv.validate_tree_topology(empty)
11 assert not result["valid"]
12 assert "No branch data found" in result["issues"][0]
15def test_validate_disconnected_and_orphaned():
16 tv = TopologyValidator()
17 # Two disconnected edges -> two components
18 df = pd.DataFrame(
19 [
20 {
21 "from_name": "A",
22 "to_name": "B",
23 "raa": 0.01,
24 "xaa": 0.02,
25 "v_ln_base": 120,
26 },
27 {
28 "from_name": "C",
29 "to_name": "D",
30 "raa": 0.01,
31 "xaa": 0.02,
32 "v_ln_base": 120,
33 },
34 ]
35 )
36 res = tv.validate_tree_topology(df)
37 assert not res["valid"]
38 assert any(
39 "disconnected" in issue.lower() and "component" in issue.lower()
40 for issue in res["issues"]
41 )
44def test_negative_impedance_and_missing_voltage_warning():
45 tv = TopologyValidator()
46 df = pd.DataFrame(
47 [
48 {
49 "from_name": "A",
50 "to_name": "B",
51 "raa": -0.1,
52 "xaa": 0.0,
53 "v_ln_base": 120,
54 "type": "ACLineSegment",
55 },
56 {
57 "from_name": "B",
58 "to_name": "C",
59 "raa": 0.0,
60 "xaa": 0.0,
61 "v_ln_base": None,
62 "type": "transformer",
63 },
64 ]
65 )
66 res = tv.validate_tree_topology(df)
67 # Should produce warnings for negative raa and missing v_ln_base, but overall might still be valid or not; check warnings content
68 assert any(
69 "negative" in w.lower() or "missing voltage base" in w.lower()
70 for w in res["warnings"]
71 )