File: test_core.py

package info (click to toggle)
python-keyring 25.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 552 kB
  • sloc: python: 1,923; sh: 17; makefile: 17
file content (45 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import textwrap

import pytest

import keyring.core


@pytest.fixture
def config_path(tmp_path, monkeypatch):
    path = tmp_path / 'keyringrc.cfg'
    monkeypatch.setattr(keyring.core, '_config_path', lambda: path)
    return path


def test_init_recommended(monkeypatch):
    """
    Test filtering of backends to recommended ones (#117, #423).
    """
    monkeypatch.setattr(keyring.core, 'set_keyring', lambda kr: None)
    keyring.core.init_backend(keyring.core.recommended)


def test_load_config_missing(caplog, config_path):
    assert keyring.core.load_config() is None
    assert not caplog.records


def test_load_empty_config(caplog, config_path):
    config_path.write_text("", encoding='utf-8')
    assert keyring.core.load_config() is None
    assert not caplog.records


fail_config = textwrap.dedent(
    """
    [backend]
    default-keyring = keyring.backends.fail.Keyring
    """
).lstrip()


def test_load_config_extant(caplog, config_path):
    config_path.write_text(fail_config, encoding='utf-8')
    assert keyring.core.load_config() is not None
    assert not caplog.records