Skip to content

Commit 481103d

Browse files
committed
SNOW-2306184: config refactor - track resolution history only when requested - fix win tests
1 parent c836746 commit 481103d

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

tests/config_ng/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import copy
2222
import os
23+
import os.path
2324
import tempfile
2425
from contextlib import contextmanager
2526
from pathlib import Path
@@ -60,6 +61,36 @@ def _temp_environment(env_vars: Dict[str, str]):
6061
os.environ.update(original_env)
6162

6263

64+
@pytest.fixture
65+
def windows_home_env(tmp_path) -> Dict[str, str]:
66+
"""
67+
Provide temporary Windows-specific home environment variables when needed.
68+
69+
Returns an empty dict on non-Windows platforms to avoid polluting tests.
70+
"""
71+
72+
if not IS_WINDOWS:
73+
return {}
74+
75+
home_dir = tmp_path / "win_home"
76+
home_dir.mkdir()
77+
78+
snowflake_home = home_dir / ".snowflake"
79+
snowflake_home.mkdir()
80+
81+
resolved_home = home_dir.resolve()
82+
drive, tail = os.path.splitdrive(str(resolved_home))
83+
homedrive = drive or os.environ.get("HOMEDRIVE", "C:")
84+
homepath = tail or os.environ.get("HOMEPATH", "\\")
85+
86+
return {
87+
"SNOWFLAKE_HOME": str(snowflake_home),
88+
"USERPROFILE": str(resolved_home),
89+
"HOMEDRIVE": homedrive,
90+
"HOMEPATH": homepath,
91+
}
92+
93+
6394
@pytest.fixture
6495
def config_ng_setup():
6596
"""

tests/config_ng/test_resolution_logger.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,17 @@ def test_check_value_source_for_env_var(self):
354354
class TestConfigurationExplanationResults:
355355
"""Tests for get_configuration_explanation_results helper."""
356356

357-
@mock.patch.dict(os.environ, {ALTERNATIVE_CONFIG_ENV_VAR: "1"}, clear=True)
358357
@mock.patch("snowflake.cli.api.config_ng.resolution_logger.ResolutionPresenter")
359358
@mock.patch("snowflake.cli.api.config_ng.resolution_logger.get_resolver")
360359
@mock.patch(
361360
"snowflake.cli.api.config_ng.resolution_logger.get_config_provider_singleton"
362361
)
363362
def test_includes_diagnostics_message_non_verbose(
364-
self, mock_provider, mock_get_resolver, mock_presenter_cls
363+
self,
364+
mock_provider,
365+
mock_get_resolver,
366+
mock_presenter_cls,
367+
windows_home_env,
365368
):
366369
from snowflake.cli.api.output.types import (
367370
CollectionResult,
@@ -377,19 +380,24 @@ def test_includes_diagnostics_message_non_verbose(
377380
table_result = CollectionResult([])
378381
presenter.build_sources_table.return_value = table_result
379382

380-
result = get_configuration_explanation_results(verbose=False)
383+
env_vars = {ALTERNATIVE_CONFIG_ENV_VAR: "1", **windows_home_env}
384+
with mock.patch.dict(os.environ, env_vars, clear=True):
385+
result = get_configuration_explanation_results(verbose=False)
381386
assert isinstance(result, MultipleResults)
382387
outputs = list(result.result)
383388
assert outputs == [diag_message, table_result]
384389

385-
@mock.patch.dict(os.environ, {ALTERNATIVE_CONFIG_ENV_VAR: "1"}, clear=True)
386390
@mock.patch("snowflake.cli.api.config_ng.resolution_logger.ResolutionPresenter")
387391
@mock.patch("snowflake.cli.api.config_ng.resolution_logger.get_resolver")
388392
@mock.patch(
389393
"snowflake.cli.api.config_ng.resolution_logger.get_config_provider_singleton"
390394
)
391395
def test_includes_diagnostics_message_verbose(
392-
self, mock_provider, mock_get_resolver, mock_presenter_cls
396+
self,
397+
mock_provider,
398+
mock_get_resolver,
399+
mock_presenter_cls,
400+
windows_home_env,
393401
):
394402
from snowflake.cli.api.output.types import (
395403
CollectionResult,
@@ -408,7 +416,9 @@ def test_includes_diagnostics_message_verbose(
408416
presenter.build_sources_table.return_value = table_result
409417
presenter.format_history_message.return_value = history_message
410418

411-
result = get_configuration_explanation_results(verbose=True)
419+
env_vars = {ALTERNATIVE_CONFIG_ENV_VAR: "1", **windows_home_env}
420+
with mock.patch.dict(os.environ, env_vars, clear=True):
421+
result = get_configuration_explanation_results(verbose=True)
412422
assert isinstance(result, MultipleResults)
413423
outputs = list(result.result)
414424
assert outputs == [diag_message, table_result, history_message]

0 commit comments

Comments
 (0)