Skip to content

Commit 0f5bf69

Browse files
formatting (black)
1 parent b30616b commit 0f5bf69

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

tests/e2e/test_driver.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,9 @@ def test_closing_a_closed_connection_doesnt_fail(self, caplog):
856856
raise KeyboardInterrupt("Simulated interrupt")
857857
finally:
858858
if conn is not None:
859-
assert not conn.open, "Connection should be closed after KeyboardInterrupt"
859+
assert (
860+
not conn.open
861+
), "Connection should be closed after KeyboardInterrupt"
860862

861863
def test_cursor_close_properly_closes_operation(self):
862864
"""Test that Cursor.close() properly closes the active operation handle on the server."""
@@ -883,7 +885,9 @@ def test_cursor_close_properly_closes_operation(self):
883885
raise KeyboardInterrupt("Simulated interrupt")
884886
finally:
885887
if cursor is not None:
886-
assert not cursor.open, "Cursor should be closed after KeyboardInterrupt"
888+
assert (
889+
not cursor.open
890+
), "Cursor should be closed after KeyboardInterrupt"
887891

888892
def test_nested_cursor_context_managers(self):
889893
"""Test that nested cursor context managers properly close operations on the server."""

tests/unit/test_client.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def test_cursor_close_handles_exception(self):
528528
mock_backend = Mock()
529529
mock_connection = Mock()
530530
mock_op_handle = Mock()
531-
531+
532532
mock_backend.close_command.side_effect = Exception("Test error")
533533

534534
cursor = client.Cursor(mock_connection, mock_backend)
@@ -537,78 +537,80 @@ def test_cursor_close_handles_exception(self):
537537
cursor.close()
538538

539539
mock_backend.close_command.assert_called_once_with(mock_op_handle)
540-
540+
541541
self.assertIsNone(cursor.active_op_handle)
542-
542+
543543
self.assertFalse(cursor.open)
544544

545545
def test_cursor_context_manager_handles_exit_exception(self):
546546
"""Test that cursor's context manager handles exceptions during __exit__."""
547547
mock_backend = Mock()
548548
mock_connection = Mock()
549-
549+
550550
cursor = client.Cursor(mock_connection, mock_backend)
551551
original_close = cursor.close
552552
cursor.close = Mock(side_effect=Exception("Test error during close"))
553-
553+
554554
try:
555555
with cursor:
556556
raise ValueError("Test error inside context")
557557
except ValueError:
558558
pass
559-
559+
560560
cursor.close.assert_called_once()
561561

562562
def test_connection_close_handles_cursor_close_exception(self):
563563
"""Test that _close handles exceptions from cursor.close() properly."""
564564
cursors_closed = []
565-
565+
566566
def mock_close_with_exception():
567567
cursors_closed.append(1)
568568
raise Exception("Test error during close")
569-
569+
570570
cursor1 = Mock()
571571
cursor1.close = mock_close_with_exception
572-
572+
573573
def mock_close_normal():
574574
cursors_closed.append(2)
575-
575+
576576
cursor2 = Mock()
577577
cursor2.close = mock_close_normal
578-
578+
579579
mock_backend = Mock()
580580
mock_session_handle = Mock()
581-
581+
582582
try:
583583
for cursor in [cursor1, cursor2]:
584584
try:
585585
cursor.close()
586586
except Exception:
587587
pass
588-
588+
589589
mock_backend.close_session(mock_session_handle)
590590
except Exception as e:
591591
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+
)
594596

595597
def test_resultset_close_handles_cursor_already_closed_error(self):
596598
"""Test that ResultSet.close() handles CursorAlreadyClosedError properly."""
597599
result_set = client.ResultSet.__new__(client.ResultSet)
598600
result_set.thrift_backend = Mock()
599-
result_set.thrift_backend.CLOSED_OP_STATE = 'CLOSED'
601+
result_set.thrift_backend.CLOSED_OP_STATE = "CLOSED"
600602
result_set.connection = Mock()
601603
result_set.connection.open = True
602-
result_set.op_state = 'RUNNING'
604+
result_set.op_state = "RUNNING"
603605
result_set.has_been_closed_server_side = False
604606
result_set.command_id = Mock()
605607

606608
class MockRequestError(Exception):
607609
def __init__(self):
608610
self.args = ["Error message", CursorAlreadyClosedError()]
609-
611+
610612
result_set.thrift_backend.close_command.side_effect = MockRequestError()
611-
613+
612614
original_close = client.ResultSet.close
613615
try:
614616
try:
@@ -624,11 +626,13 @@ def __init__(self):
624626
finally:
625627
result_set.has_been_closed_server_side = True
626628
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+
630634
assert result_set.has_been_closed_server_side is True
631-
635+
632636
assert result_set.op_state == result_set.thrift_backend.CLOSED_OP_STATE
633637
finally:
634638
pass

0 commit comments

Comments
 (0)