Move commands' `--help` tests out of transition group
Marco Ricci

Marco Ricci commited on 2025-01-28 11:03:57
Zeige 1 geänderte Dateien mit 127 Einfügungen und 103 Löschungen.


These tests aren't specific to the v1.0 transition, and if we still want
to keep them in some way or another, they should probably outlast v1.0.
... ...
@@ -296,6 +296,133 @@ def vault_config_exporter_shell_interpreter(  # noqa: C901
296 296
 class TestAllCLI:
297 297
     """Tests uniformly for all command-line interfaces."""
298 298
 
299
+    # TODO(the-13th-letter): Do we actually need this?  What should we
300
+    # check for?
301
+    def test_100_help_output(self) -> None:
302
+        """The top-level help text mentions subcommands.
303
+
304
+        TODO: Do we actually need this?  What should we check for?
305
+
306
+        """
307
+        runner = click.testing.CliRunner(mix_stderr=False)
308
+        # TODO(the-13th-letter): Rewrite using parenthesized
309
+        # with-statements.
310
+        # https://the13thletter.info/derivepassphrase/latest/pycompatibility/#after-eol-py3.9
311
+        with contextlib.ExitStack() as stack:
312
+            monkeypatch = stack.enter_context(pytest.MonkeyPatch.context())
313
+            stack.enter_context(
314
+                tests.isolated_config(
315
+                    monkeypatch=monkeypatch,
316
+                    runner=runner,
317
+                )
318
+            )
319
+            result_ = runner.invoke(
320
+                cli.derivepassphrase, ['--help'], catch_exceptions=False
321
+            )
322
+            result = tests.ReadableResult.parse(result_)
323
+        assert result.clean_exit(
324
+            empty_stderr=True, output='currently implemented subcommands'
325
+        ), 'expected clean exit, and known help text'
326
+
327
+    # TODO(the-13th-letter): Do we actually need this?  What should we
328
+    # check for?
329
+    def test_101_help_output_export(
330
+        self,
331
+    ) -> None:
332
+        """The "export" subcommand help text mentions subcommands.
333
+
334
+        TODO: Do we actually need this?  What should we check for?
335
+
336
+        """
337
+        runner = click.testing.CliRunner(mix_stderr=False)
338
+        # TODO(the-13th-letter): Rewrite using parenthesized
339
+        # with-statements.
340
+        # https://the13thletter.info/derivepassphrase/latest/pycompatibility/#after-eol-py3.9
341
+        with contextlib.ExitStack() as stack:
342
+            monkeypatch = stack.enter_context(pytest.MonkeyPatch.context())
343
+            stack.enter_context(
344
+                tests.isolated_config(
345
+                    monkeypatch=monkeypatch,
346
+                    runner=runner,
347
+                )
348
+            )
349
+            result_ = runner.invoke(
350
+                cli.derivepassphrase,
351
+                ['export', '--help'],
352
+                catch_exceptions=False,
353
+            )
354
+            result = tests.ReadableResult.parse(result_)
355
+        assert result.clean_exit(
356
+            empty_stderr=True, output='only available subcommand'
357
+        ), 'expected clean exit, and known help text'
358
+
359
+    # TODO(the-13th-letter): Do we actually need this?  What should we
360
+    # check for?
361
+    def test_102_help_output_export_vault(
362
+        self,
363
+    ) -> None:
364
+        """The "export vault" subcommand help text has known content.
365
+
366
+        TODO: Do we actually need this?  What should we check for?
367
+
368
+        """
369
+        runner = click.testing.CliRunner(mix_stderr=False)
370
+        # TODO(the-13th-letter): Rewrite using parenthesized
371
+        # with-statements.
372
+        # https://the13thletter.info/derivepassphrase/latest/pycompatibility/#after-eol-py3.9
373
+        with contextlib.ExitStack() as stack:
374
+            monkeypatch = stack.enter_context(pytest.MonkeyPatch.context())
375
+            stack.enter_context(
376
+                tests.isolated_config(
377
+                    monkeypatch=monkeypatch,
378
+                    runner=runner,
379
+                )
380
+            )
381
+            result_ = runner.invoke(
382
+                cli.derivepassphrase,
383
+                ['export', 'vault', '--help'],
384
+                catch_exceptions=False,
385
+            )
386
+            result = tests.ReadableResult.parse(result_)
387
+        assert result.clean_exit(
388
+            empty_stderr=True, output='Export a vault-native configuration'
389
+        ), 'expected clean exit, and known help text'
390
+
391
+    # TODO(the-13th-letter): Do we actually need this?  What should we
392
+    # check for?
393
+    def test_103_help_output_vault(
394
+        self,
395
+    ) -> None:
396
+        """The "vault" subcommand help text has known content.
397
+
398
+        TODO: Do we actually need this?  What should we check for?
399
+
400
+        """
401
+        runner = click.testing.CliRunner(mix_stderr=False)
402
+        # TODO(the-13th-letter): Rewrite using parenthesized
403
+        # with-statements.
404
+        # https://the13thletter.info/derivepassphrase/latest/pycompatibility/#after-eol-py3.9
405
+        with contextlib.ExitStack() as stack:
406
+            monkeypatch = stack.enter_context(pytest.MonkeyPatch.context())
407
+            stack.enter_context(
408
+                tests.isolated_config(
409
+                    monkeypatch=monkeypatch,
410
+                    runner=runner,
411
+                )
412
+            )
413
+            result_ = runner.invoke(
414
+                cli.derivepassphrase,
415
+                ['vault', '--help'],
416
+                catch_exceptions=False,
417
+            )
418
+            result = tests.ReadableResult.parse(result_)
419
+        assert result.clean_exit(
420
+            empty_stderr=True, output='Passphrase generation:\n'
421
+        ), 'expected clean exit, and option groups in help text'
422
+        assert result.clean_exit(
423
+            empty_stderr=True, output='Use $VISUAL or $EDITOR to configure'
424
+        ), 'expected clean exit, and option group epilog in help text'
425
+
299 426
     @pytest.mark.parametrize(
300 427
         ['command', 'non_eager_arguments'],
301 428
         [
... ...
@@ -3381,109 +3508,6 @@ Boo.
3381 3508
 class TestCLITransition:
3382 3509
     """Transition tests for the command-line interface up to v1.0."""
3383 3510
 
3384
-    def test_100_help_output(self) -> None:
3385
-        """The top-level help text mentions subcommands."""
3386
-        runner = click.testing.CliRunner(mix_stderr=False)
3387
-        # TODO(the-13th-letter): Rewrite using parenthesized
3388
-        # with-statements.
3389
-        # https://the13thletter.info/derivepassphrase/latest/pycompatibility/#after-eol-py3.9
3390
-        with contextlib.ExitStack() as stack:
3391
-            monkeypatch = stack.enter_context(pytest.MonkeyPatch.context())
3392
-            stack.enter_context(
3393
-                tests.isolated_config(
3394
-                    monkeypatch=monkeypatch,
3395
-                    runner=runner,
3396
-                )
3397
-            )
3398
-            result_ = runner.invoke(
3399
-                cli.derivepassphrase, ['--help'], catch_exceptions=False
3400
-            )
3401
-            result = tests.ReadableResult.parse(result_)
3402
-        assert result.clean_exit(
3403
-            empty_stderr=True, output='currently implemented subcommands'
3404
-        ), 'expected clean exit, and known help text'
3405
-
3406
-    def test_101_help_output_export(
3407
-        self,
3408
-    ) -> None:
3409
-        """The "export" subcommand help text mentions subcommands."""
3410
-        runner = click.testing.CliRunner(mix_stderr=False)
3411
-        # TODO(the-13th-letter): Rewrite using parenthesized
3412
-        # with-statements.
3413
-        # https://the13thletter.info/derivepassphrase/latest/pycompatibility/#after-eol-py3.9
3414
-        with contextlib.ExitStack() as stack:
3415
-            monkeypatch = stack.enter_context(pytest.MonkeyPatch.context())
3416
-            stack.enter_context(
3417
-                tests.isolated_config(
3418
-                    monkeypatch=monkeypatch,
3419
-                    runner=runner,
3420
-                )
3421
-            )
3422
-            result_ = runner.invoke(
3423
-                cli.derivepassphrase,
3424
-                ['export', '--help'],
3425
-                catch_exceptions=False,
3426
-            )
3427
-            result = tests.ReadableResult.parse(result_)
3428
-        assert result.clean_exit(
3429
-            empty_stderr=True, output='only available subcommand'
3430
-        ), 'expected clean exit, and known help text'
3431
-
3432
-    def test_102_help_output_export_vault(
3433
-        self,
3434
-    ) -> None:
3435
-        """The "export vault" subcommand help text has known content."""
3436
-        runner = click.testing.CliRunner(mix_stderr=False)
3437
-        # TODO(the-13th-letter): Rewrite using parenthesized
3438
-        # with-statements.
3439
-        # https://the13thletter.info/derivepassphrase/latest/pycompatibility/#after-eol-py3.9
3440
-        with contextlib.ExitStack() as stack:
3441
-            monkeypatch = stack.enter_context(pytest.MonkeyPatch.context())
3442
-            stack.enter_context(
3443
-                tests.isolated_config(
3444
-                    monkeypatch=monkeypatch,
3445
-                    runner=runner,
3446
-                )
3447
-            )
3448
-            result_ = runner.invoke(
3449
-                cli.derivepassphrase,
3450
-                ['export', 'vault', '--help'],
3451
-                catch_exceptions=False,
3452
-            )
3453
-            result = tests.ReadableResult.parse(result_)
3454
-        assert result.clean_exit(
3455
-            empty_stderr=True, output='Export a vault-native configuration'
3456
-        ), 'expected clean exit, and known help text'
3457
-
3458
-    def test_103_help_output_vault(
3459
-        self,
3460
-    ) -> None:
3461
-        """The "vault" subcommand help text has known content."""
3462
-        runner = click.testing.CliRunner(mix_stderr=False)
3463
-        # TODO(the-13th-letter): Rewrite using parenthesized
3464
-        # with-statements.
3465
-        # https://the13thletter.info/derivepassphrase/latest/pycompatibility/#after-eol-py3.9
3466
-        with contextlib.ExitStack() as stack:
3467
-            monkeypatch = stack.enter_context(pytest.MonkeyPatch.context())
3468
-            stack.enter_context(
3469
-                tests.isolated_config(
3470
-                    monkeypatch=monkeypatch,
3471
-                    runner=runner,
3472
-                )
3473
-            )
3474
-            result_ = runner.invoke(
3475
-                cli.derivepassphrase,
3476
-                ['vault', '--help'],
3477
-                catch_exceptions=False,
3478
-            )
3479
-            result = tests.ReadableResult.parse(result_)
3480
-        assert result.clean_exit(
3481
-            empty_stderr=True, output='Passphrase generation:\n'
3482
-        ), 'expected clean exit, and option groups in help text'
3483
-        assert result.clean_exit(
3484
-            empty_stderr=True, output='Use $VISUAL or $EDITOR to configure'
3485
-        ), 'expected clean exit, and option group epilog in help text'
3486
-
3487 3511
     @pytest.mark.parametrize(
3488 3512
         'config',
3489 3513
         [
3490 3514