Skip to content

Commit

Permalink
rename to dict instead of json
Browse files Browse the repository at this point in the history
  • Loading branch information
svlandeg committed Jan 10, 2025
1 parent 71ca8e3 commit 240d614
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

You can declare a *CLI parameter* to be a standard Python `dict`:

{* docs_src/parameter_types/json/tutorial001.py hl[5] *}
{* docs_src/parameter_types/dict/tutorial001.py hl[5] *}

Check it:

<div class="termy">

```console
// Run your program
$ python main.py --user-info '{"name": "Camila", "age": 15, "height_meters": 1.7, "female": true}'
$ python main.py --user-info '{"name": "Camila", "age": 15, "height": 1.7, "female": true}'

Name: Camila
User attributes: ['age', 'female', 'height_meters', 'name']
User attributes: ['age', 'female', 'height', 'name']

```

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import typer
from typer.testing import CliRunner

from docs_src.parameter_types.json import tutorial001 as mod
from docs_src.parameter_types.dict import tutorial001 as mod

runner = CliRunner()

Expand All @@ -21,7 +21,7 @@ def test_help():


def test_params():
data = {"name": "Camila", "age": 15, "height_meters": 1.7, "female": True}
data = {"name": "Camila", "age": 15, "height": 1.7, "female": True}
result = runner.invoke(
app,
[
Expand All @@ -30,11 +30,8 @@ def test_params():
],
)
assert result.exit_code == 0
assert "Name: Camila" in result.output.strip()
assert (
f"User attributes: {['age', 'female', 'height_meters', 'name']}"
in result.output.strip()
)
assert "Name: Camila" in result.output
assert "User attributes: ['age', 'female', 'height', 'name']" in result.output


def test_invalid():
Expand Down

0 comments on commit 240d614

Please sign in to comment.