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
Provenance
Commit
dcbe3fc
Tree
4497440
Author
Sebastián Ramírez <tiangolo@gmail.com>
Committer
GitHub <noreply@github.com>
Parent 1
e9c5cd6
Parent 2
cde63b0
2 files changed+52 added−3 removed
added:tests/test_completion.py+49 added
1+import os2+import subprocess3+import sys4+from pathlib import Path5+6+import typer7+from typer.testing import CliRunner8+9+from first_steps import tutorial001 as mod10+11+runner = CliRunner()12+app = typer.Typer()13+app.command()(mod.main)14+15+16+def 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.stdout29+30+31+def 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