Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/bloomy/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _store_api_key(self) -> None:
config_file.parent.mkdir(parents=True, exist_ok=True)

config_data = {"version": 1, "api_key": self.api_key}
with open(config_file, "w") as f:
with config_file.open("w") as f:
yaml.dump(config_data, f)

def _load_api_key(self) -> str | None:
Expand All @@ -124,7 +124,7 @@ def _load_api_key(self) -> str | None:
return None

try:
with open(config_file) as f:
with config_file.open() as f:
data = yaml.safe_load(f)
return data.get("api_key")
except Exception:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_init_with_config_file(self):

with (
patch.dict(os.environ, {"BG_API_KEY": ""}), # Clear env var
patch("builtins.open", mock_open(read_data=yaml.dump(mock_yaml_data))),
patch("pathlib.Path.open", mock_open(read_data=yaml.dump(mock_yaml_data))),
patch("pathlib.Path.exists", return_value=True),
):
config = Configuration()
Expand All @@ -43,7 +43,7 @@ def test_init_priority_order(self):

with (
patch.dict(os.environ, {"BG_API_KEY": "env-key"}),
patch("builtins.open", mock_open(read_data=yaml.dump(mock_yaml_data))),
patch("pathlib.Path.open", mock_open(read_data=yaml.dump(mock_yaml_data))),
patch("pathlib.Path.exists", return_value=True),
):
# Direct API key takes precedence
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_configure_api_key_with_store(self):
mock_client_class.return_value.__enter__.return_value = mock_client

with (
patch("builtins.open", mock_open()) as mock_file,
patch("pathlib.Path.open", mock_open()) as mock_file,
patch("pathlib.Path.mkdir"),
):
config = Configuration()
Expand Down Expand Up @@ -147,7 +147,7 @@ def test_load_api_key_no_file(self):
def test_load_api_key_invalid_yaml(self):
"""Test loading API key with invalid YAML."""
with (
patch("builtins.open", mock_open(read_data="invalid: yaml: content:")),
patch("pathlib.Path.open", mock_open(read_data="invalid: yaml: content:")),
patch("pathlib.Path.exists", return_value=True),
patch.dict(os.environ, {}, clear=True),
):
Expand All @@ -159,7 +159,7 @@ def test_config_file_location(self):
"""Test that configuration is loaded from the correct location."""
with (
patch("pathlib.Path.exists") as mock_exists,
patch("builtins.open", mock_open(read_data="api_key: test-key")),
patch("pathlib.Path.open", mock_open(read_data="api_key: test-key")),
patch.dict(os.environ, {}, clear=True),
):
# Initialize config which should try to load from file
Expand Down
Loading