88from datetime import datetime , date
99from uuid import UUID
1010
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-
2411from databricks .sql .thrift_api .TCLIService .ttypes import (
2512 TOpenSessionResp ,
2613 TExecuteStatementResp ,
@@ -51,6 +38,10 @@ def new(cls):
5138 cls .apply_property_to_mock (ThriftBackendMock , staging_allowed_local_path = None )
5239 MockTExecuteStatementResp = MagicMock (spec = TExecuteStatementResp ())
5340
41+ mock_retry_policy = Mock ()
42+ mock_retry_policy .history = []
43+ cls .apply_property_to_mock (ThriftBackendMock , retry_policy = mock_retry_policy )
44+
5445 cls .apply_property_to_mock (
5546 MockTExecuteStatementResp ,
5647 description = None ,
@@ -331,7 +322,7 @@ def test_executing_multiple_commands_uses_the_most_recent_command(
331322 mock_result_sets [1 ].fetchall .assert_called_once_with ()
332323
333324 def test_closed_cursor_doesnt_allow_operations (self ):
334- cursor = client .Cursor (Mock (), Mock ())
325+ cursor = client .Cursor (Mock (), ThriftBackendMockFactory . new ())
335326 cursor .close ()
336327
337328 with self .assertRaises (Error ) as e :
@@ -343,14 +334,19 @@ def test_closed_cursor_doesnt_allow_operations(self):
343334 self .assertIn ("closed" , e .msg )
344335
345336 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 ())
347343
348344 with self .assertRaises (ValueError ) as e :
349345 result_set .fetchmany (- 1 )
350346
351347 def test_context_manager_closes_cursor (self ):
352348 mock_close = Mock ()
353- with client .Cursor (Mock (), Mock ()) as cursor :
349+ with client .Cursor (Mock (), ThriftBackendMockFactory . new ()) as cursor :
354350 cursor .close = mock_close
355351 mock_close .assert_called_once_with ()
356352
@@ -393,7 +389,7 @@ def test_get_schemas_parameters_passed_to_thrift_backend(self, mock_thrift_backe
393389 for req_args in req_args_combinations :
394390 req_args = {k : v for k , v in req_args .items () if v != "NOT_SET" }
395391 with self .subTest (req_args = req_args ):
396- mock_thrift_backend = Mock ()
392+ mock_thrift_backend = ThriftBackendMockFactory . new ()
397393
398394 cursor = client .Cursor (Mock (), mock_thrift_backend )
399395 cursor .schemas (** req_args )
@@ -416,7 +412,7 @@ def test_get_tables_parameters_passed_to_thrift_backend(self, mock_thrift_backen
416412 for req_args in req_args_combinations :
417413 req_args = {k : v for k , v in req_args .items () if v != "NOT_SET" }
418414 with self .subTest (req_args = req_args ):
419- mock_thrift_backend = Mock ()
415+ mock_thrift_backend = ThriftBackendMockFactory . new ()
420416
421417 cursor = client .Cursor (Mock (), mock_thrift_backend )
422418 cursor .tables (** req_args )
@@ -439,7 +435,7 @@ def test_get_columns_parameters_passed_to_thrift_backend(self, mock_thrift_backe
439435 for req_args in req_args_combinations :
440436 req_args = {k : v for k , v in req_args .items () if v != "NOT_SET" }
441437 with self .subTest (req_args = req_args ):
442- mock_thrift_backend = Mock ()
438+ mock_thrift_backend = ThriftBackendMockFactory . new ()
443439
444440 cursor = client .Cursor (Mock (), mock_thrift_backend )
445441 cursor .columns (** req_args )
0 commit comments