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