-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_parser.py
More file actions
171 lines (147 loc) · 4.45 KB
/
test_parser.py
File metadata and controls
171 lines (147 loc) · 4.45 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
from typing import Any, Dict, List
import pytest
from gardenlinux.features import Parser
from ..constants import GL_ROOT_DIR
@pytest.mark.parametrize(
"input_cname, expected_output",
[
(
"aws-gardener_prod",
{
"platform": ["aws"],
"element": [
"log",
"sap",
"ssh",
"base",
"server",
"cloud",
"multipath",
"iscsi",
"nvme",
"gardener",
],
"flag": ["_fwcfg", "_legacy", "_nopkg", "_prod", "_slim"],
},
),
(
"gcp-gardener_prod",
{
"platform": ["gcp"],
"element": [
"log",
"sap",
"ssh",
"base",
"server",
"cloud",
"multipath",
"iscsi",
"nvme",
"gardener",
],
"flag": ["_fwcfg", "_legacy", "_nopkg", "_prod", "_slim"],
},
),
(
"azure-gardener_prod",
{
"platform": ["azure"],
"element": [
"log",
"sap",
"ssh",
"base",
"server",
"cloud",
"multipath",
"iscsi",
"nvme",
"gardener",
],
"flag": ["_fwcfg", "_legacy", "_nopkg", "_prod", "_slim"],
},
),
(
"ali-gardener_prod",
{
"platform": ["ali"],
"element": [
"log",
"sap",
"ssh",
"base",
"server",
"cloud",
"multipath",
"iscsi",
"nvme",
"gardener",
],
"flag": ["_fwcfg", "_legacy", "_nopkg", "_prod", "_slim"],
},
),
(
"openstack-metal-khost_dev",
{
"platform": ["openstack"],
"element": [
"firewall",
"log",
"sap",
"ssh",
"base",
"server",
"chost",
"khost",
"metal",
],
"flag": ["_dev", "_fwcfg", "_legacy", "_selinux", "_slim"],
},
),
],
)
def test_parser_filter_as_dict(
input_cname: str, expected_output: Dict[str, Any]
) -> None:
"""
Tests if parser_filter_as_dict returns the dict with expected features.
If you discover that this test failed, you may want to verify if the included
features have changed since writing this test. In this case, update the expected output accordingly.
You can print the output of parser_filter_as_dict so you have the dict in the expected format.
"""
features_dict = Parser(GL_ROOT_DIR).filter_as_dict(input_cname)
assert features_dict == expected_output
def test_parser_return_intersection_subset() -> None:
# Arrange
input_set = {"a", "c"}
order_list = ["a", "b", "c", "d"]
# Act
result = Parser.subset(input_set, order_list)
# Assert
assert result == ["a", "c"]
def test_get_flavor_from_feature_set() -> None:
# Arrange
sorted_features = ["base", "_hidden", "extra"]
# Act
result = Parser.get_flavor_from_feature_set(sorted_features)
# Assert
assert result == "base_hidden-extra"
def test_gget_flavor_from_feature_set_empty_raises() -> None:
# get_flavor with empty iterable raises TypeError
with pytest.raises(TypeError):
Parser.get_flavor_from_feature_set([])
def test_parser_subset_nomatch() -> None:
# Arrange
input_set = {"x", "y"}
order_list = ["a", "b", "c"]
# Act
result = Parser.subset(input_set, order_list)
# Assert
assert result == []
def test_parser_subset_with_empty_order_list() -> None:
# Arrange
input_set = {"a", "b"}
order_list: List[str] = []
result = Parser.subset(input_set, order_list)
assert result == []