-
-
Notifications
You must be signed in to change notification settings - Fork 972
Expand file tree
/
Copy pathtest_issue_493.py
More file actions
86 lines (65 loc) · 2.3 KB
/
Copy pathtest_issue_493.py
File metadata and controls
86 lines (65 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import typer
from typer.testing import CliRunner
runner = CliRunner()
def test_boolean_help_display() -> None:
app = typer.Typer()
@app.command()
def main(
debug: bool = typer.Option(False, "--debug", help="Enable debug mode"),
) -> None:
pass
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "BOOL" in result.stdout
assert "[default: False]" in result.stdout
def test_boolean_help_display_show_default_false() -> None:
app = typer.Typer()
@app.command()
def main(
debug: bool = typer.Option(
False, "--debug", help="Enable debug mode", show_default=False
),
) -> None:
pass
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
# We check that the debug line doesn't have BOOL or [default: False]
debug_line = [line for line in result.stdout.split("\n") if "--debug" in line][0]
assert "BOOL" not in debug_line
assert "[default: False]" not in debug_line
def test_boolean_help_display_true_default_secondary() -> None:
app = typer.Typer()
@app.command()
def main(
debug: bool = typer.Option(
True, "--debug/--no-debug", help="Enable debug mode"
),
) -> None:
pass
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "BOOL" in result.stdout
assert "[default: debug]" in result.stdout
def test_boolean_help_display_false_default_secondary() -> None:
app = typer.Typer()
@app.command()
def main(
debug: bool = typer.Option(
False, "--debug/--no-debug", help="Enable debug mode"
),
) -> None:
pass
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "BOOL" in result.stdout
assert "[default: no-debug]" in result.stdout
def test_boolean_argument_help_display() -> None:
app = typer.Typer()
@app.command()
def main(force: bool = typer.Argument(False, help="Force execution")) -> None:
pass
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
# Arguments might show up with their name in brackets as metavar by default in Click
# but we want to ensure the default value is shown at least.
assert "[default: False]" in result.stdout