Skip to content

Commit

Permalink
Merge pull request #638 from jteichroeb-oanda/fix_config_ensure
Browse files Browse the repository at this point in the history
Fix reading config file
  • Loading branch information
jaraco authored Jun 24, 2023
2 parents 3f479e3 + c0c8e9e commit 7d625e4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions keyring/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def _config_path():
def _ensure_path(path):
if not path.exists():
raise FileNotFoundError(path)
return path


def load_config() -> typing.Optional[backend.KeyringBackend]:
Expand Down
1 change: 1 addition & 0 deletions newsfragments/638.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restore support for reading from a config file (with regression test).
28 changes: 26 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import keyring.core
from unittest.mock import patch
import pathlib
import tempfile


def test_init_recommended(monkeypatch):
Expand All @@ -10,5 +13,26 @@ def test_init_recommended(monkeypatch):


def test_load_config_missing(caplog):
assert keyring.core.load_config() is None
assert not caplog.records
with tempfile.TemporaryDirectory() as tmpdirname:
path = pathlib.Path(tmpdirname) / "keyringrc.cfg"
with patch.object(
keyring.core, '_config_path', return_value=path
) as config_path_mock:
assert keyring.core.load_config() is None
assert not caplog.records

config_path_mock.assert_called_once()


def test_load_config_exists(caplog):
with tempfile.TemporaryDirectory() as tmpdirname:
path = pathlib.Path(tmpdirname) / "keyringrc.cfg"
with open(path, "w", encoding='UTF-8') as file:
file.write('[backend]\ndefault-keyring=keyring.backends.fail.Keyring\n')
with patch.object(
keyring.core, '_config_path', return_value=path
) as config_path_mock:
assert keyring.core.load_config() is not None
assert not caplog.records

config_path_mock.assert_called_once()

0 comments on commit 7d625e4

Please sign in to comment.