Skip to content

Commit 07d7f61

Browse files
committed
test(cli): snapshot help output for copy and update commands
Capture and assert full `--help` output for `copier copy` and `copier update` in CLI tests instead of checking partial strings to make help text changes explicit and improve regression protection against unintended CLI UX drift.
1 parent 7ac0ca4 commit 07d7f61

1 file changed

Lines changed: 123 additions & 8 deletions

File tree

‎tests/test_cli.py‎

Lines changed: 123 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,131 @@ def test_help() -> None:
367367
assert "copier update [SWITCHES] [destination_path=.]" in _help
368368

369369

370-
def test_copy_help() -> None:
371-
_help = COPIER_CMD("copy", "--help")
372-
assert "copier copy [SWITCHES] template_src destination_path" in _help
370+
def test_copy_help(capsys: pytest.CaptureFixture[str]) -> None:
371+
with patch("plumbum.cli.application.get_terminal_size", return_value=(80, 1)):
372+
_, status = CopierApp.run(["copier", "copy", "--help"], exit=False)
373+
assert status == 0
374+
header, body = capsys.readouterr().out.split("\n", 1)
375+
assert header.startswith("copier copy")
376+
assert body == snapshot("""\
373377
378+
Copy from a template source to a destination.
374379
375-
def test_update_help() -> None:
376-
_help = COPIER_CMD("update", "--help")
377-
assert "-o, --conflict" in _help
378-
assert "copier update [SWITCHES] [destination_path=.]" in _help
379-
assert "--skip-answered" in _help
380+
Usage:
381+
copier copy [SWITCHES] template_src destination_path
382+
383+
Meta-switches:
384+
-h, --help Prints this help message and quits
385+
--help-all Prints help messages of all sub-commands and
386+
quits
387+
-v, --version Prints the program's version and quits
388+
389+
Switches:
390+
-C, --no-cleanup On error, do not delete destination if it
391+
was created by Copier.
392+
-T, --skip-tasks Skip template tasks execution
393+
--UNSAFE, --trust Allow templates with unsafe features (Jinja
394+
extensions, migrations, tasks)
395+
-a, --answers-file VALUE:str Update using this path (relative to
396+
`destination_path`) to find the answers file
397+
-d, --data VARIABLE=VALUE:str Make VARIABLE available as VALUE when
398+
rendering the template; may be given
399+
multiple times
400+
--data-file PATH:ExistingFile Load data from a YAML file
401+
-f, --force Same as `--defaults --overwrite`.
402+
-g, --prereleases Use prereleases to compare template VCS
403+
tags.
404+
-l, --defaults Use default answers to questions, which
405+
might be null if not specified.
406+
-n, --pretend Run but do not make any changes
407+
-q, --quiet Suppress status output
408+
-r, --vcs-ref VALUE:str Git reference to checkout in `template_src`.
409+
If you do not specify it, it will try to
410+
checkout the latest git tag, as sorted using
411+
the PEP 440 algorithm. If you want to
412+
checkout always the latest version, use
413+
`--vcs-ref=HEAD`. Use the special value
414+
`:current:` to refer to the current
415+
reference of the template if it already
416+
exists.
417+
-s, --skip VALUE:str Skip specified files if they exist already;
418+
may be given multiple times
419+
-w, --overwrite Overwrite files that already exist, without
420+
asking.
421+
-x, --exclude VALUE:str A name or shell-style pattern matching files
422+
or folders that must not be copied; may be
423+
given multiple times
424+
425+
""")
426+
427+
428+
def test_update_help(capsys: pytest.CaptureFixture[str]) -> None:
429+
with patch("plumbum.cli.application.get_terminal_size", return_value=(80, 1)):
430+
_, status = CopierApp.run(["copier", "update", "--help"], exit=False)
431+
assert status == 0
432+
header, body = capsys.readouterr().out.split("\n", 1)
433+
assert header.startswith("copier update")
434+
assert body == snapshot("""\
435+
436+
Update a subproject from its original template
437+
438+
The copy must have a valid answers file which contains info from the last Copier
439+
execution, including the source template (it must be a key called `_src_path`).
440+
441+
If that file contains also `_commit`, and `destination_path` is a git
442+
repository, this command will do its best to respect the diff that you have
443+
generated since the last `copier` execution. To avoid that, use `copier recopy`
444+
instead.
445+
446+
Usage:
447+
copier update [SWITCHES] [destination_path=.]
448+
449+
Meta-switches:
450+
-h, --help Prints this help message and quits
451+
--help-all Prints help messages of all sub-commands and
452+
quits
453+
-v, --version Prints the program's version and quits
454+
455+
Switches:
456+
-A, --skip-answered Skip questions that have already been
457+
answered
458+
-T, --skip-tasks Skip template tasks execution
459+
--UNSAFE, --trust Allow templates with unsafe features (Jinja
460+
extensions, migrations, tasks)
461+
-a, --answers-file VALUE:str Update using this path (relative to
462+
`destination_path`) to find the answers file
463+
-c, --context-lines VALUE:int Lines of context to use for detecting
464+
conflicts. Increase for accuracy, decrease
465+
for resilience.; the default is 3
466+
-d, --data VARIABLE=VALUE:str Make VARIABLE available as VALUE when
467+
rendering the template; may be given
468+
multiple times
469+
--data-file PATH:ExistingFile Load data from a YAML file
470+
-g, --prereleases Use prereleases to compare template VCS
471+
tags.
472+
-l, -f, --defaults Use default answers to questions, which
473+
might be null if not specified.
474+
-n, --pretend Run but do not make any changes
475+
-o, --conflict VALUE:{rej, inline} Behavior on conflict: Create .rej files, or
476+
add inline conflict markers.; the default is
477+
inline
478+
-q, --quiet Suppress status output
479+
-r, --vcs-ref VALUE:str Git reference to checkout in `template_src`.
480+
If you do not specify it, it will try to
481+
checkout the latest git tag, as sorted using
482+
the PEP 440 algorithm. If you want to
483+
checkout always the latest version, use
484+
`--vcs-ref=HEAD`. Use the special value
485+
`:current:` to refer to the current
486+
reference of the template if it already
487+
exists.
488+
-s, --skip VALUE:str Skip specified files if they exist already;
489+
may be given multiple times
490+
-x, --exclude VALUE:str A name or shell-style pattern matching files
491+
or folders that must not be copied; may be
492+
given multiple times
493+
494+
""")
380495

381496

382497
def test_check_update_help(capsys: pytest.CaptureFixture[str]) -> None:

0 commit comments

Comments
 (0)