@@ -252,20 +252,45 @@ def test_availability_summary_plots_empty(availability_analysis_object):
252252def test_degradation_timeseries_plot (degradation_info ):
253253 power , yoy_rd , yoy_ci , yoy_info = degradation_info
254254
255- # test defaults
256- result = degradation_timeseries_plot (yoy_info )
257- assert_isinstance (result , plt .Figure )
258- assert (result .get_axes ()[0 ].get_xlim ()[0 ] == 17685.55 )
259- # test other label options
260- result = degradation_timeseries_plot (yoy_info = yoy_info , include_ci = False ,
261- label = 'center' , fig = result )
262- assert_isinstance (result , plt .Figure )
263- assert (result .get_axes ()[0 ].get_xlim ()[0 ] == 17304.4 )
264- result = degradation_timeseries_plot (yoy_info = yoy_info , include_ci = False , label = 'left' )
265- assert_isinstance (result , plt .Figure )
266- assert (result .get_axes ()[0 ].get_xlim ()[0 ] == 17130.5 )
267- result = degradation_timeseries_plot (yoy_info = yoy_info , include_ci = False , label = None )
268- assert_isinstance (result , plt .Figure )
255+ # test defaults (label='right')
256+ result_right = degradation_timeseries_plot (yoy_info )
257+ assert_isinstance (result_right , plt .Figure )
258+ xlim_right = result_right .get_axes ()[0 ].get_xlim ()[0 ]
259+
260+ # test label='center'
261+ result_center = degradation_timeseries_plot (yoy_info = yoy_info , include_ci = False ,
262+ label = 'center' , fig = result_right )
263+ assert_isinstance (result_center , plt .Figure )
264+ xlim_center = result_center .get_axes ()[0 ].get_xlim ()[0 ]
265+
266+ # test label='left'
267+ result_left = degradation_timeseries_plot (yoy_info = yoy_info , include_ci = False , label = 'left' )
268+ assert_isinstance (result_left , plt .Figure )
269+ xlim_left = result_left .get_axes ()[0 ].get_xlim ()[0 ]
270+
271+ # test label=None (should default to 'right')
272+ result_none = degradation_timeseries_plot (yoy_info = yoy_info , include_ci = False , label = None )
273+ assert_isinstance (result_none , plt .Figure )
274+ xlim_none = result_none .get_axes ()[0 ].get_xlim ()[0 ]
275+
276+ # Check that the xlim values are offset as expected
277+ # right > center > left (since offset_days increases)
278+ assert xlim_right > xlim_center > xlim_left
279+ assert xlim_right == xlim_none # label=None defaults to 'right'
280+
281+ # The expected difference from right to left is 548 days (1.5 yrs), allow 5% tolerance
282+ expected_diff = 548
283+ actual_diff = (xlim_right - xlim_left )
284+ tolerance = expected_diff * 0.05
285+ assert abs (actual_diff - expected_diff ) <= tolerance , \
286+ f"difference of right-left xlim { actual_diff } not within 5% of 1.5 yrs."
287+
288+ # The expected difference from right to center is 365 days, allow 5% tolerance
289+ expected_diff2 = 365
290+ actual_diff2 = (xlim_right - xlim_center )
291+ tolerance2 = expected_diff2 * 0.05
292+ assert abs (actual_diff2 - expected_diff2 ) <= tolerance2 , \
293+ f"difference of right-center xlim { actual_diff2 } not within 5% of 1 yr."
269294
270295 with pytest .raises (KeyError ):
271296 degradation_timeseries_plot ({'a' : 1 }, include_ci = False )
0 commit comments