Skip to content
Myr

:white_check_mark: Add tests for completion

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sebastián Ramírez · committed by GitHub · parents e9c5cd6, cde63b0 · Browse files · 2 files+52 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+52 added−3 removed

  • tests:+49 added−0 removed
  • other:+3 added−3 removed

2 files+52 added−3 removed

added:tests/test_completion.py+49 added
1import os2import subprocess3import sys4from pathlib import Path56import typer7from typer.testing import CliRunner89from first_steps import tutorial001 as mod1011runner = CliRunner()12app = typer.Typer()13app.command()(mod.main)141516def test_show_completion():17 result = subprocess.run(18 [19 "bash",20 "-c",21 f"{sys.executable} -m coverage run {mod.__file__} --show-completion",22 ],23 stdout=subprocess.PIPE,24 stderr=subprocess.PIPE,25 encoding="utf-8",26 env={**os.environ, "SHELL": "/bin/bash"},27 )28 assert "_TUTORIAL001.PY_COMPLETE=complete-bash" in result.stdout293031def test_install_completion():32 bash_completion_path: Path = Path.home() / ".bash_completion"33 text = ""34 if bash_completion_path.is_file():35 text = bash_completion_path.read_text()36 result = subprocess.run(37 [38 "bash",39 "-c",40 f"{sys.executable} -m coverage run {mod.__file__} --install-completion",41 ],42 stdout=subprocess.PIPE,43 stderr=subprocess.PIPE,44 encoding="utf-8",45 env={**os.environ, "SHELL": "/bin/bash"},46 )47 new_text = bash_completion_path.read_text()48 assert "_TUTORIAL001.PY_COMPLETE=complete-bash" in new_text49 bash_completion_path.write_text(text)
modified:typer/completion.py+3 added-3 removed
10 unmodified lines
111213def install_callback(ctx: click.Context, param: click.Parameter, value: Any) -> Any:14 if not value or ctx.resilient_parsing:15 return value15 return value # pragma no cover16 shell, path = click_completion.core.install()17 click.secho(f"{shell} completion installed in {path}.", fg="green")18 click.echo("Completion will take effect once you restart the terminal.")19 sys.exit(0)202122def show_callback(ctx: click.Context, param: click.Parameter, value: Any) -> Any:23 if not value or ctx.resilient_parsing:24 return value24 return value # pragma no cover25 click.echo(click_completion.core.get_code())26 sys.exit(0)2728
15 unmodified lines
44 expose_value=False,45 help="Show completion for the current shell, to copy it or customize the installation.",46 ),47) -> Any:48 pass48 pass # pragma no cover