Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/assets/cli/multiapp-docs-title.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ $ multiapp sub hello [OPTIONS]

**Options**:

* `--name TEXT`: [default: World]
* `--age INTEGER`: The age of the user [default: 0]
* `--name <str>`: [default: World]
* `--age <int>`: The age of the user [default: 0]
* `--help`: Show this message and exit.

### `multiapp sub hi`
Expand All @@ -76,12 +76,12 @@ Say Hi
**Usage**:

```console
$ multiapp sub hi [OPTIONS] [USER]
$ multiapp sub hi [OPTIONS] [user]
```

**Arguments**:

* `[USER]`: The name of the user to greet [default: World]
* `[user]`: The name of the user to greet [default: World]

**Options**:

Expand Down
8 changes: 4 additions & 4 deletions tests/assets/cli/multiapp-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ $ multiapp sub hello [OPTIONS]

**Options**:

* `--name TEXT`: [default: World]
* `--age INTEGER`: The age of the user [default: 0]
* `--name <str>`: [default: World]
* `--age <int>`: The age of the user [default: 0]
* `--help`: Show this message and exit.

### `multiapp sub hi`
Expand All @@ -76,12 +76,12 @@ Say Hi
**Usage**:

```console
$ multiapp sub hi [OPTIONS] [USER]
$ multiapp sub hi [OPTIONS] [user]
```

**Arguments**:

* `[USER]`: The name of the user to greet [default: World]
* `[user]`: The name of the user to greet [default: World]

**Options**:

Expand Down
6 changes: 3 additions & 3 deletions tests/assets/cli/richformattedapp-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Say <span style="color: #800000; text-decoration-color: #800000; font-weight: bo
**Usage**:

```console
$ hello [OPTIONS] USER_1 [USER_2]
$ hello [OPTIONS] {user_1} [user_2]
```

**Arguments**:

* `USER_1`: The <span style="font-weight: bold">cool</span> name of the <span style="color: #008000; text-decoration-color: #008000">user</span> [required]
* `[USER_2]`: The world [default: The World]
* `user_1`: The <span style="font-weight: bold">cool</span> name of the <span style="color: #008000; text-decoration-color: #008000">user</span> [required]
* `[user_2]`: The world [default: The World]

**Options**:

Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def cmd(value: str) -> None:
output_lines = result.output.splitlines()
usage_idx = output_lines.index("Usage: very-long-program-name-that-forces-wrap ")
args_line = output_lines[usage_idx + 1]
assert args_line.lstrip() == "[OPTIONS] VALUE"
assert args_line.lstrip() == "[OPTIONS] {value}"
assert args_line.startswith(" ")


Expand Down
62 changes: 61 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main(
command = typer.main.get_command(app)
params = {param.name: param for param in command.params}

assert params["my_arg_1"].human_readable_name == "MY_ARG_1"
assert params["my_arg_1"].human_readable_name == "my_arg_1"
assert params["my_arg_2"].human_readable_name == "META_ARG"
assert params["my_opt"].human_readable_name == "my_opt"

Expand Down Expand Up @@ -377,3 +377,63 @@ def main(names: list[str] = typer.Option(None)):
result = runner.invoke(app, [], default_map={"names": "not-a-list"})
assert result.exit_code == 2
assert "Invalid value" in result.output


def test_parameter_name_casing():
app = typer.Typer()

@app.command()
def main(
arg1: int,
arg2: int = 42,
arg3: int = typer.Argument(...),
ARG4: int = typer.Argument(42),
ARG5: int = typer.Option(...),
arg6: int = typer.Option(42),
arg7: int = typer.Argument(42, metavar="meta7"),
arg8: int = typer.Argument(metavar="ARG8"),
arg9: int = typer.Option(metavar="ARG9"),
):
print(
f"arg1={arg1} arg2={arg2} arg3={arg3} ARG4={ARG4} ARG5={ARG5} "
f"arg6={arg6} arg7={arg7} arg8={arg8} arg9={arg9}"
)

result = runner.invoke(
app,
[
"1",
"3",
"4",
"7",
"8",
"--arg2",
"2",
"--ARG5",
"5",
"--arg6",
"6",
"--ARG9",
"9",
],
)
assert result.exit_code == 0
assert (
"arg1=1 arg2=2 arg3=3 ARG4=4 ARG5=5 arg6=6 arg7=7 arg8=8 arg9=9"
in result.output
)

result = runner.invoke(app, ["1", "3", "4", "7", "8", "--ARG5", "5", "--ARG9", "9"])
assert result.exit_code == 0
assert (
"arg1=1 arg2=42 arg3=3 ARG4=4 ARG5=5 arg6=42 arg7=7 arg8=8 arg9=9"
in result.output
)

result = runner.invoke(app, ["1", "3", "4", "7", "8", "--arg5", "5", "--ARG9", "9"])
assert result.exit_code != 0
assert "No such option: --arg5" in result.output

result = runner.invoke(app, ["1", "3", "4", "7", "8", "--ARG5", "5", "--arg9", "9"])
assert result.exit_code != 0
assert "No such option: --arg9" in result.output
2 changes: 1 addition & 1 deletion tests/test_prog_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ def test_custom_prog_name():
capture_output=True,
encoding="utf-8",
)
assert "Usage: custom-name [OPTIONS] I" in result.stdout
assert "Usage: custom-name [OPTIONS] {i}" in result.stdout
2 changes: 1 addition & 1 deletion tests/test_rich_markup_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main(arg: str):
assert "Hello World" in result.stdout

