Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion databricks/sdk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ def __init__(self, cmd: List[str], token_type_field: str, access_token_field: st

@staticmethod
def _parse_expiry(expiry: str) -> datetime:
for fmt in ("%Y-%m-%d %H:%M:%S.%f", "%Y-%m-%d %H:%M:%S", "%Y-%m-%dT%H:%M:%S.%f%z"):
expiry = expiry.rstrip("Z").split(".")[0]
for fmt in ("%Y-%m-%d %H:%M:%S", "%Y-%m-%dT%H:%M:%S"):
try:
return datetime.strptime(expiry, fmt)
except ValueError as e:
Expand Down
14 changes: 10 additions & 4 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

from databricks.sdk import WorkspaceClient
from databricks.sdk.azure import ENVIRONMENTS, AzureEnvironment
from databricks.sdk.core import (ApiClient, Config, CredentialsProvider,
DatabricksCliTokenSource, DatabricksError,
HeaderFactory, StreamingResponse,
databricks_cli)
from databricks.sdk.core import (ApiClient, CliTokenSource, Config,
CredentialsProvider, DatabricksCliTokenSource,
DatabricksError, HeaderFactory,
StreamingResponse, databricks_cli)
from databricks.sdk.service.catalog import PermissionsChange
from databricks.sdk.service.iam import AccessControlRequest
from databricks.sdk.version import __version__
Expand Down Expand Up @@ -52,6 +52,12 @@ def test_databricks_cli_token_source_not_installed(config, monkeypatch):
DatabricksCliTokenSource(config)


def test_databricks_cli_token_parse_expiry():
CliTokenSource._parse_expiry("2023-12-01T15:19:48.007742617Z")
CliTokenSource._parse_expiry("2023-12-05T15:59:01.40081+11:00")
CliTokenSource._parse_expiry("2023-12-06 10:06:05")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just add an assertion on the actual returned values?
BTW: good practice here would be to use pytest.mark.parameterize annotation, e.g.

@pytest.mark.parametrize(
    "date_string,expected",
    [("2023-12-01T15:19:48.007742617Z", <the expected date>),
      ("2023-12-05T15:59:01.40081+11:00", <the expected date>),
      ("2023-12-06 10:06:05", <the expected date>)])
def test_databricks_cli_token_parse_expiry(date_string, expected):



def write_small_dummy_executable(path: pathlib.Path):
cli = path.joinpath('databricks')
cli.write_text('#!/bin/sh\necho "hello world"\n')
Expand Down