:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
import os
|
|
|
|
import subprocess
|
2022-11-07 19:01:54 +01:00
|
|
|
import sys
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
from pathlib import Path
|
2020-03-16 13:21:58 +01:00
|
|
|
from unittest import mock
|
2020-01-05 22:20:54 +01:00
|
|
|
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
import click
|
|
|
|
import pytest
|
2020-03-16 13:21:58 +01:00
|
|
|
import shellingham
|
2020-01-05 22:20:54 +01:00
|
|
|
import typer
|
2020-03-16 13:21:58 +01:00
|
|
|
import typer.completion
|
2020-01-05 22:20:54 +01:00
|
|
|
from typer.main import solve_typer_info_defaults, solve_typer_info_help
|
|
|
|
from typer.models import TyperInfo
|
|
|
|
from typer.testing import CliRunner
|
|
|
|
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
|
|
|
|
|
|
def test_help_from_info():
|
|
|
|
# Mainly for coverage/completeness
|
|
|
|
value = solve_typer_info_help(TyperInfo())
|
|
|
|
assert value is None
|
|
|
|
|
|
|
|
|
|
|
|
def test_defaults_from_info():
|
|
|
|
# Mainly for coverage/completeness
|
|
|
|
value = solve_typer_info_defaults(TyperInfo())
|
|
|
|
assert value
|
2020-03-16 13:21:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_install_invalid_shell():
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
@app.command()
|
|
|
|
def main():
|
2022-07-12 18:45:43 +02:00
|
|
|
print("Hello World")
|
2020-03-16 13:21:58 +01:00
|
|
|
|
|
|
|
with mock.patch.object(
|
|
|
|
shellingham, "detect_shell", return_value=("xshell", "/usr/bin/xshell")
|
|
|
|
):
|
|
|
|
result = runner.invoke(app, ["--install-completion"])
|
|
|
|
assert "Shell xshell is not supported." in result.stdout
|
|
|
|
result = runner.invoke(app)
|
|
|
|
assert "Hello World" in result.stdout
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_too_many_parameters():
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
def name_callback(ctx, param, val1, val2):
|
|
|
|
pass # pragma: nocover
|
|
|
|
|
|
|
|
@app.command()
|
|
|
|
def main(name: str = typer.Option(..., callback=name_callback)):
|
|
|
|
pass # pragma: nocover
|
|
|
|
|
|
|
|
with pytest.raises(click.ClickException) as exc_info:
|
|
|
|
runner.invoke(app, ["--name", "Camila"])
|
|
|
|
assert (
|
|
|
|
exc_info.value.message == "Too many CLI parameter callback function parameters"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_2_untyped_parameters():
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
def name_callback(ctx, value):
|
2022-07-12 18:45:43 +02:00
|
|
|
print(f"info name is: {ctx.info_name}")
|
|
|
|
print(f"value is: {value}")
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
|
|
|
|
@app.command()
|
|
|
|
def main(name: str = typer.Option(..., callback=name_callback)):
|
2022-07-12 18:45:43 +02:00
|
|
|
print("Hello World")
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
|
|
|
|
result = runner.invoke(app, ["--name", "Camila"])
|
|
|
|
assert "info name is: main" in result.stdout
|
|
|
|
assert "value is: Camila" in result.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_3_untyped_parameters():
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
def name_callback(ctx, param, value):
|
2022-07-12 18:45:43 +02:00
|
|
|
print(f"info name is: {ctx.info_name}")
|
|
|
|
print(f"param name is: {param.name}")
|
|
|
|
print(f"value is: {value}")
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
|
|
|
|
@app.command()
|
|
|
|
def main(name: str = typer.Option(..., callback=name_callback)):
|
2022-07-12 18:45:43 +02:00
|
|
|
print("Hello World")
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
|
|
|
|
result = runner.invoke(app, ["--name", "Camila"])
|
|
|
|
assert "info name is: main" in result.stdout
|
|
|
|
assert "param name is: name" in result.stdout
|
|
|
|
assert "value is: Camila" in result.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_completion_untyped_parameters():
|
|
|
|
file_path = Path(__file__).parent / "assets/completion_no_types.py"
|
|
|
|
result = subprocess.run(
|
2022-11-07 19:01:54 +01:00
|
|
|
[sys.executable, "-m", "coverage", "run", str(file_path)],
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
encoding="utf-8",
|
|
|
|
env={
|
|
|
|
**os.environ,
|
|
|
|
"_COMPLETION_NO_TYPES.PY_COMPLETE": "complete_zsh",
|
|
|
|
"_TYPER_COMPLETE_ARGS": "completion_no_types.py --name Sebastian --name Ca",
|
|
|
|
"_TYPER_COMPLETE_TESTING": "True",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
assert "info name is: completion_no_types.py" in result.stderr
|
2021-08-30 09:57:12 +02:00
|
|
|
# TODO: when deprecating Click 7, remove second option
|
|
|
|
assert (
|
|
|
|
"args is: []" in result.stderr
|
|
|
|
or "args is: ['--name', 'Sebastian', '--name']" in result.stderr
|
|
|
|
)
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
assert "incomplete is: Ca" in result.stderr
|
|
|
|
assert '"Camila":"The reader of books."' in result.stdout
|
|
|
|
assert '"Carlos":"The writer of scripts."' in result.stdout
|
|
|
|
|
|
|
|
result = subprocess.run(
|
2022-11-07 19:01:54 +01:00
|
|
|
[sys.executable, "-m", "coverage", "run", str(file_path)],
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
encoding="utf-8",
|
|
|
|
)
|
|
|
|
assert "Hello World" in result.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_completion_untyped_parameters_different_order_correct_names():
|
|
|
|
file_path = Path(__file__).parent / "assets/completion_no_types_order.py"
|
|
|
|
result = subprocess.run(
|
2022-11-07 19:01:54 +01:00
|
|
|
[sys.executable, "-m", "coverage", "run", str(file_path)],
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
encoding="utf-8",
|
|
|
|
env={
|
|
|
|
**os.environ,
|
|
|
|
"_COMPLETION_NO_TYPES_ORDER.PY_COMPLETE": "complete_zsh",
|
|
|
|
"_TYPER_COMPLETE_ARGS": "completion_no_types_order.py --name Sebastian --name Ca",
|
|
|
|
"_TYPER_COMPLETE_TESTING": "True",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
assert "info name is: completion_no_types_order.py" in result.stderr
|
2021-08-30 09:57:12 +02:00
|
|
|
# TODO: when deprecating Click 7, remove second option
|
|
|
|
assert (
|
|
|
|
"args is: []" in result.stderr
|
|
|
|
or "args is: ['--name', 'Sebastian', '--name']" in result.stderr
|
|
|
|
)
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
assert "incomplete is: Ca" in result.stderr
|
|
|
|
assert '"Camila":"The reader of books."' in result.stdout
|
|
|
|
assert '"Carlos":"The writer of scripts."' in result.stdout
|
|
|
|
|
|
|
|
result = subprocess.run(
|
2022-11-07 19:01:54 +01:00
|
|
|
[sys.executable, "-m", "coverage", "run", str(file_path)],
|
:sparkles: Add docs for testing, password, version, context. Extra tests, include callback and autocompletion PR (#68)
* :sparkles: Implement custom handling for callbacks with types
* :sparkles: Implement type-based handling for completion functions
* :sparkles: Add examples for custom completion
* :memo: Add docs for custom autocompletion
* :white_check_mark: Add tests for autocompletion
* :sparkles: Document using the context
* :white_check_mark: Add tests for using the context
* :white_check_mark: Add tests init for context
* :wrench: Update Mypy config
* :white_check_mark: Add extra tests for completion
* :pencil2: Fix format, typos, and minor texts
* :sparkles: Update docs for printing, include stdout, stderr, and stdin
* :pencil2: Add references to FastAPI, fix typos
* :pencil2: Fix typo in Typer CLI
* :memo: Update docs for version
* :memo: Update docs for callbacks
* :memo: Update references to stdout/stderr in autocompletion
* :memo: Add docs for password in CLI option
* :memo: Add docs and tests for Testing
* :memo: Add new sections to docs
* :art: Fix formatting
2020-03-18 21:17:47 +01:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
encoding="utf-8",
|
|
|
|
)
|
|
|
|
assert "Hello World" in result.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_autocompletion_too_many_parameters():
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
def name_callback(ctx, args, incomplete, val2):
|
|
|
|
pass # pragma: nocover
|
|
|
|
|
|
|
|
@app.command()
|
|
|
|
def main(name: str = typer.Option(..., autocompletion=name_callback)):
|
|
|
|
pass # pragma: nocover
|
|
|
|
|
|
|
|
with pytest.raises(click.ClickException) as exc_info:
|
|
|
|
runner.invoke(app, ["--name", "Camila"])
|
|
|
|
assert exc_info.value.message == "Invalid autocompletion callback parameters: val2"
|
2020-04-26 15:42:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_forward_references():
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
@app.command()
|
|
|
|
def main(arg1, arg2: int, arg3: "int", arg4: bool = False, arg5: "bool" = False):
|
2022-07-12 18:45:43 +02:00
|
|
|
print(f"arg1: {type(arg1)} {arg1}")
|
|
|
|
print(f"arg2: {type(arg2)} {arg2}")
|
|
|
|
print(f"arg3: {type(arg3)} {arg3}")
|
|
|
|
print(f"arg4: {type(arg4)} {arg4}")
|
|
|
|
print(f"arg5: {type(arg5)} {arg5}")
|
2020-04-26 15:42:13 +02:00
|
|
|
|
|
|
|
result = runner.invoke(app, ["Hello", "2", "invalid"])
|
2021-08-30 09:57:12 +02:00
|
|
|
# TODO: when deprecating Click 7, remove second option
|
|
|
|
|
2020-04-26 15:42:13 +02:00
|
|
|
assert (
|
2022-07-12 18:45:43 +02:00
|
|
|
"Invalid value for 'ARG3': 'invalid' is not a valid integer" in result.stdout
|
|
|
|
or "Invalid value for 'ARG3': invalid is not a valid integer" in result.stdout
|
2020-04-26 15:42:13 +02:00
|
|
|
)
|
|
|
|
result = runner.invoke(app, ["Hello", "2", "3", "--arg4", "--arg5"])
|
|
|
|
assert (
|
|
|
|
"arg1: <class 'str'> Hello\narg2: <class 'int'> 2\narg3: <class 'int'> 3\narg4: <class 'bool'> True\narg5: <class 'bool'> True\n"
|
|
|
|
in result.stdout
|
|
|
|
)
|
2022-07-02 18:36:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_context_settings_inheritance_single_command():
|
|
|
|
app = typer.Typer(context_settings=dict(help_option_names=["-h", "--help"]))
|
|
|
|
|
|
|
|
@app.command()
|
|
|
|
def main(name: str):
|
|
|
|
pass # pragma: nocover
|
|
|
|
|
|
|
|
result = runner.invoke(app, ["main", "-h"])
|
|
|
|
assert "Show this message and exit." in result.stdout
|