-
-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathtest_argument.py
More file actions
74 lines (54 loc) · 2.12 KB
/
Copy pathtest_argument.py
File metadata and controls
74 lines (54 loc) · 2.12 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
from __future__ import annotations
import pytest
from cleo.exceptions import CleoLogicError
from cleo.io.inputs.argument import Argument
def test_optional_non_list_argument() -> None:
argument = Argument(
"foo",
required=False,
is_list=False,
description="Foo description",
default="bar",
)
assert argument.name == "foo"
assert not argument.is_required()
assert not argument.is_list()
assert argument.description == "Foo description"
assert argument.default == "bar"
def test_required_non_list_argument() -> None:
argument = Argument("foo", is_list=False, description="Foo description")
assert argument.name == "foo"
assert argument.is_required()
assert not argument.is_list()
assert argument.description == "Foo description"
assert argument.default is None
def test_list_argument() -> None:
argument = Argument("foo", is_list=True, description="Foo description")
assert argument.name == "foo"
assert argument.is_required()
assert argument.is_list()
assert argument.description == "Foo description"
assert argument.default == []
def test_required_arguments_do_not_support_default_values() -> None:
with pytest.raises(
CleoLogicError, match="Cannot set a default value for required arguments"
):
Argument("foo", description="Foo description", default="bar")
def test_list_arguments_do_not_support_non_list_default_values() -> None:
with pytest.raises(
CleoLogicError, match="A default value for a list argument must be a list"
):
Argument(
"foo",
required=False,
is_list=True,
description="Foo description",
default="bar",
)
def test_argument_with_choices() -> None:
argument = Argument("foo", choices=["choice1", "choice2"])
assert argument.name == "foo"
assert argument.choices == ["choice1", "choice2"]
def test_argument_default_not_in_choices() -> None:
with pytest.raises(CleoLogicError, match="A default value must be in choices"):
Argument("foo", default="arg0", choices=["arg1", "arg2"])