Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_core for windows #702

Merged
merged 5 commits into from
Jul 8, 2024
Merged
Changes from 4 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
39 changes: 32 additions & 7 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
databricks_cli)
from databricks.sdk.environments import (ENVIRONMENTS, AzureEnvironment, Cloud,
DatabricksEnvironment)
from databricks.sdk.oauth import Token
from databricks.sdk.service.catalog import PermissionsChange
from databricks.sdk.service.iam import AccessControlRequest
from databricks.sdk.version import __version__
Expand Down Expand Up @@ -67,9 +68,14 @@ 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')
cli.chmod(0o755)
if platform.system() == "Windows":
cli = path.joinpath('databricks.exe')
cli.touch()
cli.write_text('@echo off\necho "hello world"\n')
else:
cli = path.joinpath('databricks')
cli.write_text('#!/bin/sh\necho "hello world"\n')
cli.chmod(0o755)
assert cli.stat().st_size < 1024
return cli

Expand Down Expand Up @@ -133,9 +139,15 @@ def test_databricks_cli_token_source_installed_legacy_with_symlink(config, monke
dir1.mkdir()
dir2.mkdir()

(dir1 / "databricks").symlink_to(write_small_dummy_executable(dir2))
if platform.system() == 'Windows':
(dir1 / "databricks.exe").symlink_to(write_small_dummy_executable(dir2))
path = pathlib.PureWindowsPath(dir1)
else:
(dir1 / "databricks").symlink_to(write_small_dummy_executable(dir2))
path = pathlib.PurePosixPath(dir1)
path = path.__str__()
parthban-db marked this conversation as resolved.
Show resolved Hide resolved
monkeypatch.setenv('PATH', path)

monkeypatch.setenv('PATH', dir1.as_posix())
with pytest.raises(FileNotFoundError, match="version <0.100.0 detected"):
DatabricksCliTokenSource(config)

Expand Down Expand Up @@ -175,10 +187,23 @@ def test_databricks_cli_credential_provider_installed_legacy(config, monkeypatch
assert databricks_cli(config) == None


def test_databricks_cli_credential_provider_installed_new(config, monkeypatch, tmp_path):
def test_databricks_cli_credential_provider_installed_new(config, monkeypatch, tmp_path, mocker):
get_mock = mocker.patch('databricks.sdk.credentials_provider.CliTokenSource.refresh',
return_value=Token(access_token='token',
token_type='Bearer',
expiry=datetime(2023, 5, 22, 0, 0, 0)))
write_large_dummy_executable(tmp_path)
monkeypatch.setenv('PATH', str(os.pathsep).join([tmp_path.as_posix(), os.environ['PATH']]))
path = str(os.pathsep).join([tmp_path.as_posix(), os.environ['PATH']])
if platform.system() == 'Windows':
path = pathlib.PureWindowsPath(path)
parthban-db marked this conversation as resolved.
Show resolved Hide resolved
monkeypatch.setenv('COMSPEC', 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe')
else:
path = pathlib.PurePosixPath(path)
path = path.__str__()
parthban-db marked this conversation as resolved.
Show resolved Hide resolved
monkeypatch.setenv('PATH', path)

assert databricks_cli(config) is not None
assert get_mock.call_count == 1


def test_extra_and_upstream_user_agent(monkeypatch):
Expand Down
Loading