pypowsybl
pypowsybl copied to clipboard
Unit tests readability/maintainability
- Do you want to request a feature or report a bug?
Code improvement
- What is the current behavior?
Unit tests involve a lot of dataframe creation and comparisons. Those dataframes are created using usual factory functions, but it makes them not easily readable nor updatable.
- What is the expected behavior?
We could load dataframes from a textual representation using multiline strings:
# Before
expected = pd.DataFrame(
index=pd.Series(name='id', data=['VSC1', 'VSC2']),
columns=['name', 'loss_factor', 'min_q', 'max_q', 'reactive_limits_kind', 'target_v', 'target_q',
'voltage_regulator_on', 'regulated_element_id', 'p', 'q', 'i', 'voltage_level_id', 'bus_id',
'connected'],
data=[
['VSC1', 1.1, NaN, NaN, 'CURVE', 300, 400, True, 'VSC2', 10.11, -512.081, 739.27, 'S1VL2', 'S1VL2_0', True],
['VSC2', 1.1, -350, 400, 'MIN_MAX', 1, 2, False, 'VSC1', -9.89, -120, 170.032, 'S2VL1', 'S2VL1_0', True]
]
)
# After
expected_str = """
id name loss_factor min_q max_q reactive_limits_kind target_v target_q voltage_regulator_on regulated_element_id p q i voltage_level_id bus_id connected
VSC1 VSC1 1.1 NaN NaN CURVE 300 400 True VSC2 10.11 -512.081 739.270 S1VL2 S1VL2_0 True
VSC2 VSC2 1.1 -350.0 400.0 MIN_MAX 1 2 False VSC1 -9.89 -120.000 170.032 S2VL1 S2VL1_0 True
"""
- What is the motivation / use case for changing the behavior?
Mostly understanding of tests and convenience to update them.
Started in #408, using util.dataframe_from_string
method