⬆️ Upgrade coverage and configs (#769)
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 · parent 2d4c4c9 · Browse files · 23 files·+59 added−60 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
23 files+59 added−60 removed
- tests:+18 added−18 removed
- other:+41 added−42 removed
Provenance
- Commit
71bdae1- Tree
6420a65- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
2d4c4c9
23 files changed+59 added−60 removed
modified:scripts/test.sh+1 added-1 removed
7 unmodified lines89101112127 unmodified lines# Force disable terminal for tests inside of pytest, takes precedence over GITHUB_ACTIONS env varexport _TYPER_FORCE_DISABLE_TERMINAL=1bash ./scripts/test-files.sh# It seems xdist-pytest ensures modified sys.path to import relative modules in examples keeps workingpytest --cov-config=.coveragerc --cov --cov-report=term-missing -o console_output_style=progress --numprocesses=auto ${@}pytest --cov --cov-report=term-missing -o console_output_style=progress --numprocesses=auto ${@}modified:tests/test_completion/test_completion_install.py+2 added-2 removed
70 unmodified lines71 72 def test_completion_install_zsh():73 completion_path: Path = Path.home() / ".zshrc"74 text = ""75- if not completion_path.is_file(): # pragma: nocover75+ if not completion_path.is_file(): # pragma: no cover76 completion_path.write_text('echo "custom .zshrc"')77 if completion_path.is_file():78 text = completion_path.read_text()79 result = subprocess.run(67 unmodified lines147 Path.home() / ".config/powershell/Microsoft.PowerShell_profile.ps1"148 )149 completion_path_bytes = f"{completion_path}\n".encode("windows-1252")150 text = ""151- if completion_path.is_file(): # pragma: nocover151+ if completion_path.is_file(): # pragma: no cover152 text = completion_path.read_text()153 154 with mock.patch.object(155 shellingham, "detect_shell", return_value=("pwsh", "/usr/bin/pwsh")19 unmodified linesmodified:tests/test_completion/test_completion.py+1 added-1 removed
21 unmodified lines22 23 def test_install_completion():24 bash_completion_path: Path = Path.home() / ".bashrc"25 text = ""26- if bash_completion_path.is_file(): # pragma: nocover26+ if bash_completion_path.is_file(): # pragma: no cover27 text = bash_completion_path.read_text()28 result = subprocess.run(29 [30 "bash",135 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial002_an.py+1 added-1 removed
13 unmodified lines14 15 16 def test_main(tmpdir):17 config_file = Path(tmpdir) / "config.txt"18- if config_file.exists(): # pragma no cover18+ if config_file.exists(): # pragma: no cover19 config_file.unlink()20 result = runner.invoke(app, ["--config", f"{config_file}"])21 text = config_file.read_text()22 config_file.unlink()12 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial002.py+1 added-1 removed
13 unmodified lines14 15 16 def test_main(tmpdir):17 config_file = Path(tmpdir) / "config.txt"18- if config_file.exists(): # pragma no cover18+ if config_file.exists(): # pragma: no cover19 config_file.unlink()20 result = runner.invoke(app, ["--config", f"{config_file}"])21 text = config_file.read_text()22 config_file.unlink()12 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial004_an.py+1 added-1 removed
13 unmodified lines14 15 16 def test_main(tmpdir):17 binary_file = Path(tmpdir) / "config.txt"18- if binary_file.exists(): # pragma no cover18+ if binary_file.exists(): # pragma: no cover19 binary_file.unlink()20 result = runner.invoke(app, ["--file", f"{binary_file}"])21 text = binary_file.read_text()22 binary_file.unlink()13 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial004.py+1 added-1 removed
13 unmodified lines14 15 16 def test_main(tmpdir):17 binary_file = Path(tmpdir) / "config.txt"18- if binary_file.exists(): # pragma no cover18+ if binary_file.exists(): # pragma: no cover19 binary_file.unlink()20 result = runner.invoke(app, ["--file", f"{binary_file}"])21 text = binary_file.read_text()22 binary_file.unlink()13 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial005_an.py+1 added-1 removed
13 unmodified lines14 15 16 def test_main(tmpdir):17 config_file = Path(tmpdir) / "config.txt"18- if config_file.exists(): # pragma no cover18+ if config_file.exists(): # pragma: no cover19 config_file.unlink()20 config_file.write_text("")21 result = runner.invoke(app, ["--config", f"{config_file}"])22 result = runner.invoke(app, ["--config", f"{config_file}"])15 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial005.py+1 added-1 removed
13 unmodified lines14 15 16 def test_main(tmpdir):17 config_file = Path(tmpdir) / "config.txt"18- if config_file.exists(): # pragma no cover18+ if config_file.exists(): # pragma: no cover19 config_file.unlink()20 config_file.write_text("")21 result = runner.invoke(app, ["--config", f"{config_file}"])22 result = runner.invoke(app, ["--config", f"{config_file}"])15 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_path/test_tutorial001_an.py+1 added-1 removed
21 unmodified lines22 23 24 def test_not_exists(tmpdir):25 config_file = Path(tmpdir) / "config.txt"26- if config_file.exists(): # pragma no cover26+ if config_file.exists(): # pragma: no cover27 config_file.unlink()28 result = runner.invoke(app, ["--config", f"{config_file}"])29 assert result.exit_code == 030 assert "The config doesn't exist" in result.output24 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_path/test_tutorial001.py+1 added-1 removed
21 unmodified lines22 23 24 def test_not_exists(tmpdir):25 config_file = Path(tmpdir) / "config.txt"26- if config_file.exists(): # pragma no cover26+ if config_file.exists(): # pragma: no cover27 config_file.unlink()28 result = runner.invoke(app, ["--config", f"{config_file}"])29 assert result.exit_code == 030 assert "The config doesn't exist" in result.output24 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_path/test_tutorial002_an.py+1 added-1 removed
13 unmodified lines14 15 16 def test_not_exists(tmpdir):17 config_file = Path(tmpdir) / "config.txt"18- if config_file.exists(): # pragma no cover18+ if config_file.exists(): # pragma: no cover19 config_file.unlink()20 result = runner.invoke(app, ["--config", f"{config_file}"])21 assert result.exit_code != 022 assert "Invalid value for '--config': File" in result.output25 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_path/test_tutorial002.py+1 added-1 removed
13 unmodified lines14 15 16 def test_not_exists(tmpdir):17 config_file = Path(tmpdir) / "config.txt"18- if config_file.exists(): # pragma no cover18+ if config_file.exists(): # pragma: no cover19 config_file.unlink()20 result = runner.invoke(app, ["--config", f"{config_file}"])21 assert result.exit_code != 022 assert "Invalid value for '--config': File" in result.output25 unmodified linesmodified:tests/test_others.py+5 added-5 removed
92 unmodified lines93 def test_callback_too_many_parameters():94 app = typer.Typer()95 96 def name_callback(ctx, param, val1, val2):97- pass # pragma: nocover97+ pass # pragma: no cover98 99 @app.command()100 def main(name: str = typer.Option(..., callback=name_callback)):101- pass # pragma: nocover101+ pass # pragma: no cover102 103 with pytest.raises(click.ClickException) as exc_info:104 runner.invoke(app, ["--name", "Camila"])105 assert (92 unmodified lines198 def test_autocompletion_too_many_parameters():199 app = typer.Typer()200 201 def name_callback(ctx, args, incomplete, val2):202- pass # pragma: nocover202+ pass # pragma: no cover203 204 @app.command()205 def main(name: str = typer.Option(..., autocompletion=name_callback)):206- pass # pragma: nocover206+ pass # pragma: no cover207 208 with pytest.raises(click.ClickException) as exc_info:209 runner.invoke(app, ["--name", "Camila"])210 assert exc_info.value.message == "Invalid autocompletion callback parameters: val2"24 unmodified lines235 app = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]})236 237 @app.command()238 def main(name: str):239- pass # pragma: nocover239+ pass # pragma: no cover240 241 result = runner.invoke(app, ["main", "-h"])242 assert "Show this message and exit." in result.stdout243 17 unmodified linesmodified:typer/_completion_classes.py+1 added-1 removed
15 unmodified lines16 )17 18 try:19 import shellingham20-except ImportError: # pragma: nocover20+except ImportError: # pragma: no cover21 shellingham = None22 23 24 class BashComplete(click.shell_completion.BashComplete):168 unmodified linesmodified:typer/_completion_shared.py+6 added-6 removed
7 unmodified lines8 import click9 10 try:11 import shellingham12-except ImportError: # pragma: nocover12+except ImportError: # pragma: no cover13 shellingham = None14 15 16 class Shells(str, Enum):90 unmodified lines107 if rc_path.is_file():108 rc_content = rc_path.read_text()109 completion_init_lines = [f"source {completion_path}"]110 for line in completion_init_lines:111- if line not in rc_content: # pragma: nocover111+ if line not in rc_content: # pragma: no cover112 rc_content += f"\n{line}"113 rc_content += "\n"114 rc_path.write_text(rc_content)115 # Install completion18 unmodified lines134 "zstyle ':completion:*' menu select",135 "fpath+=~/.zfunc",136 ]137 for line in completion_init_lines:138- if line not in zshrc_content: # pragma: nocover138+ if line not in zshrc_content: # pragma: no cover139 zshrc_content += f"\n{line}"140 zshrc_content += "\n"141 zshrc_path.write_text(zshrc_content)142 # Install completion under ~/.zfunc/32 unmodified lines175 [shell, "-NoProfile", "-Command", "echo", "$profile"],176 check=True,177 stdout=subprocess.PIPE,178 )179- if result.returncode != 0: # pragma: nocover179+ if result.returncode != 0: # pragma: no cover180 click.echo("Couldn't get PowerShell user profile", err=True)181 raise click.exceptions.Exit(result.returncode)182 path_str = ""183- if isinstance(result.stdout, str): # pragma: nocover183+ if isinstance(result.stdout, str): # pragma: no cover184 path_str = result.stdout185 if isinstance(result.stdout, bytes):186 try:187 # PowerShell would be predominant in Windows188 path_str = result.stdout.decode("windows-1252")189- except UnicodeDecodeError: # pragma: nocover189+ except UnicodeDecodeError: # pragma: no cover190 try:191 path_str = result.stdout.decode("utf8")192 except UnicodeDecodeError:193 click.echo("Couldn't decode the path automatically", err=True)47 unmodified linesmodified:typer/completion.py+5 added-5 removed
10 unmodified lines11 from .utils import get_params_from_function12 13 try:14 import shellingham15-except ImportError: # pragma: nocover15+except ImportError: # pragma: no cover16 shellingham = None17 18 19 _click_patched = False13 unmodified lines33 34 35 def install_callback(ctx: click.Context, param: click.Parameter, value: Any) -> Any:36 if not value or ctx.resilient_parsing:37- return value # pragma no cover37+ return value # pragma: no cover38 if isinstance(value, str):39 shell, path = install(shell=value)40 else:41 shell, path = install()3 unmodified lines45 46 47 def show_callback(ctx: click.Context, param: click.Parameter, value: Any) -> Any:48 if not value or ctx.resilient_parsing:49- return value # pragma no cover49+ return value # pragma: no cover50 prog_name = ctx.find_root().info_name51 assert prog_name52 complete_var = "_{}_COMPLETE".format(prog_name.replace("-", "_").upper())53 shell = ""27 unmodified lines81 expose_value=False,82 help="Show completion for the current shell, to copy it or customize the installation.",83 ),84 ) -> Any:85- pass # pragma no cover85+ pass # pragma: no cover86 87 88 def _install_completion_no_auto_placeholder_function(89 install_completion: Shells = Option(8 unmodified lines98 expose_value=False,99 help="Show completion for the specified shell, to copy it or customize the installation.",100 ),101 ) -> Any:102- pass # pragma no cover102+ pass # pragma: no cover103 104 105 # Re-implement Click's shell_complete to add error message with:106 # Invalid completion instruction43 unmodified linesmodified:typer/core.py+1 added-1 removed
34 unmodified lines35 import rich36 37 from . import rich_utils38 39-except ImportError: # pragma: nocover39+except ImportError: # pragma: no cover40 rich = None # type: ignore41 42 MarkupMode = Literal["markdown", "rich", None]43 697 unmodified linesmodified:typer/main.py+4 added-4 removed
41 unmodified lines42 from rich.traceback import Traceback43 44 console_stderr = Console(stderr=True)45 46-except ImportError: # pragma: nocover46+except ImportError: # pragma: no cover47 rich = None # type: ignore48 49 _original_except_hook = sys.excepthook50 _typer_developer_exception_attr_name = "__typer_developer_exception__"318 unmodified lines369 click_command.params.append(click_show_param)370 return click_command371 raise RuntimeError(372 "Could not get a command for this Typer instance"373- ) # pragma no cover373+ ) # pragma: no cover374 375 376 def get_group_name(typer_info: TyperInfo) -> Optional[str]:377 if typer_info.callback:402 unmodified lines780 return click.Choice(781 [item.value for item in annotation],782 case_sensitive=parameter_info.case_sensitive,783 )784- raise RuntimeError(f"Type not yet supported: {annotation}") # pragma no cover784+ raise RuntimeError(f"Type not yet supported: {annotation}") # pragma: no cover785 786 787 def lenient_issubclass(788 cls: Any, class_or_tuple: Union[AnyType, Tuple[AnyType, ...]]159 unmodified lines948 rich_help_panel=parameter_info.rich_help_panel,949 ),950 convertor,951 )952- raise AssertionError("A click.Parameter should be returned") # pragma no cover952+ raise AssertionError("A click.Parameter should be returned") # pragma: no cover953 954 955 def get_param_callback(956 *,107 unmodified linesdeleted:.coveragerc-23 removed
1-[run]2-3-source =4- typer5- tests6- docs_src7-8-omit =9- typer/_typing.py10-11-parallel = True12-context = '${CONTEXT}'13-14-[report]15-precision = 216-exclude_lines =17- pragma: no cover18- pragma: nocover19- pragma no cover20- raise NotImplementedError21- raise NotImplemented22- @overload23- if TYPE_CHECKING:modified:.gitignore+1 added
9 unmodified lines10 .coverage11 htmlcov12 .pytest_cache13 coverage.xml14+.coverage*modified:pyproject.toml+21 added
74 unmodified lines75 # For pytest-xdist76 'ignore::DeprecationWarning:xdist',77 ]78 79+[tool.coverage.run]80+parallel = true81+data_file = "coverage/.coverage"82+source = [83+ "docs_src",84+ "tests",85+ "typer"86+]87+omit = [88+ "typer/_typing.py"89+]90+context = '${CONTEXT}'91+92+[tool.coverage.report]93+exclude_lines = [94+ "pragma: no cover",95+ "@overload",96+ 'if __name__ == "__main__":',97+ "if TYPE_CHECKING:",98+]99+100 [tool.mypy]101 strict = true102 103 [[tool.mypy.overrides]]58 unmodified linesmodified:requirements-tests.txt+1 added-1 removed
1 -e .[all]2 3 pytest >=4.4.0,<8.0.04 pytest-cov >=2.10.0,<5.0.05-coverage[toml] >=6.2,<7.05+coverage[toml] >=6.2,<8.06 pytest-xdist >=1.32.0,<4.0.07 pytest-sugar >=0.9.4,<0.10.08 mypy ==1.4.19 ruff ==0.2.0