Skip to content

Commit 4294600

Browse files
Fix all tests
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
1 parent 30c04a6 commit 4294600

File tree

5 files changed

+23
-125
lines changed

5 files changed

+23
-125
lines changed

src/databricks/sql/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def get_protocol_version(openSessionResp: TOpenSessionResp):
443443
@property
444444
def open(self) -> bool:
445445
"""Return whether the connection is open by checking if the session is open."""
446-
return self.session.is_open
446+
return hasattr(self, 'session') and self.session.is_open
447447

448448
def cursor(
449449
self,

tests/unit/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def test_get_token_failure(self, token_source, http_response):
294294
mock_http_client.execute.return_value.__enter__.return_value = mock_response
295295
mock_http_client.execute.return_value.__exit__.return_value = None
296296

297-
with pytest.raises(Exception):
297+
with pytest.raises(Exception) as e:
298298
token_source.get_token()
299299
assert "Failed to get token: 400" in str(e.value)
300300

tests/unit/test_sea_queue.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99
import pytest
10-
from unittest.mock import Mock, patch
10+
from unittest.mock import Mock, patch, MagicMock
1111

1212
from databricks.sql.backend.sea.queue import (
1313
JsonQueue,
@@ -184,6 +184,7 @@ def description(self):
184184
def test_build_queue_json_array(self, json_manifest, sample_data):
185185
"""Test building a JSON array queue."""
186186
result_data = ResultData(data=sample_data)
187+
mock_http_client = MagicMock()
187188

188189
queue = SeaResultSetQueueFactory.build_queue(
189190
result_data=result_data,
@@ -194,6 +195,7 @@ def test_build_queue_json_array(self, json_manifest, sample_data):
194195
max_download_threads=10,
195196
sea_client=Mock(),
196197
lz4_compressed=False,
198+
http_client=mock_http_client,
197199
)
198200

199201
assert isinstance(queue, JsonQueue)
@@ -217,6 +219,8 @@ def test_build_queue_arrow_stream(
217219
]
218220
result_data = ResultData(data=None, external_links=external_links)
219221

222+
mock_http_client = MagicMock()
223+
220224
with patch(
221225
"databricks.sql.backend.sea.queue.ResultFileDownloadManager"
222226
), patch.object(SeaCloudFetchQueue, "_create_next_table", return_value=None):
@@ -229,13 +233,15 @@ def test_build_queue_arrow_stream(
229233
max_download_threads=10,
230234
sea_client=mock_sea_client,
231235
lz4_compressed=False,
236+
http_client=mock_http_client,
232237
)
233238

234239
assert isinstance(queue, SeaCloudFetchQueue)
235240

236241
def test_build_queue_invalid_format(self, invalid_manifest):
237242
"""Test building a queue with invalid format."""
238243
result_data = ResultData(data=[])
244+
mock_http_client = MagicMock()
239245

240246
with pytest.raises(ProgrammingError, match="Invalid result format"):
241247
SeaResultSetQueueFactory.build_queue(
@@ -247,6 +253,7 @@ def test_build_queue_invalid_format(self, invalid_manifest):
247253
max_download_threads=10,
248254
sea_client=Mock(),
249255
lz4_compressed=False,
256+
http_client=mock_http_client,
250257
)
251258

252259

@@ -339,6 +346,7 @@ def test_init_with_valid_initial_link(
339346
):
340347
"""Test initialization with valid initial link."""
341348
# Create a queue with valid initial link
349+
mock_http_client = MagicMock()
342350
with patch.object(SeaCloudFetchQueue, "_create_next_table", return_value=None):
343351
queue = SeaCloudFetchQueue(
344352
result_data=ResultData(external_links=[sample_external_link]),
@@ -349,6 +357,7 @@ def test_init_with_valid_initial_link(
349357
total_chunk_count=1,
350358
lz4_compressed=False,
351359
description=description,
360+
http_client=mock_http_client,
352361
)
353362

354363
# Verify attributes
@@ -367,6 +376,7 @@ def test_init_no_initial_links(
367376
):
368377
"""Test initialization with no initial links."""
369378
# Create a queue with empty initial links
379+
mock_http_client = MagicMock()
370380
queue = SeaCloudFetchQueue(
371381
result_data=ResultData(external_links=[]),
372382
max_download_threads=5,
@@ -376,6 +386,7 @@ def test_init_no_initial_links(
376386
total_chunk_count=0,
377387
lz4_compressed=False,
378388
description=description,
389+
http_client=mock_http_client,
379390
)
380391
assert queue.table is None
381392

@@ -462,7 +473,7 @@ def test_hybrid_disposition_with_attachment(
462473
# Create result data with attachment
463474
attachment_data = b"mock_arrow_data"
464475
result_data = ResultData(attachment=attachment_data)
465-
476+
mock_http_client = MagicMock()
466477
# Build queue
467478
queue = SeaResultSetQueueFactory.build_queue(
468479
result_data=result_data,
@@ -473,6 +484,7 @@ def test_hybrid_disposition_with_attachment(
473484
max_download_threads=10,
474485
sea_client=mock_sea_client,
475486
lz4_compressed=False,
487+
http_client=mock_http_client,
476488
)
477489

478490
# Verify ArrowQueue was created
@@ -508,7 +520,8 @@ def test_hybrid_disposition_with_external_links(
508520
# Create result data with external links but no attachment
509521
result_data = ResultData(external_links=external_links, attachment=None)
510522

511-
# Build queue
523+
# Build queue
524+
mock_http_client = MagicMock()
512525
queue = SeaResultSetQueueFactory.build_queue(
513526
result_data=result_data,
514527
manifest=arrow_manifest,
@@ -518,6 +531,7 @@ def test_hybrid_disposition_with_external_links(
518531
max_download_threads=10,
519532
sea_client=mock_sea_client,
520533
lz4_compressed=False,
534+
http_client=mock_http_client,
521535
)
522536

523537
# Verify SeaCloudFetchQueue was created
@@ -548,7 +562,7 @@ def test_hybrid_disposition_with_compressed_attachment(
548562

549563
# Create result data with attachment
550564
result_data = ResultData(attachment=compressed_data)
551-
565+
mock_http_client = MagicMock()
552566
# Build queue with lz4_compressed=True
553567
queue = SeaResultSetQueueFactory.build_queue(
554568
result_data=result_data,
@@ -559,6 +573,7 @@ def test_hybrid_disposition_with_compressed_attachment(
559573
max_download_threads=10,
560574
sea_client=mock_sea_client,
561575
lz4_compressed=True,
576+
http_client=mock_http_client,
562577
)
563578

564579
# Verify ArrowQueue was created with decompressed data

tests/unit/test_session.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ def test_http_header_passthrough(self, mock_client_class):
7575
call_kwargs = mock_client_class.call_args[1]
7676
assert ("foo", "bar") in call_kwargs["http_headers"]
7777

78+
@patch("%s.client.UnifiedHttpClient" % PACKAGE_NAME)
7879
@patch("%s.session.ThriftDatabricksClient" % PACKAGE_NAME)
79-
def test_tls_arg_passthrough(self, mock_client_class):
80+
def test_tls_arg_passthrough(self, mock_client_class, mock_http_client):
8081
databricks.sql.connect(
8182
**self.DUMMY_CONNECTION_ARGS,
8283
_tls_verify_hostname="hostname",

tests/unit/test_telemetry_retry.py

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)