@@ -299,35 +299,37 @@ def test_body_battery_data_get_mixed_valid_invalid():
299299def test_body_battery_data_get_unexpected_error ():
300300 """Test handling of unexpected errors during object creation."""
301301 mock_client = MagicMock ()
302-
302+
303303 # Create a special object that raises an exception when accessed
304304 class ExceptionRaisingDict (dict ):
305305 def get (self , key , default = None ):
306306 if key == "activityName" :
307307 raise RuntimeError ("Unexpected error during object creation" )
308308 return super ().get (key , default )
309-
309+
310310 # Create mock data with problematic item
311- mock_response_item = ExceptionRaisingDict ({
312- "event" : {
313- "eventType" : "sleep" ,
314- "eventStartTimeGmt" : "2023-07-20T10:00:00.000Z" ,
315- "timezoneOffset" : - 25200000 ,
316- "durationInMilliseconds" : 28800000 ,
317- "bodyBatteryImpact" : 35 ,
318- "feedbackType" : "good_sleep" ,
319- "shortFeedback" : "Good sleep"
320- },
321- "activityName" : None ,
322- "activityType" : None ,
323- "activityId" : None ,
324- "averageStress" : 15.5 ,
325- "stressValuesArray" : [[1689811800000 , 12 ]],
326- "bodyBatteryValuesArray" : [[1689811800000 , "charging" , 45 , 1.0 ]]
327- })
328-
311+ mock_response_item = ExceptionRaisingDict (
312+ {
313+ "event" : {
314+ "eventType" : "sleep" ,
315+ "eventStartTimeGmt" : "2023-07-20T10:00:00.000Z" ,
316+ "timezoneOffset" : - 25200000 ,
317+ "durationInMilliseconds" : 28800000 ,
318+ "bodyBatteryImpact" : 35 ,
319+ "feedbackType" : "good_sleep" ,
320+ "shortFeedback" : "Good sleep" ,
321+ },
322+ "activityName" : None ,
323+ "activityType" : None ,
324+ "activityId" : None ,
325+ "averageStress" : 15.5 ,
326+ "stressValuesArray" : [[1689811800000 , 12 ]],
327+ "bodyBatteryValuesArray" : [[1689811800000 , "charging" , 45 , 1.0 ]],
328+ }
329+ )
330+
329331 mock_client .connectapi .return_value = [mock_response_item ]
330-
332+
331333 result = BodyBatteryData .get ("2023-07-20" , client = mock_client )
332334 # Should handle unexpected errors and return empty list
333335 assert result == []
0 commit comments