@@ -101,6 +101,7 @@ def _setup_redis_mocks(self, redis_service, sessions_data=None):
101101 mock_context_manager .__aenter__ = AsyncMock (return_value = mock_pipe )
102102 mock_context_manager .__aexit__ = AsyncMock (return_value = None )
103103 redis_service .cache .pipeline = MagicMock (return_value = mock_context_manager )
104+
104105 redis_service .cache .srem = AsyncMock ()
105106 redis_service .cache .get = AsyncMock (return_value = None ) # Default to no session
106107
@@ -151,9 +152,11 @@ async def test_create_get_session(self, redis_service):
151152 assert session .user_id == user_id
152153 assert session .id is not None
153154 assert session .state == state
155+
156+ # Allow tiny float/clock rounding differences (~1ms)
154157 assert (
155158 session .last_update_time
156- <= datetime .now ().astimezone (timezone .utc ).timestamp ()
159+ <= datetime .now ().astimezone (timezone .utc ).timestamp () + 0.001
157160 )
158161
159162 # Mock individual session retrieval
@@ -274,7 +277,9 @@ async def test_append_event_with_bytes(self, redis_service):
274277 test_content = types .Content (
275278 role = "user" ,
276279 parts = [
277- types .Part .from_bytes (data = b"test_image_data" , mime_type = "image/png" ),
280+ types .Part .from_bytes (
281+ data = b"test_image_data" , mime_type = "image/png"
282+ ),
278283 ],
279284 )
280285 test_grounding_metadata = types .GroundingMetadata (
@@ -314,7 +319,10 @@ async def test_append_event_with_bytes(self, redis_service):
314319 # Verify the binary content was preserved through serialization
315320 retrieved_event = retrieved_session .events [0 ]
316321 assert retrieved_event .content .parts [0 ].inline_data .data == b"test_image_data"
317- assert retrieved_event .content .parts [0 ].inline_data .mime_type == "image/png"
322+ assert (
323+ retrieved_event .content .parts [0 ].inline_data .mime_type
324+ == "image/png"
325+ )
318326 assert (
319327 retrieved_event .grounding_metadata .search_entry_point .sdk_blob
320328 == b"test_sdk_blob"
@@ -343,7 +351,10 @@ async def test_get_session_with_config(self, redis_service):
343351 # Test num_recent_events filter
344352 config = GetSessionConfig (num_recent_events = 3 )
345353 filtered_session = await redis_service .get_session (
346- app_name = app_name , user_id = user_id , session_id = session .id , config = config
354+ app_name = app_name ,
355+ user_id = user_id ,
356+ session_id = session .id ,
357+ config = config ,
347358 )
348359
349360 assert len (filtered_session .events ) == 3
@@ -352,7 +363,10 @@ async def test_get_session_with_config(self, redis_service):
352363 # Test after_timestamp filter
353364 config = GetSessionConfig (after_timestamp = 3.0 )
354365 filtered_session = await redis_service .get_session (
355- app_name = app_name , user_id = user_id , session_id = session .id , config = config
366+ app_name = app_name ,
367+ user_id = user_id ,
368+ session_id = session .id ,
369+ config = config ,
356370 )
357371
358372 assert len (filtered_session .events ) == 3 # Events 3, 4, 5
@@ -367,7 +381,9 @@ async def test_delete_session(self, redis_service):
367381
368382 self ._setup_redis_mocks (redis_service ) # Empty sessions
369383 await redis_service .delete_session (
370- app_name = app_name , user_id = user_id , session_id = session_id
384+ app_name = app_name ,
385+ user_id = user_id ,
386+ session_id = session_id ,
371387 )
372388 pipeline_mock = redis_service .cache .pipeline .return_value
373389 pipe_mock = await pipeline_mock .__aenter__ ()
@@ -377,7 +393,9 @@ async def test_delete_session(self, redis_service):
377393 self ._setup_redis_mocks (redis_service )
378394
379395 await redis_service .delete_session (
380- app_name = app_name , user_id = user_id , session_id = session_id
396+ app_name = app_name ,
397+ user_id = user_id ,
398+ session_id = session_id ,
381399 )
382400
383401 pipeline_mock = redis_service .cache .pipeline .return_value
@@ -526,7 +544,10 @@ async def test_decode_responses_handling(self, redis_service):
526544 session_id = "test_session"
527545
528546 # Test with bytes response (decode_responses=False)
529- session_data = '{"app_name": "test_app", "user_id": "test_user", "id": "test_session", "state": {}, "events": [], "last_update_time": 1234567890}'
547+ session_data = (
548+ '{"app_name": "test_app", "user_id": "test_user", "id": "test_session", '
549+ '"state": {}, "events": [], "last_update_time": 1234567890}'
550+ )
530551 redis_service .cache .get = AsyncMock (return_value = session_data .encode ())
531552 redis_service .cache .hgetall = AsyncMock (return_value = {})
532553
0 commit comments