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

22 statements  

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

1# tests/unit/test_phase_utils.py 

2from cimgraph.data_profile import cimhub_2023 as cim 

3from distopf.cim_importer.utils.phase_utils import PhaseUtils 

4 

5 

6def make_obj_with_value(v): 

7 """Create a small real dataclass instance and attach a .value attribute to it.""" 

8 obj = cim.TransformerTankEnd() 

9 # attach .value attribute (allowed) for PhaseUtils.get_phase_str 

10 setattr(obj, "value", v) 

11 return obj 

12 

13 

14def test_get_phase_str_various_inputs(): 

15 assert PhaseUtils.get_phase_str(make_obj_with_value("s1")) == "s1" 

16 assert PhaseUtils.get_phase_str(make_obj_with_value("S2")) == "s2" 

17 assert PhaseUtils.get_phase_str(make_obj_with_value("A")) == "a" 

18 assert PhaseUtils.get_phase_str(make_obj_with_value("b")) == "b" 

19 assert PhaseUtils.get_phase_str(make_obj_with_value("C")) == "c" 

20 # For unknown values the implementation returns a string (not None) — assert it's a string 

21 res = PhaseUtils.get_phase_str(make_obj_with_value("unknown")) 

22 assert isinstance(res, str) 

23 # Also accept plain strings 

24 assert PhaseUtils.get_phase_str(cim.PhaseCode(value="A")) == "a" 

25 assert PhaseUtils.get_phase_str(cim.PhaseCode(value="s1")) == "s1" 

26 

27 

28def test_filter_standard_phases_behavior(): 

29 assert PhaseUtils.filter_standard_phases("abcs1") == "abc" 

30 # Implementation returns fallback 'abc' when only s1/s2 present 

31 assert PhaseUtils.filter_standard_phases("s1s2") == "abc" 

32 assert PhaseUtils.filter_standard_phases("a") == "a" 

33 assert PhaseUtils.filter_standard_phases("") == "abc" 

34 assert PhaseUtils.filter_standard_phases(["a", "b", "s1"]) == "ab"