Marco Ricci commited on 2025-02-04 13:17:03
Zeige 2 geänderte Dateien mit 13 Einfügungen und 5 Löschungen.
"no-op" editing of notes makes no sense for a service which does not have notes yet. Also, "no-op" editing may involve extra whitespace at the beginning or end of the contents. Use these two facts to construct a better test. Also, do not use click's convenience feature of using a `None` return to signal that no changes have been made. The check is heuristic in nature (it involves filesystem timestamps), and vault(1) actually uses a more naive system that does not map cleanly to click's system.
... | ... |
@@ -1393,8 +1393,9 @@ def derivepassphrase_vault( # noqa: C901,PLR0912,PLR0913,PLR0914,PLR0915 |
1393 | 1393 |
str(notes_marker), |
1394 | 1394 |
old_notes_value, |
1395 | 1395 |
]) |
1396 |
- notes_value = click.edit(text=text) |
|
1397 |
- if notes_value is not None: |
|
1396 |
+ notes_value = click.edit(text=text, require_save=False) |
|
1397 |
+ assert notes_value is not None |
|
1398 |
+ if notes_value != text: |
|
1398 | 1399 |
notes_lines = collections.deque( |
1399 | 1400 |
notes_value.splitlines(True) # noqa: FBT003 |
1400 | 1401 |
) |
... | ... |
@@ -2501,10 +2501,17 @@ contents go here |
2501 | 2501 |
tests.isolated_vault_config( |
2502 | 2502 |
monkeypatch=monkeypatch, |
2503 | 2503 |
runner=runner, |
2504 |
- vault_config={'global': {'phrase': 'abc'}, 'services': {}}, |
|
2504 |
+ vault_config={ |
|
2505 |
+ 'global': {'phrase': 'abc'}, |
|
2506 |
+ 'services': {'sv': {'notes': 'Contents go here'}}, |
|
2507 |
+ }, |
|
2505 | 2508 |
) |
2506 | 2509 |
) |
2507 |
- monkeypatch.setattr(click, 'edit', lambda *a, **kw: None) # noqa: ARG005 |
|
2510 |
+ |
|
2511 |
+ def space(text: str, *_args: Any, **_kwargs: Any) -> str: |
|
2512 |
+ return ' ' + text + '\n\n\n\n\n\n' |
|
2513 |
+ |
|
2514 |
+ monkeypatch.setattr(click, 'edit', space) |
|
2508 | 2515 |
result_ = runner.invoke( |
2509 | 2516 |
cli.derivepassphrase_vault, |
2510 | 2517 |
['--config', '--notes', '--', 'sv'], |
... | ... |
@@ -2518,7 +2525,7 @@ contents go here |
2518 | 2525 |
config = json.load(infile) |
2519 | 2526 |
assert config == { |
2520 | 2527 |
'global': {'phrase': 'abc'}, |
2521 |
- 'services': {'sv': {}}, |
|
2528 |
+ 'services': {'sv': {'notes': 'Contents go here'}}, |
|
2522 | 2529 |
} |
2523 | 2530 |
|
2524 | 2531 |
# TODO(the-13th-letter): Keep this behavior or not, with or without |
2525 | 2532 |