Skip to content

Commit 473ef5a

Browse files
committed
test: add config file search path for cwd
1 parent 33e8f36 commit 473ef5a

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

tests/utils/test_config.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,57 @@ def test_from_configuration_files_get_typed_value(tmp_path_factory: pytest.TempP
9393

9494
assert Config().get_bool("legacy-current-snapshot-id")
9595
assert Config().get_int("max-workers") == 4
96+
97+
98+
@pytest.mark.parametrize(
99+
"config_location, config_content, expected_result",
100+
[
101+
(
102+
"config",
103+
{"catalog": {"default": {"uri": "https://service.io/api"}}},
104+
{"catalog": {"default": {"uri": "https://service.io/api"}}},
105+
),
106+
(
107+
"home",
108+
{"catalog": {"default": {"uri": "https://service.io/api"}}},
109+
{"catalog": {"default": {"uri": "https://service.io/api"}}},
110+
),
111+
(
112+
"current",
113+
{"catalog": {"default": {"uri": "https://service.io/api"}}},
114+
{"catalog": {"default": {"uri": "https://service.io/api"}}},
115+
),
116+
("none", None, None),
117+
],
118+
)
119+
def test_from_multiple_configuration_files(
120+
monkeypatch: pytest.MonkeyPatch, tmp_path_factory: pytest.TempPathFactory, config_location, config_content, expected_result
121+
):
122+
def create_config_file(directory: str, content: dict) -> None:
123+
config_file_path = os.path.join(directory, ".pyiceberg.yaml")
124+
with open(config_file_path, "w", encoding="utf-8") as file:
125+
yaml_str = as_document(content).as_yaml() if content else ""
126+
file.write(yaml_str)
127+
128+
config_path = str(tmp_path_factory.mktemp("config"))
129+
home_path = str(tmp_path_factory.mktemp("home"))
130+
current_path = str(tmp_path_factory.mktemp("current"))
131+
132+
location_to_path = {
133+
"config": config_path,
134+
"home": home_path,
135+
"current": current_path,
136+
}
137+
138+
if config_location in location_to_path and config_content:
139+
create_config_file(location_to_path[config_location], config_content)
140+
141+
monkeypatch.setenv("PYICEBERG_HOME", config_path)
142+
monkeypatch.setattr(os.path, "expanduser", lambda _: home_path)
143+
144+
if config_location == "current":
145+
monkeypatch.chdir(current_path)
146+
147+
assert (
148+
Config()._from_configuration_files() == expected_result
149+
), f"Unexpected configuration result for content: {config_content}"

0 commit comments

Comments
 (0)