source: rtems-central/rtemsspec/tests/test_specdoc.py @ 7617fcb

Last change on this file since 7617fcb was 7617fcb, checked in by Sebastian Huber <sebastian.huber@…>, on 07/28/20 at 04:56:37

specdoc: Fix output format of regular expressions

  • Property mode set to 100644
File size: 6.6 KB
Line 
1# SPDX-License-Identifier: BSD-2-Clause
2""" Unit tests for the rtemsspec.specdoc 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
28
29from rtemsspec.items import ItemCache
30from rtemsspec.specdoc import document
31from rtemsspec.tests.util import create_item_cache_config_and_copy_spec
32
33
34def test_document(tmpdir):
35    item_cache_config = create_item_cache_config_and_copy_spec(
36        tmpdir, "spec-doc")
37    item_cache_config["spec-type-root-uid"] = "/root"
38    item_cache = ItemCache(item_cache_config)
39    assert item_cache["/root"].type == "spec"
40    doc_target = os.path.join(tmpdir, "items.rst")
41    config = {
42        "root-type": "/root",
43        "doc-target": doc_target,
44    }
45    document(config, item_cache)
46    with open(doc_target, "r") as src:
47        content = """.. SPDX-License-Identifier: CC-BY-SA-4.0
48
49.. Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
50
51.. _ReqEngSpecificationItems:
52
53Specification Items
54===================
55
56.. _ReqEngSpecificationItemHierarchy:
57
58Specification Item Hierarchy
59----------------------------
60
61The specification item types have the following hierarchy:
62
63* :ref:`SpecTypeRoot`
64
65  * :ref:`SpecTypeA`
66
67  * :ref:`SpecTypeB`
68
69.. _ReqEngSpecificationItemTypes:
70
71Specification Item Types
72------------------------
73
74.. _SpecTypeRoot:
75
76Root
77^^^^
78
79A value of this type shall be of one of the following variants:
80
81* The value may be a boolean. A reference to :ref:`SpecTypeRoot`. The value
82  shall be true.
83
84* The value may be a set of attributes. All explicit attributes shall be
85  specified. The explicit attributes for this type are:
86
87  type
88      The attribute value shall be a :ref:`SpecTypeName`.
89
90  In addition to the explicit attributes, generic attributes may be specified.
91  Each generic attribute key shall be a :ref:`SpecTypeName`. Each generic
92  attribute value shall be a :ref:`SpecTypeRoot`.
93
94* The value may be a floating-point number. The value shall be equal to 0.0.
95
96* The value may be an integer number. The value shall be equal to 0.
97
98* The value may be a list. Each list element shall be a :ref:`SpecTypeRoot`.
99
100* There may by be no value (null).
101
102* The value may be a string. The value
103
104  * shall meet,
105
106    * shall contain an element of
107
108      * "``a``",
109
110      * "``b``", and
111
112      * "``c``",
113
114    * and, shall be equal to "``d``",
115
116    * and, shall be greater than or equal to "``e``",
117
118    * and, shall be greater than "``f``",
119
120    * and, shall be an element of
121
122      * "``g``", and
123
124      * "``h``",
125
126    * and, shall be less than or equal to "``i``",
127
128    * and, shall be less than "``j``",
129
130    * and, shall be not equal to "``k``",
131
132    * and, shall match with the regular expression "``l``",
133
134    * and, shall be true,
135
136    * and, shall be a valid item UID,
137
138  * or,
139
140    * shall be an element of,
141
142    * or, shall be an element of
143
144      * "``x``",
145
146  * or, shall not meet,
147
148    * shall not contain an element of
149
150      * "``a``",
151
152      * "``b``", and
153
154      * "``c``",
155
156    * or, shall be not equal to "``d``",
157
158    * or, shall be less than "``e``",
159
160    * or, shall be less than or equal to "``f``",
161
162    * or, shall not be an element of
163
164      * "``g``", and
165
166      * "``h``",
167
168    * or, shall be greater than "``i``",
169
170    * or, shall be greater than or equal to "``j``",
171
172    * or, shall be equal to "``k``",
173
174    * or, shall not match with the regular expression "``l``",
175
176    * or, shall be false,
177
178    * or, shall be an invalid item UID.
179
180This type is refined by the following types:
181
182* :ref:`SpecTypeA`
183
184* :ref:`SpecTypeB`
185
186This type is used by the following types:
187
188* :ref:`SpecTypeRoot`
189
190.. _SpecTypeA:
191
192A
193^
194
195This type refines the :ref:`SpecTypeRoot` though the ``type`` attribute if the
196value is ``spec``.
197
198The explicit attributes for this type are:
199
200a
201    The attribute value shall be an :ref:`SpecTypeA`.
202
203This type is used by the following types:
204
205* :ref:`SpecTypeA`
206
207Please have a look at the following example:
208
209.. code-block:: yaml
210
211    a: null
212
213.. _SpecTypeB:
214
215B
216^
217
218This type refines the following types:
219
220* :ref:`SpecTypeD` though the ``d1`` attribute if the value is ``b``
221
222* :ref:`SpecTypeRoot` though the ``type`` attribute if the value is ``b``
223
224Generic attributes may be specified. Each generic attribute key shall be a
225:ref:`SpecTypeName`. Each generic attribute value shall be a list. Each list
226element shall be a string.
227
228.. _ReqEngSpecificationAttributeSetsAndValueTypes:
229
230Specification Attribute Sets and Value Types
231--------------------------------------------
232
233.. _SpecTypeC:
234
235C
236^
237
238Only the ``c`` attribute is mandatory. The explicit attributes for this type
239are:
240
241c
242    The attribute value shall be a floating-point number.
243
244.. _SpecTypeD:
245
246D
247^
248
249The following explicit attributes are mandatory:
250
251* ``d1``
252
253* ``d2``
254
255The explicit attributes for this type are:
256
257d1
258    The attribute value shall be a :ref:`SpecTypeName`.
259
260d2
261    The attribute shall have no value.
262
263This type is refined by the following types:
264
265* :ref:`SpecTypeB`
266
267.. _SpecTypeName:
268
269Name
270^^^^
271
272The value shall be a string. A string is a valid name if it matches with the
273``^([a-z][a-z0-9-]*|SPDX-License-Identifier)$`` regular expression.
274
275This type is used by the following types:
276
277* :ref:`SpecTypeB`
278
279* :ref:`SpecTypeD`
280
281* :ref:`SpecTypeRoot`
282
283.. _SpecTypeUID:
284
285UID
286^^^
287
288The value shall be a string. The string shall be a valid absolute or relative
289item UID.
290"""
291        assert content == src.read()
Note: See TracBrowser for help on using the repository browser.