diff --git a/src/bloomy/configuration.py b/src/bloomy/configuration.py index 609a278..d137141 100644 --- a/src/bloomy/configuration.py +++ b/src/bloomy/configuration.py @@ -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: @@ -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: diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 899e695..e200581 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -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() @@ -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 @@ -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() @@ -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), ): @@ -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