File: test_new_type.py

package info (click to toggle)
python-cyclopts 3.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,288 kB
  • sloc: python: 11,445; makefile: 24
file content (41 lines) | stat: -rw-r--r-- 980 bytes parent folder | download | duplicates (2)
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)