-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathtest_option.py
More file actions
134 lines (87 loc) · 3.3 KB
/
test_option.py
File metadata and controls
134 lines (87 loc) · 3.3 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from __future__ import annotations
import pytest
from cleo.exceptions import CleoLogicError
from cleo.exceptions import CleoValueError
from cleo.io.inputs.option import Option
def test_create() -> None:
opt = Option("option")
assert opt.name == "option"
assert opt.shortcut is None
assert opt.is_flag()
assert not opt.accepts_value()
assert not opt.requires_value()
assert not opt.is_list()
assert not opt.default
assert not opt.choices
def test_dashed_name() -> None:
opt = Option("--option")
assert opt.name == "option"
def test_fail_if_name_is_empty() -> None:
with pytest.raises(CleoValueError):
Option("")
def test_fail_if_default_value_provided_for_flag() -> None:
with pytest.raises(CleoLogicError):
Option("option", flag=True, default="default")
def test_fail_if_wrong_default_value_for_list_option() -> None:
with pytest.raises(CleoLogicError):
Option("option", flag=False, is_list=True, default="default")
def test_fail_if_choices_provided_for_flag() -> None:
with pytest.raises(CleoLogicError):
Option("option", flag=True, choices=["ch1", "ch2"])
def test_fail_if_choices_without_required_values() -> None:
with pytest.raises(CleoLogicError):
Option("option", flag=False, requires_value=False, choices=["ch1", "ch2"])
def test_shortcut() -> None:
opt = Option("option", "o")
assert opt.shortcut == "o"
def test_dashed_shortcut() -> None:
opt = Option("option", "-o")
assert opt.shortcut == "o"
def test_multiple_shortcuts() -> None:
opt = Option("option", "-o|oo|-ooo")
assert opt.shortcut == "o|oo|ooo"
def test_fail_if_shortcut_is_empty() -> None:
with pytest.raises(CleoValueError):
Option("option", "")
def test_optional_value() -> None:
opt = Option("option", flag=False, requires_value=False)
assert not opt.is_flag()
assert opt.accepts_value()
assert not opt.requires_value()
assert not opt.is_list()
assert opt.default is None
def test_optional_value_with_default() -> None:
opt = Option("option", flag=False, requires_value=False, default="Default")
assert not opt.is_flag()
assert opt.accepts_value()
assert not opt.requires_value()
assert not opt.is_list()
assert opt.default == "Default"
def test_required_value() -> None:
opt = Option("option", flag=False, requires_value=True)
assert not opt.is_flag()
assert opt.accepts_value()
assert opt.requires_value()
assert not opt.is_list()
assert opt.default is None
def test_required_value_with_default() -> None:
opt = Option("option", flag=False, requires_value=True, default="Default")
assert not opt.is_flag()
assert opt.accepts_value()
assert opt.requires_value()
assert not opt.is_list()
assert opt.default == "Default"
def test_list() -> None:
opt = Option("option", flag=False, is_list=True)
assert not opt.is_flag()
assert opt.accepts_value()
assert opt.requires_value()
assert opt.is_list()
assert opt.default == []
def test_multi_valued_with_default() -> None:
opt = Option("option", flag=False, is_list=True, default=["foo", "bar"])
assert not opt.is_flag()
assert opt.accepts_value()
assert opt.requires_value()
assert opt.is_list()
assert opt.default == ["foo", "bar"]