result = runner.invoke(app, ["--help"])
assert "ARG [required]" in result.stdout
assert "arg [required]" in result.stdout
assert all(c not in result.stdout for c in rounded)


Expand Down
29 changes: 16 additions & 13 deletions tests/test_rich_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def main(bar: str):

result = runner.invoke(app, ["--help"])
assert "Usage" in result.stdout
assert "BAR" in result.stdout
assert "{bar}" in result.stdout


@needs_rich
Expand Down Expand Up @@ -233,8 +233,8 @@ def main(
arg1: int,
arg2: int = 42,
arg3: int = typer.Argument(...),
arg4: int = typer.Argument(42),
arg5: int = typer.Option(...),
ARG4: int = typer.Argument(42),
ARG5: int = typer.Option(...),
arg6: int = typer.Option(42),
arg7: int = typer.Argument(42, metavar="meta7"),
arg8: int = typer.Argument(metavar="ARG8"),
Expand All @@ -243,23 +243,26 @@ def main(
pass # pragma: no cover

result = runner.invoke(app, ["--help"])
assert "Usage: main [OPTIONS] ARG1 ARG3 [ARG4] [meta7] ARG8 arg9" in result.stdout
assert (
"Usage: main [OPTIONS] {arg1} {arg3} [ARG4] [meta7] {ARG8} {arg9}"
in result.stdout
)

out_nospace = result.stdout.replace(" ", "")

# arguments
assert "arg1INTEGER" in out_nospace
assert "arg3INTEGER" in out_nospace
assert "[arg4]INTEGER" in out_nospace
assert "[meta7]INTEGER" in out_nospace
assert "ARG8INTEGER" in out_nospace
assert "arg9INTEGER" in out_nospace
assert "arg1<int>" in out_nospace
assert "arg3<int>" in out_nospace
assert "[ARG4]<int>" in out_nospace
assert "[meta7]<int>" in out_nospace
assert "ARG8<int>" in out_nospace
assert "arg9<int>" in out_nospace

assert "arg7" not in result.stdout.lower()
assert "arg8" not in result.stdout
assert "ARG9" not in result.stdout

# options
assert "arg2INTEGER" in out_nospace
assert "arg5INTEGER" in out_nospace
assert "arg6INTEGER" in out_nospace
assert "--arg2<int>" in out_nospace
assert "--ARG5<int>" in out_nospace
assert "--arg6<int>" in out_nospace
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType:
def test_help(mod: ModuleType):
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "[OPTIONS] [name]" in result.output
assert "Arguments" in result.output
assert "[default: Wade Wilson]" in result.output

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType:
def test_help(mod: ModuleType):
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "[OPTIONS] [name]" in result.output
assert "Arguments" in result.output
assert "[default: (dynamic)]" in result.output

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType:
def test_help(mod: ModuleType):
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "[OPTIONS] [name]" in result.output
assert "Arguments" in result.output
assert "env var: AWESOME_NAME" in result.output
assert "default: World" in result.output
Expand All @@ -37,7 +37,7 @@ def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType):
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "[OPTIONS] [name]" in result.output
assert "Arguments" in result.output
assert "env var: AWESOME_NAME" in result.output
assert "default: World" in result.output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType:
def test_help(mod: ModuleType):
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "[OPTIONS] [name]" in result.output
assert "Arguments" in result.output
assert "env var: AWESOME_NAME, GOD_NAME" in result.output
assert "default: World" in result.output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType:
def test_help(mod: ModuleType):
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "[OPTIONS] [name]" in result.output
assert "Arguments" in result.output
assert "env var: AWESOME_NAME" not in result.output
assert "default: World" in result.output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType:
def test_help(mod: ModuleType):
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] NAME" in result.output
assert "[OPTIONS] {name}" in result.output
assert "Arguments" in result.output
assert "NAME" in result.output
assert "{name}" in result.output
assert "The name of the user to greet" in result.output
assert "[required]" in result.output

