source: rtems-central/rtemsqual/tests/test_applconfig.py @ a87154a

Last change on this file since a87154a was a87154a, checked in by Sebastian Huber <sebastian.huber@…>, on 04/17/20 at 05:15:26

applconfig: Add unit tests

  • Property mode set to 100644
File size: 9.8 KB
Line 
1# SPDX-License-Identifier: BSD-2-Clause
2""" Unit tests for the rtemsqual.applconfig module. """
3
4# Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26
27import os
28import shutil
29
30from rtemsqual.applconfig import generate
31from rtemsqual.items import ItemCache
32
33
34def test_applconfig(tmpdir):
35    item_cache_config = {}
36    item_cache_config["cache-directory"] = "cache"
37    spec_src = os.path.join(os.path.dirname(__file__), "spec-applconfig")
38    spec_dst = os.path.join(tmpdir, "spec")
39    shutil.copytree(spec_src, spec_dst)
40    item_cache_config["paths"] = [os.path.normpath(spec_dst)]
41    ic = ItemCache(item_cache_config)
42
43    applconfig_config = {}
44    applconfig_config["groups"] = [{"uid": "g", "target": "g.rst"}]
45    generate(applconfig_config, ic)
46
47    with open("g.rst", "r") as src:
48        content = (
49            ".. SPDX-License-Identifier: CC-BY-SA-4.0\n"
50            "\n"
51            ".. Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)\n"
52            "\n"
53            "group name\n"
54            "==========\n"
55            "\n"
56            "description\n"
57            "\n"
58            ".. index:: a\n"
59            ".. index:: index a\n"
60            "\n"
61            ".. _a:\n"
62            "\n"
63            "a\n"
64            "-\n"
65            "\n"
66            "CONSTANT:\n"
67            "    ``a``\n"
68            "\n"
69            "OPTION TYPE:\n"
70            "    This configuration option is a boolean feature define.\n"
71            "\n"
72            "DEFAULT CONFIGURATION:\n"
73            "    default a\n"
74            "\n"
75            "DESCRIPTION:\n"
76            "    description a\n"
77            "\n"
78            "NOTES:\n"
79            "    notes a\n"
80            "\n"
81            ".. index:: b\n"
82            "\n"
83            ".. _b:\n"
84            "\n"
85            "b\n"
86            "-\n"
87            "\n"
88            "CONSTANT:\n"
89            "    ``b``\n"
90            "\n"
91            "OPTION TYPE:\n"
92            "    This configuration option is a boolean feature define.\n"
93            "\n"
94            "DEFAULT CONFIGURATION:\n"
95            "    If this configuration option is undefined, then the described feature is not\n"
96            "    enabled.\n"
97            "\n"
98            "DESCRIPTION:\n"
99            "    description b\n"
100            "\n"
101            "NOTES:\n"
102            "    None.\n"
103            "\n"
104            ".. index:: c\n"
105            "\n"
106            ".. _c:\n"
107            "\n"
108            "c\n"
109            "-\n"
110            "\n"
111            "CONSTANT:\n"
112            "    ``c``\n"
113            "\n"
114            "OPTION TYPE:\n"
115            "    This configuration option is an integer define.\n"
116            "\n"
117            "DEFAULT VALUE:\n"
118            "    The default value is 13.\n"
119            "\n"
120            "VALUE CONSTRAINTS:\n"
121            "    The value of this configuration option shall satisfy all of the following\n"
122            "    constraints:\n"
123            "\n"
124            "    * It shall be greater than or equal to -1.\n"
125            "\n"
126            "    * It shall be less than or equal to 99.\n"
127            "\n"
128            "    * custom c 1\n"
129            "\n"
130            "    * custom c 2\n"
131            "\n"
132            "    * constraint d\n"
133            "\n"
134            "DESCRIPTION:\n"
135            "    description c\n"
136            "\n"
137            "NOTES:\n"
138            "    notes c\n"
139            "\n"
140            ".. index:: e\n"
141            "\n"
142            ".. _e:\n"
143            "\n"
144            "e\n"
145            "-\n"
146            "\n"
147            "CONSTANT:\n"
148            "    ``e``\n"
149            "\n"
150            "OPTION TYPE:\n"
151            "    This configuration option is an integer define.\n"
152            "\n"
153            "DEFAULT VALUE:\n"
154            "    The default value is 7.\n"
155            "\n"
156            "VALUE CONSTRAINTS:\n"
157            "    The value of this configuration option shall be greater than or equal to -2.\n"
158            "\n"
159            "DESCRIPTION:\n"
160            "    description e\n"
161            "\n"
162            "NOTES:\n"
163            "    None.\n"
164            "\n"
165            ".. index:: f\n"
166            "\n"
167            ".. _f:\n"
168            "\n"
169            "f\n"
170            "-\n"
171            "\n"
172            "CONSTANT:\n"
173            "    ``f``\n"
174            "\n"
175            "OPTION TYPE:\n"
176            "    This configuration option is an integer define.\n"
177            "\n"
178            "DEFAULT VALUE:\n"
179            "    The default value is 1.\n"
180            "\n"
181            "VALUE CONSTRAINTS:\n"
182            "    The value of this configuration option shall be less than or equal to 2.\n"
183            "\n"
184            "DESCRIPTION:\n"
185            "    description f\n"
186            "\n"
187            "NOTES:\n"
188            "    None.\n"
189            "\n"
190            ".. index:: h\n"
191            "\n"
192            ".. _h:\n"
193            "\n"
194            "h\n"
195            "-\n"
196            "\n"
197            "CONSTANT:\n"
198            "    ``h``\n"
199            "\n"
200            "OPTION TYPE:\n"
201            "    This configuration option is an integer define.\n"
202            "\n"
203            "DEFAULT VALUE:\n"
204            "    The default value is 1.\n"
205            "\n"
206            "VALUE CONSTRAINTS:\n"
207            "    custom h\n"
208            "\n"
209            "DESCRIPTION:\n"
210            "    description h\n"
211            "\n"
212            "NOTES:\n"
213            "    None.\n"
214            "\n"
215            ".. index:: i\n"
216            "\n"
217            ".. _i:\n"
218            "\n"
219            "i\n"
220            "-\n"
221            "\n"
222            "CONSTANT:\n"
223            "    ``i``\n"
224            "\n"
225            "OPTION TYPE:\n"
226            "    This configuration option is an integer define.\n"
227            "\n"
228            "DEFAULT VALUE:\n"
229            "    The default value is 1.\n"
230            "\n"
231            "VALUE CONSTRAINTS:\n"
232            "    The value of this configuration option shall be\n"
233            "    an element of {1, 2, 3}.\n"
234            "\n"
235            "DESCRIPTION:\n"
236            "    description i\n"
237            "\n"
238            "NOTES:\n"
239            "    None.\n"
240            "\n"
241            ".. index:: j\n"
242            "\n"
243            ".. _j:\n"
244            "\n"
245            "j\n"
246            "-\n"
247            "\n"
248            "CONSTANT:\n"
249            "    ``j``\n"
250            "\n"
251            "OPTION TYPE:\n"
252            "    This configuration option is an integer define.\n"
253            "\n"
254            "DEFAULT VALUE:\n"
255            "    The default value is 1.\n"
256            "\n"
257            "VALUE CONSTRAINTS:\n"
258            "    The value of this configuration option shall satisfy all of the following\n"
259            "    constraints:\n"
260            "\n"
261            "    * It shall be an element of [1, 2].\n"
262            "\n"
263            "    * constraint d\n"
264            "\n"
265            "DESCRIPTION:\n"
266            "    description j\n"
267            "\n"
268            "NOTES:\n"
269            "    None.\n"
270            "\n"
271            ".. index:: k\n"
272            "\n"
273            ".. _k:\n"
274            "\n"
275            "k\n"
276            "-\n"
277            "\n"
278            "CONSTANT:\n"
279            "    ``k``\n"
280            "\n"
281            "OPTION TYPE:\n"
282            "    This configuration option is an integer define.\n"
283            "\n"
284            "DEFAULT VALUE:\n"
285            "    The default value is 1.\n"
286            "\n"
287            "VALUE CONSTRAINTS:\n"
288            "    The value of this configuration option shall satisfy all of the following\n"
289            "    constraints:\n"
290            "\n"
291            "    * custom k 1\n"
292            "\n"
293            "    * custom k 2\n"
294            "\n"
295            "DESCRIPTION:\n"
296            "    description k\n"
297            "\n"
298            "NOTES:\n"
299            "    None.\n"
300            "\n"
301            ".. index:: l\n"
302            "\n"
303            ".. _l:\n"
304            "\n"
305            "l\n"
306            "-\n"
307            "\n"
308            "CONSTANT:\n"
309            "    ``l``\n"
310            "\n"
311            "OPTION TYPE:\n"
312            "    This configuration option is an initializer define.\n"
313            "\n"
314            "DEFAULT VALUE:\n"
315            "    The default value is 1.\n"
316            "\n"
317            "VALUE CONSTRAINTS:\n"
318            "    The value of this configuration option shall be greater than or equal to 0\n"
319            "    and less than or equal to 2.\n"
320            "\n"
321            "DESCRIPTION:\n"
322            "    description l\n"
323            "\n"
324            "NOTES:\n"
325            "    None.\n")
326        assert content == src.read()
Note: See TracBrowser for help on using the repository browser.