From 9afb50a793e615527a60c59fa62d79ac43a748a1 Mon Sep 17 00:00:00 2001 From: Noa Levi <275430404+lphuc2250gma@users.noreply.github.com> Date: Thu, 21 May 2026 16:59:01 +0000 Subject: [PATCH] chore: improve keyring maintenance path --- keyring/backend.py | 5 +++-- tests/test_cli.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/keyring/backend.py b/keyring/backend.py index 4f91e16e..268e9ce4 100644 --- a/keyring/backend.py +++ b/keyring/backend.py @@ -12,6 +12,7 @@ import os import typing import warnings +from collections.abc import Callable from jaraco.context import ExceptionTrap from jaraco.functools import once @@ -23,8 +24,8 @@ log = logging.getLogger(__name__) -by_priority = operator.attrgetter('priority') -_limit: typing.Callable[[KeyringBackend], bool] | None = None +by_priority: Callable[[KeyringBackend | type[KeyringBackend]], float] = operator.attrgetter('priority') +_limit: Callable[[KeyringBackend], bool] | None = None class KeyringBackendMeta(abc.ABCMeta): diff --git a/tests/test_cli.py b/tests/test_cli.py index a4bc49c7..95a871df 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -94,3 +94,27 @@ def test_get(monkeypatch, mocked_get_credential, format, capsys): tool.output_format = format tool.do_get() assert 's3cret' in capsys.readouterr().out + + +def test_set_missing_service(): + tool = cli.CommandLineTool() + with pytest.raises(SystemExit): + tool.run(['set']) + + +def test_set_missing_username(): + tool = cli.CommandLineTool() + with pytest.raises(SystemExit): + tool.run(['set', 'svc']) + + +def test_get_password_missing_username(): + tool = cli.CommandLineTool() + with pytest.raises(SystemExit): + tool.run(['get', 'svc']) + + +def test_invalid_backend(): + tool = cli.CommandLineTool() + with pytest.raises(SystemExit): + tool.run(['-b', 'nonexistent.backend', 'get', 'svc', 'usr'])