Expand All @@ -37,9 +37,9 @@ def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType):
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] NAME" in result.output
assert "[OPTIONS] {name}" in result.output
assert "Arguments" in result.output
assert "NAME" in result.output
assert "{name}" in result.output
assert "The name of the user to greet" in result.output
assert "[required]" in result.output

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType:
def test_help(mod: ModuleType):
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] NAME" in result.output
assert "[OPTIONS] {name}" in result.output
assert "Say hi to NAME very gently, like Dirk." in result.output
assert "Arguments" in result.output
assert "NAME" in result.output
assert "{name}" in result.output
assert "The name of the user to greet" in result.output
assert "[required]" in result.output

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType:
def test_help(mod: ModuleType):
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "[OPTIONS] [name]" in result.output
assert "Say hi to NAME very gently, like Dirk." in result.output
assert "Arguments" in result.output
assert "NAME" in result.output
assert "[name]" in result.output
assert "Who to greet" in result.output
assert "[default: World]" in result.output

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType:
def test_help(mod: ModuleType):
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "[OPTIONS] [name]" in result.output
assert "Say hi to NAME very gently, like Dirk." in result.output
assert "Arguments" in result.output
assert "NAME" in result.output
assert "[name]" in result.output
assert "Who to greet" in result.output
assert "[default: World]" not in result.output

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType:
def test_help(mod: ModuleType):
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "Usage: main [OPTIONS] [NAME]" in result.output
assert "Usage: main [OPTIONS] [name]" in result.output
assert "Arguments" in result.output
assert "Who to greet" in result.output
assert "[default: (Deadpoolio the amazing's name)]" in result.output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType:
def test_help(mod: ModuleType):
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "[OPTIONS] [name]" in result.output
assert "Say hi to NAME very gently, like Dirk." in result.output
assert "Arguments" not in result.output
assert "[default: World]" not in result.output
Expand All @@ -36,7 +36,7 @@ def test_help_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType):
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "[OPTIONS] [name]" in result.output
assert "Say hi to NAME very gently, like Dirk." in result.output
assert "Arguments" not in result.output
assert "[default: World]" not in result.output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_cli(app: typer.Typer):
def test_cli_missing_argument(app: typer.Typer):
result = runner.invoke(app)
assert result.exit_code == 2
assert "Missing argument 'NAME'" in result.output
assert "Missing argument 'name'" in result.output


def test_script(mod: ModuleType):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_mod(request: pytest.FixtureRequest) -> ModuleType:
def test_call_no_arg(mod: ModuleType):
result = runner.invoke(mod.app)
assert result.exit_code != 0
assert "Missing argument 'NAME'." in result.output
assert "Missing argument 'name'." in result.output


def test_call_no_arg_standalone(mod: ModuleType):
Expand All @@ -40,7 +40,7 @@ def test_call_no_arg_no_rich(monkeypatch: pytest.MonkeyPatch, mod: ModuleType):
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(mod.app)
assert result.exit_code != 0
assert "Error: Missing argument 'NAME'" in result.output
assert "Error: Missing argument 'name'" in result.output


def test_call_arg(mod: ModuleType):
Expand Down
Loading
Loading