Skip to content
Myr

✅ Only run completion installation tests when the env var `_TYPER_RUN_INSTALL_COMPLETION_TESTS` is set (#995)

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

authored by Sofie Van Landeghem · committed by GitHub · parent dcd5078 · Browse files · 5 files+20 added−1 removed
This commit

State

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

Diff stats

5 files+20 added−1 removed

  • tests:+18 added−1 removed
  • other:+2 added−0 removed

5 files+20 added−1 removed

modified:scripts/test.sh+2 added
modified:tests/test_completion/test_completion_install.py+7 added
8 unmodified lines
9from typer.testing import CliRunner1011from docs_src.commands.index import tutorial001 as mod1213from ..utils import requires_completion_permission1415runner = CliRunner()16app = typer.Typer()17app.command()(mod.main)181920@requires_completion_permission21def test_completion_install_no_shell():22 result = subprocess.run(23 [sys.executable, "-m", "coverage", "run", mod.__file__, "--install-completion"],24 capture_output=True,
5 unmodified lines
30 )31 assert "Option '--install-completion' requires an argument" in result.stderr323334@requires_completion_permission35def test_completion_install_bash():36 bash_completion_path: Path = Path.home() / ".bashrc"37 text = ""38 if bash_completion_path.is_file():
31 unmodified lines
70 in install_content71 )727374@requires_completion_permission75def test_completion_install_zsh():76 completion_path: Path = Path.home() / ".zshrc"77 text = ""78 if not completion_path.is_file(): # pragma: no cover
29 unmodified lines
108 install_source_path.unlink()109 assert "compdef _tutorial001py_completion tutorial001.py" in install_content110111112@requires_completion_permission113def test_completion_install_fish():114 script_path = Path(mod.__file__)115 completion_path: Path = (116 Path.home() / f".config/fish/completions/{script_path.name}.fish"
21 unmodified lines
138 assert "completion installed in" in result.stdout139 assert "Completion will take effect once you restart the terminal" in result.stdout140141142@requires_completion_permission143def test_completion_install_powershell():144 completion_path: Path = (145 Path.home() / ".config/powershell/Microsoft.PowerShell_profile.ps1"146 )
26 unmodified lines
modified:tests/test_completion/test_completion.py+2 added-1 removed
3 unmodified lines
4from pathlib import Path56from docs_src.commands.index import tutorial001 as mod78from ..utils import needs_bash, needs_linux8from ..utils import needs_bash, needs_linux, requires_completion_permission91011@needs_bash12@needs_linux
12 unmodified lines
252627@needs_bash28@needs_linux29@requires_completion_permission30def test_install_completion():31 bash_completion_path: Path = Path.home() / ".bashrc"32 text = ""33 if bash_completion_path.is_file(): # pragma: no cover
131 unmodified lines
modified:tests/test_others.py+3 added
13 unmodified lines
14from typer.main import solve_typer_info_defaults, solve_typer_info_help15from typer.models import ParameterInfo, TyperInfo16from typer.testing import CliRunner1718from .utils import requires_completion_permission1920runner = CliRunner()212223def test_help_from_info():
51 unmodified lines
75 ParameterInfo(parser=custom_parser)76 ParameterInfo(click_type=CustomClickParser())777879@requires_completion_permission80def test_install_invalid_shell():81 app = typer.Typer()8283 @app.command()
197 unmodified lines
modified:tests/utils.py+6 added
1import sys2from os import getenv34import pytest56try:
18 unmodified lines
2526needs_bash = pytest.mark.skipif(27 not shellingham or not shell or "bash" not in shell, reason="Test requires Bash"28)2930requires_completion_permission = pytest.mark.skipif(31 not getenv("_TYPER_RUN_INSTALL_COMPLETION_TESTS", False),32 reason="Test requires permission to run completion installation tests",33)