Skip to content

Commit ac50669

Browse files
remove changes to sea test
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent e3cef5c commit ac50669

File tree

2 files changed

+64
-110
lines changed

2 files changed

+64
-110
lines changed

tests/unit/test_sea_backend.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
import pytest
9-
from unittest.mock import Mock, patch, MagicMock
9+
from unittest.mock import patch, MagicMock, Mock
1010

1111
from databricks.sql.backend.sea.backend import (
1212
SeaDatabricksClient,
@@ -216,17 +216,18 @@ def test_command_execution_sync(
216216
},
217217
"result": {"data": [["value1"]]},
218218
}
219+
mock_http_client._make_request.return_value = execute_response
219220

220221
with patch.object(
221222
sea_client, "get_execution_result", return_value="mock_result_set"
222223
) as mock_get_result:
223224
result = sea_client.execute_command(
224225
operation="SELECT 1",
225-
session_id=session_id,
226+
session_id=sea_session_id,
226227
max_rows=100,
227228
max_bytes=1000,
228229
lz4_compression=False,
229-
cursor=cursor,
230+
cursor=mock_cursor,
230231
use_cloud_fetch=False,
231232
parameters=[],
232233
async_op=False,
@@ -275,7 +276,7 @@ def test_command_execution_async(
275276
max_rows=100,
276277
max_bytes=1000,
277278
lz4_compression=False,
278-
cursor=cursor,
279+
cursor=mock_cursor,
279280
use_cloud_fetch=False,
280281
parameters=[],
281282
async_op=True,

tests/unit/test_sea_result_set.py

Lines changed: 59 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
"""
22
Tests for the SeaResultSet class.
3+
4+
This module contains tests for the SeaResultSet class, which implements
5+
the result set functionality for the SEA (Statement Execution API) backend.
36
"""
47

58
import pytest
6-
import unittest
79
from unittest.mock import patch, MagicMock, Mock
810

911
from databricks.sql.result_set import SeaResultSet
1012
from databricks.sql.backend.types import CommandId, CommandState, BackendType
1113

1214

13-
class TestSeaResultSet(unittest.TestCase):
14-
"""Tests for the SeaResultSet class."""
15+
class TestSeaResultSet:
16+
"""Test suite for the SeaResultSet class."""
1517

1618
@pytest.fixture
1719
def mock_connection(self):
@@ -40,130 +42,81 @@ def execute_response(self):
4042
mock_response.is_staging_operation = False
4143
return mock_response
4244

43-
def test_init_with_inline_data(self):
44-
"""Test initialization with inline data."""
45-
# Create mock result data and manifest
46-
from databricks.sql.backend.sea.models.base import ResultData, ResultManifest
47-
48-
result_data = ResultData(
49-
data=[[1, "Alice"], [2, "Bob"], [3, "Charlie"]], external_links=None
50-
)
51-
manifest = ResultManifest(
52-
format="JSON_ARRAY",
53-
schema={},
54-
total_row_count=3,
55-
total_byte_count=0,
56-
total_chunk_count=1,
57-
truncated=False,
58-
chunks=None,
59-
result_compression=None,
60-
)
61-
45+
def test_init_with_execute_response(
46+
self, mock_connection, mock_sea_client, execute_response
47+
):
48+
"""Test initializing SeaResultSet with an execute response."""
6249
result_set = SeaResultSet(
63-
connection=self.mock_connection,
64-
execute_response=self.mock_execute_response_inline,
65-
sea_client=self.mock_backend,
50+
connection=mock_connection,
51+
execute_response=execute_response,
52+
sea_client=mock_sea_client,
6653
buffer_size_bytes=1000,
6754
arraysize=100,
68-
result_data=result_data,
69-
manifest=manifest,
7055
)
7156

72-
# Check properties
73-
self.assertEqual(result_set.backend, self.mock_backend)
74-
self.assertEqual(result_set.buffer_size_bytes, 1000)
75-
self.assertEqual(result_set.arraysize, 100)
76-
77-
# Check statement ID
78-
self.assertEqual(result_set.statement_id, "test-statement-id")
79-
80-
# Check status
81-
self.assertEqual(result_set.status, CommandState.SUCCEEDED)
82-
83-
# Check description
84-
self.assertEqual(result_set.description, self.sample_description)
85-
86-
# Check results queue
87-
self.assertTrue(isinstance(result_set.results, JsonQueue))
88-
89-
def test_init_without_result_data(self):
90-
"""Test initialization without result data."""
91-
# Create a result set without providing result_data
57+
# Verify basic properties
58+
assert result_set.command_id == execute_response.command_id
59+
assert result_set.status == CommandState.SUCCEEDED
60+
assert result_set.connection == mock_connection
61+
assert result_set.backend == mock_sea_client
62+
assert result_set.buffer_size_bytes == 1000
63+
assert result_set.arraysize == 100
64+
assert result_set.description == execute_response.description
65+
66+
def test_close(self, mock_connection, mock_sea_client, execute_response):
67+
"""Test closing a result set."""
9268
result_set = SeaResultSet(
93-
connection=self.mock_connection,
94-
execute_response=self.mock_execute_response_inline,
95-
sea_client=self.mock_backend,
69+
connection=mock_connection,
70+
execute_response=execute_response,
71+
sea_client=mock_sea_client,
9672
buffer_size_bytes=1000,
9773
arraysize=100,
9874
)
9975

100-
# Check properties
101-
self.assertEqual(result_set.backend, self.mock_backend)
102-
self.assertEqual(result_set.statement_id, "test-statement-id")
103-
self.assertEqual(result_set.status, CommandState.SUCCEEDED)
104-
self.assertEqual(result_set.description, self.sample_description)
105-
self.assertTrue(isinstance(result_set.results, JsonQueue))
106-
107-
# Verify that the results queue is empty
108-
self.assertEqual(result_set.results.data_array, [])
109-
110-
def test_init_with_error(self):
111-
"""Test initialization with error response."""
112-
result_set = SeaResultSet(
113-
connection=self.mock_connection,
114-
execute_response=self.mock_execute_response_error,
115-
sea_client=self.mock_backend,
116-
)
76+
# Close the result set
77+
result_set.close()
11778

118-
# Check status
119-
self.assertEqual(result_set.status, CommandState.FAILED)
120-
121-
# Check that description is None
122-
self.assertIsNone(result_set.description)
123-
124-
def test_close(self):
125-
"""Test closing the result set."""
126-
# Setup
127-
from databricks.sql.backend.sea.models.base import ResultData, ResultManifest
128-
129-
result_data = ResultData(data=[[1, "Alice"]], external_links=None)
130-
manifest = ResultManifest(
131-
format="JSON_ARRAY",
132-
schema={},
133-
total_row_count=1,
134-
total_byte_count=0,
135-
total_chunk_count=1,
136-
truncated=False,
137-
chunks=None,
138-
result_compression=None,
139-
)
79+
# Verify the backend's close_command was called
80+
mock_sea_client.close_command.assert_called_once_with(result_set.command_id)
81+
assert result_set.has_been_closed_server_side is True
82+
assert result_set.status == CommandState.CLOSED
14083

84+
def test_close_when_already_closed_server_side(
85+
self, mock_connection, mock_sea_client, execute_response
86+
):
87+
"""Test closing a result set that has already been closed server-side."""
14188
result_set = SeaResultSet(
142-
connection=self.mock_connection,
143-
execute_response=self.mock_execute_response_inline,
144-
sea_client=self.mock_backend,
145-
result_data=result_data,
146-
manifest=manifest,
89+
connection=mock_connection,
90+
execute_response=execute_response,
91+
sea_client=mock_sea_client,
92+
buffer_size_bytes=1000,
93+
arraysize=100,
14794
)
95+
result_set.has_been_closed_server_side = True
14896

149-
# Mock the backend's close_command method
150-
self.mock_backend.close_command = MagicMock()
151-
152-
# Execute
97+
# Close the result set
15398
result_set.close()
15499

155-
# Verify
156-
self.mock_backend.close_command.assert_called_once_with(self.mock_command_id)
100+
# Verify the backend's close_command was NOT called
101+
mock_sea_client.close_command.assert_not_called()
102+
assert result_set.has_been_closed_server_side is True
103+
assert result_set.status == CommandState.CLOSED
157104

158-
def test_is_staging_operation(self):
159-
"""Test is_staging_operation property."""
105+
def test_close_when_connection_closed(
106+
self, mock_connection, mock_sea_client, execute_response
107+
):
108+
"""Test closing a result set when the connection is closed."""
109+
mock_connection.open = False
160110
result_set = SeaResultSet(
161-
connection=self.mock_connection,
162-
execute_response=self.mock_execute_response_inline,
163-
sea_client=self.mock_backend,
111+
connection=mock_connection,
112+
execute_response=execute_response,
113+
sea_client=mock_sea_client,
114+
buffer_size_bytes=1000,
115+
arraysize=100,
164116
)
165117

166-
self.assertFalse(result_set.is_staging_operation)
118+
# Close the result set
119+
result_set.close()
167120

168121
# Verify the backend's close_command was NOT called
169122
mock_sea_client.close_command.assert_not_called()

0 commit comments

Comments
 (0)