test_completion.py
This file
Path
tests/test_completion.py
49 lines · 1.3 KiB · Python
Last changed by
:white_check_mark: Add tests for completionSebastián Ramírezbefore adoptiondcbe3fc
History of this fileTake it
:white_check_mark: Add tests for completionSebastián Ramírezbefore adoptiondcbe3fc
lines 1–49why, one step back1import 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)