Debian Codegraph @

test/units/utils/test_plugin_docs.py

raw
1 # -*- coding: utf-8 -*-
2 # (c) 2020 Felix Fontein <[email protected]>
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import annotations
6
7 import copy
8
9 import pytest
10
11 from ansible.utils.plugin_docs import (
12 add_collection_to_versions_and_dates,
13 )
14
15
16 ADD_TESTS = [
17 (
18 # Module options
19 True,
20 False,
21 {
22 'author': 'x',
23 'version_added': '1.0.0',
24 'deprecated': {
25 'removed_in': '2.0.0',
26 },
27 'options': {
28 'test': {
29 'description': '',
30 'type': 'str',
31 'version_added': '1.1.0',
32 'deprecated': {
33 # should not be touched since this isn't a plugin
34 'removed_in': '2.0.0',
35 },
36 'env': [
37 # should not be touched since this isn't a plugin
38 {
39 'version_added': '1.3.0',
40 'deprecated': {
41 'version': '2.0.0',
42 },
43 },
44 ],
45 'ini': [
46 # should not be touched since this isn't a plugin
47 {
48 'version_added': '1.3.0',
49 'deprecated': {
50 'version': '2.0.0',
51 },
52 },
53 ],
54 'vars': [
55 # should not be touched since this isn't a plugin
56 {
57 'version_added': '1.3.0',
58 'deprecated': {
59 'removed_at_date': '2020-01-01',
60 },
61 },
62 ],
63 },
64 'subtest': {
65 'description': '',
66 'type': 'dict',
67 'deprecated': {
68 # should not be touched since this isn't a plugin
69 'version': '2.0.0',
70 },
71 'suboptions': {
72 'suboption': {
73 'description': '',
74 'type': 'int',
75 'version_added': '1.2.0',
76 }
77 },
78 }
79 },
80 },
81 {
82 'author': 'x',
83 'version_added': '1.0.0',
84 'version_added_collection': 'foo.bar',
85 'deprecated': {
86 'removed_in': '2.0.0',
87 'removed_from_collection': 'foo.bar',
88 },
89 'options': {
90 'test': {
91 'description': '',
92 'type': 'str',
93 'version_added': '1.1.0',
94 'version_added_collection': 'foo.bar',
95 'deprecated': {
96 # should not be touched since this isn't a plugin
97 'removed_in': '2.0.0',
98 },
99 'env': [
100 # should not be touched since this isn't a plugin
101 {
102 'version_added': '1.3.0',
103 'deprecated': {
104 'version': '2.0.0',
105 },
106 },
107 ],
108 'ini': [
109 # should not be touched since this isn't a plugin
110 {
111 'version_added': '1.3.0',
112 'deprecated': {
113 'version': '2.0.0',
114 },
115 },
116 ],
117 'vars': [
118 # should not be touched since this isn't a plugin
119 {
120 'version_added': '1.3.0',
121 'deprecated': {
122 'removed_at_date': '2020-01-01',
123 },
124 },
125 ],
126 },
127 'subtest': {
128 'description': '',
129 'type': 'dict',
130 'deprecated': {
131 # should not be touched since this isn't a plugin
132 'version': '2.0.0',
133 },
134 'suboptions': {
135 'suboption': {
136 'description': '',
137 'type': 'int',
138 'version_added': '1.2.0',
139 'version_added_collection': 'foo.bar',
140 }
141 },
142 }
143 },
144 },
145 ),
146 (
147 # Module options
148 True,
149 False,
150 {
151 'author': 'x',
152 'deprecated': {
153 'removed_at_date': '2020-01-01',
154 },
155 },
156 {
157 'author': 'x',
158 'deprecated': {
159 'removed_at_date': '2020-01-01',
160 'removed_from_collection': 'foo.bar',
161 },
162 },
163 ),
164 (
165 # Plugin options
166 False,
167 False,
168 {
169 'author': 'x',
170 'version_added': '1.0.0',
171 'deprecated': {
172 'removed_in': '2.0.0',
173 },
174 'options': {
175 'test': {
176 'description': '',
177 'type': 'str',
178 'version_added': '1.1.0',
179 'deprecated': {
180 # should not be touched since this is the wrong name
181 'removed_in': '2.0.0',
182 },
183 'env': [
184 {
185 'version_added': '1.3.0',
186 'deprecated': {
187 'version': '2.0.0',
188 },
189 },
190 ],
191 'ini': [
192 {
193 'version_added': '1.3.0',
194 'deprecated': {
195 'version': '2.0.0',
196 },
197 },
198 ],
199 'vars': [
200 {
201 'version_added': '1.3.0',
202 'deprecated': {
203 'removed_at_date': '2020-01-01',
204 },
205 },
206 ],
207 },
208 'subtest': {
209 'description': '',
210 'type': 'dict',
211 'deprecated': {
212 'version': '2.0.0',
213 },
214 'suboptions': {
215 'suboption': {
216 'description': '',
217 'type': 'int',
218 'version_added': '1.2.0',
219 }
220 },
221 }
222 },
223 },
224 {
225 'author': 'x',
226 'version_added': '1.0.0',
227 'version_added_collection': 'foo.bar',
228 'deprecated': {
229 'removed_in': '2.0.0',
230 'removed_from_collection': 'foo.bar',
231 },
232 'options': {
233 'test': {
234 'description': '',
235 'type': 'str',
236 'version_added': '1.1.0',
237 'version_added_collection': 'foo.bar',
238 'deprecated': {
239 # should not be touched since this is the wrong name
240 'removed_in': '2.0.0',
241 },
242 'env': [
243 {
244 'version_added': '1.3.0',
245 'version_added_collection': 'foo.bar',
246 'deprecated': {
247 'version': '2.0.0',
248 'collection_name': 'foo.bar',
249 },
250 },
251 ],
252 'ini': [
253 {
254 'version_added': '1.3.0',
255 'version_added_collection': 'foo.bar',
256 'deprecated': {
257 'version': '2.0.0',
258 'collection_name': 'foo.bar',
259 },
260 },
261 ],
262 'vars': [
263 {
264 'version_added': '1.3.0',
265 'version_added_collection': 'foo.bar',
266 'deprecated': {
267 'removed_at_date': '2020-01-01',
268 'collection_name': 'foo.bar',
269 },
270 },
271 ],
272 },
273 'subtest': {
274 'description': '',
275 'type': 'dict',
276 'deprecated': {
277 'version': '2.0.0',
278 'collection_name': 'foo.bar',
279 },
280 'suboptions': {
281 'suboption': {
282 'description': '',
283 'type': 'int',
284 'version_added': '1.2.0',
285 'version_added_collection': 'foo.bar',
286 }
287 },
288 }
289 },
290 },
291 ),
292 (
293 # Return values
294 True, # this value is ignored
295 True,
296 {
297 'rv1': {
298 'version_added': '1.0.0',
299 'type': 'dict',
300 'contains': {
301 'srv1': {
302 'version_added': '1.1.0',
303 },
304 'srv2': {
305 },
306 }
307 },
308 },
309 {
310 'rv1': {
311 'version_added': '1.0.0',
312 'version_added_collection': 'foo.bar',
313 'type': 'dict',
314 'contains': {
315 'srv1': {
316 'version_added': '1.1.0',
317 'version_added_collection': 'foo.bar',
318 },
319 'srv2': {
320 },
321 }
322 },
323 },
324 ),
325 ]
326
327
328 @pytest.mark.parametrize('is_module,return_docs,fragment,expected_fragment', ADD_TESTS)
329 def test_add(is_module, return_docs, fragment, expected_fragment):
330 fragment_copy = copy.deepcopy(fragment)
331 add_collection_to_versions_and_dates(fragment_copy, 'foo.bar', is_module, return_docs)
332 assert fragment_copy == expected_fragment