Skip to content

Commit 5c1166a

Browse files
add unit tests for added methods
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent ec95c76 commit 5c1166a

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

tests/unit/test_sea_backend.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
from databricks.sql.backend.types import SessionId, CommandId, CommandState, BackendType
1616
from databricks.sql.types import SSLOptions
1717
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+
)
1924

2025

2126
class TestSeaBackend:
@@ -523,6 +528,34 @@ def test_command_management(
523528
sea_client.get_execution_result(thrift_command_id, mock_cursor)
524529
assert "Not a valid SEA command ID" in str(excinfo.value)
525530

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+
526559
def test_utility_methods(self, sea_client):
527560
"""Test utility methods."""
528561
# Test get_default_session_configuration_value
@@ -590,6 +623,18 @@ def test_utility_methods(self, sea_client):
590623
assert description[1][1] == "INT" # type_code
591624
assert description[1][6] is False # null_ok
592625

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+
593638
def test_unimplemented_metadata_methods(
594639
self, sea_client, sea_session_id, mock_cursor
595640
):

0 commit comments

Comments
 (0)