Marco Ricci commited on 2024-10-01 10:15:36
Zeige 2 geänderte Dateien mit 11 Einfügungen und 15 Löschungen.
Instead of introducing a static method, calling it to obtain test parameters, then removing it again, use a declaration within the `pytest.mark.parametrize` decorator arguments, even if that is supposedly more difficult to read (I wouldn't agree). Among the readability benefits (primarily because of compactness), the imperative version via a static method throws errors on Python 3.9, presumably because the `staticmethod` object itself is being returned, not the bound method object, and the former isn't callable in Python 3.9. On a related note, a future import for annotations was missing as well.
| ... | ... |
@@ -21,7 +21,7 @@ import tests |
| 21 | 21 |
from derivepassphrase import _types, cli, ssh_agent, vault |
| 22 | 22 |
|
| 23 | 23 |
if TYPE_CHECKING: |
| 24 |
- from collections.abc import Iterable, Iterator |
|
| 24 |
+ from collections.abc import Iterable |
|
| 25 | 25 |
|
| 26 | 26 |
from typing_extensions import Any |
| 27 | 27 |
|
| ... | ... |
@@ -276,18 +276,14 @@ class TestAgentInteraction: |
| 276 | 276 |
with pytest.raises(ValueError, match='unsuitable SSH key'): |
| 277 | 277 |
vault.Vault.phrase_from_key(public_key_data) |
| 278 | 278 |
|
| 279 |
- @staticmethod |
|
| 280 |
- def _params() -> Iterator[tuple[bytes, bool]]: |
|
| 281 |
- for value in tests.SUPPORTED_KEYS.values(): |
|
| 282 |
- key = value['public_key_data'] |
|
| 283 |
- yield (key, False) |
|
| 284 |
- singleton_key = tests.list_keys_singleton()[0].key |
|
| 285 |
- for value in tests.SUPPORTED_KEYS.values(): |
|
| 286 |
- key = value['public_key_data'] |
|
| 287 |
- if key == singleton_key: |
|
| 288 |
- yield (key, True) |
|
| 289 |
- |
|
| 290 |
- @pytest.mark.parametrize(['key', 'single'], list(_params())) |
|
| 279 |
+ @pytest.mark.parametrize( |
|
| 280 |
+ ['key', 'single'], |
|
| 281 |
+ [ |
|
| 282 |
+ (value['public_key_data'], False) |
|
| 283 |
+ for value in tests.SUPPORTED_KEYS.values() |
|
| 284 |
+ ] |
|
| 285 |
+ + [(tests.list_keys_singleton()[0].key, True)], |
|
| 286 |
+ ) |
|
| 291 | 287 |
def test_210_ssh_key_selector( |
| 292 | 288 |
self, |
| 293 | 289 |
monkeypatch: pytest.MonkeyPatch, |
| ... | ... |
@@ -345,8 +341,6 @@ class TestAgentInteraction: |
| 345 | 341 |
for snippet in ('Suitable SSH keys:\n', text, f'\n{b64_key}\n'):
|
| 346 | 342 |
assert result.clean_exit(output=snippet), 'expected clean exit' |
| 347 | 343 |
|
| 348 |
- del _params |
|
| 349 |
- |
|
| 350 | 344 |
def test_300_constructor_bad_running_agent( |
| 351 | 345 |
self, |
| 352 | 346 |
monkeypatch: pytest.MonkeyPatch, |
| 353 | 347 |