@@ -528,7 +528,7 @@ def test_cursor_close_handles_exception(self):
528528mock_backend = Mock ()
529529mock_connection = Mock ()
530530mock_op_handle = Mock ()
531-
531+
532532mock_backend .close_command .side_effect = Exception ("Test error" )
533533
534534cursor = client .Cursor (mock_connection ,mock_backend )
@@ -537,78 +537,80 @@ def test_cursor_close_handles_exception(self):
537537cursor .close ()
538538
539539mock_backend .close_command .assert_called_once_with (mock_op_handle )
540-
540+
541541self .assertIsNone (cursor .active_op_handle )
542-
542+
543543self .assertFalse (cursor .open )
544544
545545def test_cursor_context_manager_handles_exit_exception (self ):
546546"""Test that cursor's context manager handles exceptions during __exit__."""
547547mock_backend = Mock ()
548548mock_connection = Mock ()
549-
549+
550550cursor = client .Cursor (mock_connection ,mock_backend )
551551original_close = cursor .close
552552cursor .close = Mock (side_effect = Exception ("Test error during close" ))
553-
553+
554554try :
555555with cursor :
556556raise ValueError ("Test error inside context" )
557557except ValueError :
558558pass
559-
559+
560560cursor .close .assert_called_once ()
561561
562562def test_connection_close_handles_cursor_close_exception (self ):
563563"""Test that _close handles exceptions from cursor.close() properly."""
564564cursors_closed = []
565-
565+
566566def mock_close_with_exception ():
567567cursors_closed .append (1 )
568568raise Exception ("Test error during close" )
569-
569+
570570cursor1 = Mock ()
571571cursor1 .close = mock_close_with_exception
572-
572+
573573def mock_close_normal ():
574574cursors_closed .append (2 )
575-
575+
576576cursor2 = Mock ()
577577cursor2 .close = mock_close_normal
578-
578+
579579mock_backend = Mock ()
580580mock_session_handle = Mock ()
581-
581+
582582try :
583583for cursor in [cursor1 ,cursor2 ]:
584584try :
585585cursor .close ()
586586except Exception :
587587pass
588-
588+
589589mock_backend .close_session (mock_session_handle )
590590except Exception as e :
591591self .fail (f"Connection close should handle exceptions:{ e } " )
592-
593- self .assertEqual (cursors_closed , [1 ,2 ],"Both cursors should have close called" )
592+
593+ self .assertEqual (
594+ cursors_closed , [1 ,2 ],"Both cursors should have close called"
595+ )
594596
595597def test_resultset_close_handles_cursor_already_closed_error (self ):
596598"""Test that ResultSet.close() handles CursorAlreadyClosedError properly."""
597599result_set = client .ResultSet .__new__ (client .ResultSet )
598600result_set .thrift_backend = Mock ()
599- result_set .thrift_backend .CLOSED_OP_STATE = ' CLOSED'
601+ result_set .thrift_backend .CLOSED_OP_STATE = " CLOSED"
600602result_set .connection = Mock ()
601603result_set .connection .open = True
602- result_set .op_state = ' RUNNING'
604+ result_set .op_state = " RUNNING"
603605result_set .has_been_closed_server_side = False
604606result_set .command_id = Mock ()
605607
606608class MockRequestError (Exception ):
607609def __init__ (self ):
608610self .args = ["Error message" ,CursorAlreadyClosedError ()]
609-
611+
610612result_set .thrift_backend .close_command .side_effect = MockRequestError ()
611-
613+
612614original_close = client .ResultSet .close
613615try :
614616try :
@@ -624,11 +626,13 @@ def __init__(self):
624626finally :
625627result_set .has_been_closed_server_side = True
626628result_set .op_state = result_set .thrift_backend .CLOSED_OP_STATE
627-
628- result_set .thrift_backend .close_command .assert_called_once_with (result_set .command_id )
629-
629+
630+ result_set .thrift_backend .close_command .assert_called_once_with (
631+ result_set .command_id
632+ )
633+
630634assert result_set .has_been_closed_server_side is True
631-
635+
632636assert result_set .op_state == result_set .thrift_backend .CLOSED_OP_STATE
633637finally :
634638pass