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
|
from typing import NewType
import pytest
from cyclopts._convert import token_count
def test_new_type_str(app, assert_parse_args):
CustomStr = NewType("CustomStr", str)
@app.default
def main(a: CustomStr):
pass
assert_parse_args(main, "foo", CustomStr("foo"))
def test_new_type_token_count_str(app, assert_parse_args):
CustomStr = NewType("CustomStr", str)
assert (1, False) == token_count(CustomStr)
@pytest.mark.parametrize(
"cmd, expected",
[
("foo", ["foo"]),
("--a foo", ["foo"]),
("foo bar", ["foo", "bar"]),
("--a foo --a bar", ["foo", "bar"]),
("foo bar baz", ["foo", "bar", "baz"]),
("--a foo --a bar --a baz", ["foo", "bar", "baz"]),
],
)
def test_new_type_token_count_list_str(app, assert_parse_args, cmd, expected):
CustomStr = NewType("CustomStr", str)
@app.default
def main(a: list[CustomStr]):
pass
assert_parse_args(main, cmd, expected)
|