Skip to content

Commit 17cbb99

Browse files
fix more tests
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 53975da commit 17cbb99

File tree

2 files changed

+48
-26
lines changed

2 files changed

+48
-26
lines changed

tests/unit/test_client.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,17 @@ def test_arraysize_buffer_size_passthrough(
186186

187187
def test_closing_result_set_with_closed_connection_soft_closes_commands(self):
188188
mock_connection = Mock()
189-
mock_backend = Mock()
189+
mock_backend = Mock(spec=ThriftDatabricksClient)
190190
mock_results = Mock()
191191
mock_backend.fetch_results.return_value = (Mock(), False)
192-
# Ensure isinstance check passes
192+
193+
# Ensure connection appears closed
194+
type(mock_connection).open = PropertyMock(return_value=False)
195+
# Ensure isinstance check passes if needed
193196
mock_backend.__class__ = ThriftDatabricksClient
194197

195198
# Setup session mock on the mock_connection
196199
mock_session = Mock()
197-
mock_session.open = False
198200
mock_session.backend = mock_backend
199201
type(mock_connection).session = PropertyMock(return_value=mock_session)
200202

@@ -204,11 +206,6 @@ def test_closing_result_set_with_closed_connection_soft_closes_commands(self):
204206
)
205207
result_set.results = mock_results
206208

207-
# Setup session mock on the mock_connection
208-
mock_session = Mock()
209-
mock_session.open = False
210-
type(mock_connection).session = PropertyMock(return_value=mock_session)
211-
212209
result_set.close()
213210

214211
self.assertFalse(mock_backend.close_command.called)

tests/unit/test_thrift_backend.py

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -889,12 +889,9 @@ def test_handle_execute_response_can_handle_without_direct_results(
889889
auth_provider=AuthProvider(),
890890
ssl_options=SSLOptions(),
891891
)
892-
(
893-
execute_response,
894-
_,
895-
_,
896-
_
897-
) = thrift_backend._handle_execute_response(execute_resp, Mock())
892+
(execute_response, _, _, _) = thrift_backend._handle_execute_response(
893+
execute_resp, Mock()
894+
)
898895
self.assertEqual(
899896
execute_response.status,
900897
CommandState.SUCCEEDED,
@@ -967,9 +964,12 @@ def test_use_arrow_schema_if_available(self, tcli_service_class):
967964
)
968965
)
969966
thrift_backend = self._make_fake_thrift_backend()
970-
execute_response, _, _, arrow_schema_bytes = thrift_backend._handle_execute_response(
971-
t_execute_resp, Mock()
972-
)
967+
(
968+
execute_response,
969+
_,
970+
_,
971+
arrow_schema_bytes,
972+
) = thrift_backend._handle_execute_response(t_execute_resp, Mock())
973973

974974
self.assertEqual(arrow_schema_bytes, arrow_schema_mock)
975975

@@ -1048,8 +1048,8 @@ def test_handle_execute_response_reads_has_more_rows_in_direct_results(
10481048
(
10491049
execute_response,
10501050
has_more_rows_result,
1051-
_,
1052-
_
1051+
_,
1052+
_,
10531053
) = thrift_backend._handle_execute_response(execute_resp, Mock())
10541054

10551055
self.assertEqual(is_direct_results, has_more_rows_result)
@@ -1183,7 +1183,12 @@ def test_execute_statement_calls_client_and_handle_execute_response(
11831183
ssl_options=SSLOptions(),
11841184
)
11851185
thrift_backend._handle_execute_response = Mock()
1186-
thrift_backend._handle_execute_response.return_value = (Mock(), Mock(), Mock(), Mock())
1186+
thrift_backend._handle_execute_response.return_value = (
1187+
Mock(),
1188+
Mock(),
1189+
Mock(),
1190+
Mock(),
1191+
)
11871192
cursor_mock = Mock()
11881193

11891194
result = thrift_backend.execute_command(
@@ -1219,7 +1224,12 @@ def test_get_catalogs_calls_client_and_handle_execute_response(
12191224
ssl_options=SSLOptions(),
12201225
)
12211226
thrift_backend._handle_execute_response = Mock()
1222-
thrift_backend._handle_execute_response.return_value = (Mock(), Mock(), Mock(), Mock())
1227+
thrift_backend._handle_execute_response.return_value = (
1228+
Mock(),
1229+
Mock(),
1230+
Mock(),
1231+
Mock(),
1232+
)
12231233
cursor_mock = Mock()
12241234

12251235
result = thrift_backend.get_catalogs(Mock(), 100, 200, cursor_mock)
@@ -1252,7 +1262,12 @@ def test_get_schemas_calls_client_and_handle_execute_response(
12521262
ssl_options=SSLOptions(),
12531263
)
12541264
thrift_backend._handle_execute_response = Mock()
1255-
thrift_backend._handle_execute_response.return_value = (Mock(), Mock(), Mock(), Mock())
1265+
thrift_backend._handle_execute_response.return_value = (
1266+
Mock(),
1267+
Mock(),
1268+
Mock(),
1269+
Mock(),
1270+
)
12561271
cursor_mock = Mock()
12571272

12581273
result = thrift_backend.get_schemas(
@@ -1294,7 +1309,12 @@ def test_get_tables_calls_client_and_handle_execute_response(
12941309
ssl_options=SSLOptions(),
12951310
)
12961311
thrift_backend._handle_execute_response = Mock()
1297-
thrift_backend._handle_execute_response.return_value = (Mock(), Mock(), Mock(), Mock())
1312+
thrift_backend._handle_execute_response.return_value = (
1313+
Mock(),
1314+
Mock(),
1315+
Mock(),
1316+
Mock(),
1317+
)
12981318
cursor_mock = Mock()
12991319

13001320
result = thrift_backend.get_tables(
@@ -1340,7 +1360,12 @@ def test_get_columns_calls_client_and_handle_execute_response(
13401360
ssl_options=SSLOptions(),
13411361
)
13421362
thrift_backend._handle_execute_response = Mock()
1343-
thrift_backend._handle_execute_response.return_value = (Mock(), Mock(), Mock(), Mock())
1363+
thrift_backend._handle_execute_response.return_value = (
1364+
Mock(),
1365+
Mock(),
1366+
Mock(),
1367+
Mock(),
1368+
)
13441369
cursor_mock = Mock()
13451370

13461371
result = thrift_backend.get_columns(
@@ -2258,8 +2283,8 @@ def test_execute_command_sets_complex_type_fields_correctly(
22582283
mock_handle_execute_response.return_value = (
22592284
mock_execute_response,
22602285
mock_arrow_schema,
2261-
Mock(),
2262-
Mock()
2286+
Mock(),
2287+
Mock(),
22632288
)
22642289

22652290
# Iterate through each possible combination of native types (True, False and unset)

0 commit comments

Comments
 (0)