File: test_basic_autoparse.py

package info (click to toggle)
python-autocommand 2.2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 236 kB
  • sloc: python: 1,052; sh: 15; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 899 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
42
43
44
45
import pytest


def test_basic_positional(check_parse):
    def func(arg): pass

    check_parse(
        func,
        "foo",
        arg="foo")


@pytest.mark.parametrize('cli_args', [
    [],
    ['value'],
    ['value1', 'value2']
])
def test_variadic_positional(check_parse, cli_args):
    check_parse(
        lambda arg1, *args: None,
        'arg1_value', *cli_args,
        arg1='arg1_value', args=cli_args)


def test_optional_default(check_parse):
    check_parse(
        lambda arg="default_value": None,
        arg="default_value")


@pytest.mark.parametrize('flags, result', [
    ([], False),
    (['-f'], True),
    (['--no-flag'], False),
    (['--no-flag', '-f'], True),
    (['--flag', '--no-flag'], False)
])
def test_add_nos(check_parse, flags, result):
    def func(flag: bool): pass

    check_parse(
        func,
        *flags,
        add_nos=True,
        flag=result)