From 18c143f96b182855fa05bb5682db3c0f29c7f079 Mon Sep 17 00:00:00 2001 From: Parth Bansal Date: Mon, 8 Jul 2024 17:13:14 +0200 Subject: [PATCH] Fix test_core for windows (#702) ## Changes Fix `test_core.py` for windows. ## Tests - [ ] `make test` run locally - [ ] `make fmt` applied - [ ] relevant integration tests applied --- tests/test_core.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index eb2f6d954..057147159 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -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__ @@ -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 @@ -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) @@ -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):