|
15 | 15 | from databricks.sql.backend.types import SessionId, CommandId, CommandState, BackendType |
16 | 16 | from databricks.sql.types import SSLOptions |
17 | 17 | from databricks.sql.auth.authenticators import AuthProvider |
18 | | -from databricks.sql.exc import Error, NotSupportedError, ServerOperationError |
| 18 | +from databricks.sql.exc import ( |
| 19 | + Error, |
| 20 | + NotSupportedError, |
| 21 | + ServerOperationError, |
| 22 | + DatabaseError, |
| 23 | +) |
19 | 24 |
|
20 | 25 |
|
21 | 26 | class TestSeaBackend: |
@@ -523,6 +528,34 @@ def test_command_management( |
523 | 528 | sea_client.get_execution_result(thrift_command_id, mock_cursor) |
524 | 529 | assert "Not a valid SEA command ID" in str(excinfo.value) |
525 | 530 |
|
| 531 | + def test_check_command_state(self, sea_client, sea_command_id): |
| 532 | + """Test _check_command_not_in_failed_or_closed_state method.""" |
| 533 | + # Test with RUNNING state (should not raise) |
| 534 | + sea_client._check_command_not_in_failed_or_closed_state( |
| 535 | + CommandState.RUNNING, sea_command_id |
| 536 | + ) |
| 537 | + |
| 538 | + # Test with SUCCEEDED state (should not raise) |
| 539 | + sea_client._check_command_not_in_failed_or_closed_state( |
| 540 | + CommandState.SUCCEEDED, sea_command_id |
| 541 | + ) |
| 542 | + |
| 543 | + # Test with CLOSED state (should raise DatabaseError) |
| 544 | + with pytest.raises(DatabaseError) as excinfo: |
| 545 | + sea_client._check_command_not_in_failed_or_closed_state( |
| 546 | + CommandState.CLOSED, sea_command_id |
| 547 | + ) |
| 548 | + assert "Command test-statement-123 unexpectedly closed server side" in str( |
| 549 | + excinfo.value |
| 550 | + ) |
| 551 | + |
| 552 | + # Test with FAILED state (should raise ServerOperationError) |
| 553 | + with pytest.raises(ServerOperationError) as excinfo: |
| 554 | + sea_client._check_command_not_in_failed_or_closed_state( |
| 555 | + CommandState.FAILED, sea_command_id |
| 556 | + ) |
| 557 | + assert "Command test-statement-123 failed" in str(excinfo.value) |
| 558 | + |
526 | 559 | def test_utility_methods(self, sea_client): |
527 | 560 | """Test utility methods.""" |
528 | 561 | # Test get_default_session_configuration_value |
@@ -590,6 +623,18 @@ def test_utility_methods(self, sea_client): |
590 | 623 | assert description[1][1] == "INT" # type_code |
591 | 624 | assert description[1][6] is False # null_ok |
592 | 625 |
|
| 626 | + # Test _extract_description_from_manifest with empty columns |
| 627 | + empty_manifest = MagicMock() |
| 628 | + empty_manifest.schema = {"columns": []} |
| 629 | + assert sea_client._extract_description_from_manifest(empty_manifest) is None |
| 630 | + |
| 631 | + # Test _extract_description_from_manifest with no columns key |
| 632 | + no_columns_manifest = MagicMock() |
| 633 | + no_columns_manifest.schema = {} |
| 634 | + assert ( |
| 635 | + sea_client._extract_description_from_manifest(no_columns_manifest) is None |
| 636 | + ) |
| 637 | + |
593 | 638 | def test_unimplemented_metadata_methods( |
594 | 639 | self, sea_client, sea_session_id, mock_cursor |
595 | 640 | ): |
|
0 commit comments