8
8
from datetime import datetime , date
9
9
from uuid import UUID
10
10
11
- def noop_log_latency_decorator (* args , ** kwargs ):
12
- """
13
- This is a no-op decorator. It is used to patch the log_latency decorator
14
- during tests, so that the tests for client logic are not affected by the
15
- telemetry logging logic. It accepts any arguments and returns a decorator
16
- that returns the original function unmodified.
17
- """
18
- def decorator (func ):
19
- return func
20
- return decorator
21
-
22
- patch ('databricks.sql.telemetry.latency_logger.log_latency' , new = noop_log_latency_decorator ).start ()
23
-
24
11
from databricks .sql .thrift_api .TCLIService .ttypes import (
25
12
TOpenSessionResp ,
26
13
TExecuteStatementResp ,
@@ -51,6 +38,10 @@ def new(cls):
51
38
cls .apply_property_to_mock (ThriftBackendMock , staging_allowed_local_path = None )
52
39
MockTExecuteStatementResp = MagicMock (spec = TExecuteStatementResp ())
53
40
41
+ mock_retry_policy = Mock ()
42
+ mock_retry_policy .history = []
43
+ cls .apply_property_to_mock (ThriftBackendMock , retry_policy = mock_retry_policy )
44
+
54
45
cls .apply_property_to_mock (
55
46
MockTExecuteStatementResp ,
56
47
description = None ,
@@ -331,7 +322,7 @@ def test_executing_multiple_commands_uses_the_most_recent_command(
331
322
mock_result_sets [1 ].fetchall .assert_called_once_with ()
332
323
333
324
def test_closed_cursor_doesnt_allow_operations (self ):
334
- cursor = client .Cursor (Mock (), Mock ())
325
+ cursor = client .Cursor (Mock (), ThriftBackendMockFactory . new ())
335
326
cursor .close ()
336
327
337
328
with self .assertRaises (Error ) as e :
@@ -343,14 +334,19 @@ def test_closed_cursor_doesnt_allow_operations(self):
343
334
self .assertIn ("closed" , e .msg )
344
335
345
336
def test_negative_fetch_throws_exception (self ):
346
- result_set = client .ResultSet (Mock (), Mock (), Mock ())
337
+ mock_connection = Mock ()
338
+ mock_connection .get_session_id_hex .return_value = "test_session"
339
+ mock_execute_response = Mock ()
340
+ mock_execute_response .command_handle = None
341
+
342
+ result_set = client .ResultSet (mock_connection , mock_execute_response , ThriftBackendMockFactory .new ())
347
343
348
344
with self .assertRaises (ValueError ) as e :
349
345
result_set .fetchmany (- 1 )
350
346
351
347
def test_context_manager_closes_cursor (self ):
352
348
mock_close = Mock ()
353
- with client .Cursor (Mock (), Mock ()) as cursor :
349
+ with client .Cursor (Mock (), ThriftBackendMockFactory . new ()) as cursor :
354
350
cursor .close = mock_close
355
351
mock_close .assert_called_once_with ()
356
352
@@ -393,7 +389,7 @@ def test_get_schemas_parameters_passed_to_thrift_backend(self, mock_thrift_backe
393
389
for req_args in req_args_combinations :
394
390
req_args = {k : v for k , v in req_args .items () if v != "NOT_SET" }
395
391
with self .subTest (req_args = req_args ):
396
- mock_thrift_backend = Mock ()
392
+ mock_thrift_backend = ThriftBackendMockFactory . new ()
397
393
398
394
cursor = client .Cursor (Mock (), mock_thrift_backend )
399
395
cursor .schemas (** req_args )
@@ -416,7 +412,7 @@ def test_get_tables_parameters_passed_to_thrift_backend(self, mock_thrift_backen
416
412
for req_args in req_args_combinations :
417
413
req_args = {k : v for k , v in req_args .items () if v != "NOT_SET" }
418
414
with self .subTest (req_args = req_args ):
419
- mock_thrift_backend = Mock ()
415
+ mock_thrift_backend = ThriftBackendMockFactory . new ()
420
416
421
417
cursor = client .Cursor (Mock (), mock_thrift_backend )
422
418
cursor .tables (** req_args )
@@ -439,7 +435,7 @@ def test_get_columns_parameters_passed_to_thrift_backend(self, mock_thrift_backe
439
435
for req_args in req_args_combinations :
440
436
req_args = {k : v for k , v in req_args .items () if v != "NOT_SET" }
441
437
with self .subTest (req_args = req_args ):
442
- mock_thrift_backend = Mock ()
438
+ mock_thrift_backend = ThriftBackendMockFactory . new ()
443
439
444
440
cursor = client .Cursor (Mock (), mock_thrift_backend )
445
441
cursor .columns (** req_args )
0 commit comments