Skip to content

Commit

Permalink
Fix test_core for windows (#702)
Browse files Browse the repository at this point in the history
## Changes
<!-- Summary of your changes that are easy to understand -->
Fix `test_core.py` for windows. 

## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->

- [ ] `make test` run locally
- [ ] `make fmt` applied
- [ ] relevant integration tests applied
  • Loading branch information
parthban-db authored Jul 8, 2024
1 parent 648d602 commit 18c143f
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 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))
else:
(dir1 / "databricks").symlink_to(write_small_dummy_executable(dir2))

path = pathlib.Path(dir1)
path = str(path)
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,19 @@ 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']])
path = pathlib.Path(path)
path = str(path)
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

0 comments on commit 18c143f

Please sign in to comment.