Marco Ricci commited on 2024-07-28 14:27:31
Zeige 2 geänderte Dateien mit 43 Einfügungen und 4 Löschungen.
Running the tests on a machine which already had a broken derivepassphrase configuration (e.g., invalid JSON in the `settings.json` file) previously caused some unrelated tests to fail for that reason. Therefore, apply isolation to *all* tests calling the command-line interface.
... | ... |
@@ -196,8 +196,13 @@ for opt, config in SINGLES.items(): |
196 | 196 |
|
197 | 197 |
|
198 | 198 |
class TestCLI: |
199 |
- def test_200_help_output(self) -> None: |
|
199 |
+ def test_200_help_output(self, monkeypatch: Any) -> None: |
|
200 | 200 |
runner = click.testing.CliRunner(mix_stderr=False) |
201 |
+ with tests.isolated_config( |
|
202 |
+ monkeypatch=monkeypatch, |
|
203 |
+ runner=runner, |
|
204 |
+ config={'services': {}}, |
|
205 |
+ ): |
|
201 | 206 |
result = runner.invoke( |
202 | 207 |
cli.derivepassphrase, ['--help'], catch_exceptions=False |
203 | 208 |
) |
... | ... |
@@ -219,6 +224,11 @@ class TestCLI: |
219 | 224 |
option = f'--{charset_name}' |
220 | 225 |
charset = dpp.Vault._CHARSETS[charset_name].decode('ascii') |
221 | 226 |
runner = click.testing.CliRunner(mix_stderr=False) |
227 |
+ with tests.isolated_config( |
|
228 |
+ monkeypatch=monkeypatch, |
|
229 |
+ runner=runner, |
|
230 |
+ config={'services': {}}, |
|
231 |
+ ): |
|
222 | 232 |
result = runner.invoke( |
223 | 233 |
cli.derivepassphrase, |
224 | 234 |
[option, '0', '-p', DUMMY_SERVICE], |
... | ... |
@@ -240,6 +250,11 @@ class TestCLI: |
240 | 250 |
def test_202_disable_repetition(self, monkeypatch: Any) -> None: |
241 | 251 |
monkeypatch.setattr(cli, '_prompt_for_passphrase', tests.auto_prompt) |
242 | 252 |
runner = click.testing.CliRunner(mix_stderr=False) |
253 |
+ with tests.isolated_config( |
|
254 |
+ monkeypatch=monkeypatch, |
|
255 |
+ runner=runner, |
|
256 |
+ config={'services': {}}, |
|
257 |
+ ): |
|
243 | 258 |
result = runner.invoke( |
244 | 259 |
cli.derivepassphrase, |
245 | 260 |
['--repeat', '0', '-p', DUMMY_SERVICE], |
... | ... |
@@ -388,8 +403,15 @@ class TestCLI: |
388 | 403 |
'--length', |
389 | 404 |
], |
390 | 405 |
) |
391 |
- def test_210_invalid_argument_range(self, option: str) -> None: |
|
406 |
+ def test_210_invalid_argument_range( |
|
407 |
+ self, monkeypatch: Any, option: str |
|
408 |
+ ) -> None: |
|
392 | 409 |
runner = click.testing.CliRunner(mix_stderr=False) |
410 |
+ with tests.isolated_config( |
|
411 |
+ monkeypatch=monkeypatch, |
|
412 |
+ runner=runner, |
|
413 |
+ config={'services': {}}, |
|
414 |
+ ): |
|
393 | 415 |
for value in '-42', 'invalid': |
394 | 416 |
result = runner.invoke( |
395 | 417 |
cli.derivepassphrase, |
... | ... |
@@ -482,10 +504,16 @@ class TestCLI: |
482 | 504 |
) |
483 | 505 |
def test_212_incompatible_options( |
484 | 506 |
self, |
507 |
+ monkeypatch: Any, |
|
485 | 508 |
options: list[str], |
486 | 509 |
service: bool | None, |
487 | 510 |
) -> None: |
488 | 511 |
runner = click.testing.CliRunner(mix_stderr=False) |
512 |
+ with tests.isolated_config( |
|
513 |
+ monkeypatch=monkeypatch, |
|
514 |
+ runner=runner, |
|
515 |
+ config={'services': {}}, |
|
516 |
+ ): |
|
489 | 517 |
result = runner.invoke( |
490 | 518 |
cli.derivepassphrase, |
491 | 519 |
[*options, DUMMY_SERVICE] if service else options, |
... | ... |
@@ -886,8 +914,13 @@ contents go here |
886 | 914 |
custom_error.encode() in result.stderr_bytes |
887 | 915 |
), 'expected error message missing' |
888 | 916 |
|
889 |
- def test_226_no_arguments(self) -> None: |
|
917 |
+ def test_226_no_arguments(self, monkeypatch: Any) -> None: |
|
890 | 918 |
runner = click.testing.CliRunner(mix_stderr=False) |
919 |
+ with tests.isolated_config( |
|
920 |
+ monkeypatch=monkeypatch, |
|
921 |
+ runner=runner, |
|
922 |
+ config={'services': {}}, |
|
923 |
+ ): |
|
891 | 924 |
result = runner.invoke( |
892 | 925 |
cli.derivepassphrase, [], catch_exceptions=False |
893 | 926 |
) |
... | ... |
@@ -897,8 +930,13 @@ contents go here |
897 | 930 |
b'SERVICE is required' in result.stderr_bytes |
898 | 931 |
), 'expected error message missing' |
899 | 932 |
|
900 |
- def test_226a_no_passphrase_or_key(self) -> None: |
|
933 |
+ def test_226a_no_passphrase_or_key(self, monkeypatch: Any) -> None: |
|
901 | 934 |
runner = click.testing.CliRunner(mix_stderr=False) |
935 |
+ with tests.isolated_config( |
|
936 |
+ monkeypatch=monkeypatch, |
|
937 |
+ runner=runner, |
|
938 |
+ config={'services': {}}, |
|
939 |
+ ): |
|
902 | 940 |
result = runner.invoke( |
903 | 941 |
cli.derivepassphrase, [DUMMY_SERVICE], catch_exceptions=False |
904 | 942 |
) |