| 1 | from typing import NewType |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | from cyclopts._convert import token_count |
| 6 | |
| 7 | |
| 8 | def test_new_type_str(app, assert_parse_args): |
| 9 | CustomStr = NewType("CustomStr", str) |
| 10 | |
| 11 | @app.default |
| 12 | def main(a: CustomStr): |
| 13 | pass |
| 14 | |
| 15 | assert_parse_args(main, "foo", CustomStr("foo")) |
| 16 | |
| 17 | |
| 18 | def test_new_type_token_count_str(app, assert_parse_args): |
| 19 | CustomStr = NewType("CustomStr", str) |
| 20 | assert (1, False) == token_count(CustomStr) |
| 21 | |
| 22 | |
| 23 | @pytest.mark.parametrize( |
| 24 | "cmd, expected", |
| 25 | [ |
| 26 | ("foo", ["foo"]), |
| 27 | ("--a foo", ["foo"]), |
| 28 | ("foo bar", ["foo", "bar"]), |
| 29 | ("--a foo --a bar", ["foo", "bar"]), |
| 30 | ("foo bar baz", ["foo", "bar", "baz"]), |
| 31 | ("--a foo --a bar --a baz", ["foo", "bar", "baz"]), |
| 32 | ], |
| 33 | ) |
| 34 | def test_new_type_token_count_list_str(app, assert_parse_args, cmd, expected): |
| 35 | CustomStr = NewType("CustomStr", str) |
| 36 | |
| 37 | @app.default |
| 38 | def main(a: list[CustomStr]): |
| 39 | pass |
| 40 | |
| 41 | assert_parse_args(main, cmd, expected) |