@@ -528,7 +528,7 @@ def test_cursor_close_handles_exception(self):
528
528
mock_backend = Mock ()
529
529
mock_connection = Mock ()
530
530
mock_op_handle = Mock ()
531
-
531
+
532
532
mock_backend .close_command .side_effect = Exception ("Test error" )
533
533
534
534
cursor = client .Cursor (mock_connection , mock_backend )
@@ -537,78 +537,80 @@ def test_cursor_close_handles_exception(self):
537
537
cursor .close ()
538
538
539
539
mock_backend .close_command .assert_called_once_with (mock_op_handle )
540
-
540
+
541
541
self .assertIsNone (cursor .active_op_handle )
542
-
542
+
543
543
self .assertFalse (cursor .open )
544
544
545
545
def test_cursor_context_manager_handles_exit_exception (self ):
546
546
"""Test that cursor's context manager handles exceptions during __exit__."""
547
547
mock_backend = Mock ()
548
548
mock_connection = Mock ()
549
-
549
+
550
550
cursor = client .Cursor (mock_connection , mock_backend )
551
551
original_close = cursor .close
552
552
cursor .close = Mock (side_effect = Exception ("Test error during close" ))
553
-
553
+
554
554
try :
555
555
with cursor :
556
556
raise ValueError ("Test error inside context" )
557
557
except ValueError :
558
558
pass
559
-
559
+
560
560
cursor .close .assert_called_once ()
561
561
562
562
def test_connection_close_handles_cursor_close_exception (self ):
563
563
"""Test that _close handles exceptions from cursor.close() properly."""
564
564
cursors_closed = []
565
-
565
+
566
566
def mock_close_with_exception ():
567
567
cursors_closed .append (1 )
568
568
raise Exception ("Test error during close" )
569
-
569
+
570
570
cursor1 = Mock ()
571
571
cursor1 .close = mock_close_with_exception
572
-
572
+
573
573
def mock_close_normal ():
574
574
cursors_closed .append (2 )
575
-
575
+
576
576
cursor2 = Mock ()
577
577
cursor2 .close = mock_close_normal
578
-
578
+
579
579
mock_backend = Mock ()
580
580
mock_session_handle = Mock ()
581
-
581
+
582
582
try :
583
583
for cursor in [cursor1 , cursor2 ]:
584
584
try :
585
585
cursor .close ()
586
586
except Exception :
587
587
pass
588
-
588
+
589
589
mock_backend .close_session (mock_session_handle )
590
590
except Exception as e :
591
591
self .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
+ )
594
596
595
597
def test_resultset_close_handles_cursor_already_closed_error (self ):
596
598
"""Test that ResultSet.close() handles CursorAlreadyClosedError properly."""
597
599
result_set = client .ResultSet .__new__ (client .ResultSet )
598
600
result_set .thrift_backend = Mock ()
599
- result_set .thrift_backend .CLOSED_OP_STATE = ' CLOSED'
601
+ result_set .thrift_backend .CLOSED_OP_STATE = " CLOSED"
600
602
result_set .connection = Mock ()
601
603
result_set .connection .open = True
602
- result_set .op_state = ' RUNNING'
604
+ result_set .op_state = " RUNNING"
603
605
result_set .has_been_closed_server_side = False
604
606
result_set .command_id = Mock ()
605
607
606
608
class MockRequestError (Exception ):
607
609
def __init__ (self ):
608
610
self .args = ["Error message" , CursorAlreadyClosedError ()]
609
-
611
+
610
612
result_set .thrift_backend .close_command .side_effect = MockRequestError ()
611
-
613
+
612
614
original_close = client .ResultSet .close
613
615
try :
614
616
try :
@@ -624,11 +626,13 @@ def __init__(self):
624
626
finally :
625
627
result_set .has_been_closed_server_side = True
626
628
result_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
+
630
634
assert result_set .has_been_closed_server_side is True
631
-
635
+
632
636
assert result_set .op_state == result_set .thrift_backend .CLOSED_OP_STATE
633
637
finally :
634
638
pass
0 commit comments