File: test_helpers.py

package info (click to toggle)
python-cleo 2.2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,120 kB
  • sloc: python: 8,293; makefile: 22; sh: 2
file content (72 lines) | stat: -rw-r--r-- 1,848 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from __future__ import annotations

from cleo.helpers import argument
from cleo.helpers import option


def test_argument() -> None:
    arg = argument("foo", "Foo")

    assert arg.description == "Foo"
    assert arg.is_required()
    assert not arg.is_list()
    assert arg.default is None

    arg = argument("foo", "Foo", optional=True, default="bar")

    assert not arg.is_required()
    assert not arg.is_list()
    assert arg.default == "bar"

    arg = argument("foo", "Foo", multiple=True)

    assert arg.is_required()
    assert arg.is_list()
    assert [] == arg.default

    arg = argument("foo", "Foo", optional=True, multiple=True, default=["bar"])

    assert not arg.is_required()
    assert arg.is_list()
    assert ["bar"] == arg.default


def test_option() -> None:
    opt = option("foo", "f", "Foo")

    assert opt.description == "Foo"
    assert not opt.accepts_value()
    assert not opt.requires_value()
    assert not opt.is_list()
    assert opt.default is False

    opt = option("foo", "f", "Foo", flag=False)

    assert opt.description == "Foo"
    assert opt.accepts_value()
    assert opt.requires_value()
    assert not opt.is_list()
    assert opt.default is None

    opt = option("foo", "f", "Foo", flag=False, value_required=False)

    assert opt.description == "Foo"
    assert opt.accepts_value()
    assert not opt.requires_value()
    assert not opt.is_list()

    opt = option("foo", "f", "Foo", flag=False, multiple=True)

    assert opt.description == "Foo"
    assert opt.accepts_value()
    assert opt.requires_value()
    assert opt.is_list()
    assert opt.default == []

    opt = option("foo", "f", "Foo", flag=False, default="bar")

    assert opt.description == "Foo"
    assert opt.accepts_value()
    assert opt.requires_value()
    assert not opt.is_list()
    assert opt.default == "bar"