Skip to content

Commit e6a50d7

Browse files
author
Saksham Garg
committed
Fix test mocks to accept encoding parameter for Python 3.10-3.12 compatibility
- Updated mock_open_handler in test_publish_query_with_parameters_from_files to accept **kwargs - Added proper file mock for test_publish_query_disallows_mixed_segments - Fixed assertion text to match actual error message - All 54 tests now passing on Python 3.10, 3.11, 3.12, and 3.13
1 parent 5154b9b commit e6a50d7

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

src/managedcleanroom/azext_managedcleanroom/tests/latest/test_frontend_query.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def test_publish_query_with_parameters_from_files(self, mock_get_client):
289289
"postFilters": ""
290290
}
291291

292-
def mock_open_handler(filename, mode='r'):
292+
def mock_open_handler(filename, mode='r', **kwargs):
293293
content = {
294294
'segment1.json': json.dumps(segment_1),
295295
'segment2.json': json.dumps(segment_2),
@@ -468,22 +468,32 @@ def test_publish_query_disallows_mixed_segments(self, mock_get_client):
468468
mock_client = Mock()
469469
mock_get_client.return_value = mock_client
470470

471-
with self.assertRaises(CLIError) as context:
472-
frontend_collaboration_query_publish(
473-
cmd=Mock(),
474-
collaboration_id="test-collab-123",
475-
document_id="test-query-123",
476-
body=None,
477-
query_segment=[
478-
"@segment1.json",
479-
"SELECT * FROM table2"],
480-
# Mixed
481-
execution_sequence="1,2",
482-
input_datasets="dataset1:view1",
483-
output_dataset="output-dataset:results"
484-
)
471+
# Mock file content for segment1.json
472+
segment_1 = {
473+
"data": "SELECT * FROM table1",
474+
"executionSequence": 1,
475+
"preConditions": "",
476+
"postFilters": ""
477+
}
478+
mock_file_content = json.dumps(segment_1)
479+
480+
with patch('builtins.open', unittest.mock.mock_open(read_data=mock_file_content)):
481+
with self.assertRaises(CLIError) as context:
482+
frontend_collaboration_query_publish(
483+
cmd=Mock(),
484+
collaboration_id="test-collab-123",
485+
document_id="test-query-123",
486+
body=None,
487+
query_segment=[
488+
"@segment1.json",
489+
"SELECT * FROM table2"],
490+
# Mixed
491+
execution_sequence="1,2",
492+
input_datasets="dataset1:view1",
493+
output_dataset="output-dataset:results"
494+
)
485495

486-
self.assertIn("Cannot mix @file.json and inline SQL",
496+
self.assertIn("Cannot mix @file.json / JSON-dict and inline SQL",
487497
str(context.exception))
488498

489499
@patch('azext_managedcleanroom._frontend_custom.get_frontend_client')

0 commit comments

Comments
 (0)