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
|
from typing import Dict
import pytest
@pytest.mark.parametrize(
"type_",
[
Dict[str, str],
dict,
Dict,
],
)
def test_bind_dict_str_to_str(app, assert_parse_args, type_):
@app.command
def foo(d: type_): # pyright: ignore
pass
assert_parse_args(foo, "foo --d.key_1='val1' --d.key-2='val2'", d={"key_1": "val1", "key-2": "val2"})
def test_bind_dict_str_to_int_typing(app, assert_parse_args):
@app.command
def foo(d: Dict[str, int]):
pass
assert_parse_args(foo, "foo --d.key1=7 --d.key2=42", d={"key1": 7, "key2": 42})
def test_bind_dict_str_to_int_builtin(app, assert_parse_args):
@app.command
def foo(d: Dict[str, int]):
pass
assert_parse_args(foo, "foo --d.key1=7 --d.key2=42", d={"key1": 7, "key2": 42})
|