source: rtems-central/rtemsqual/tests/test_content_sphinx.py @ 05246b3

Last change on this file since 05246b3 was a5f3cc1, checked in by Sebastian Huber <sebastian.huber@…>, on 05/06/20 at 08:31:57

spec: Use item mapper for glossary terms

  • Property mode set to 100644
File size: 3.5 KB
Line 
1# SPDX-License-Identifier: BSD-2-Clause
2""" Unit tests for the rtemsqual.content 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 pytest
28
29from rtemsqual.content import SphinxContent, SphinxMapper
30from rtemsqual.items import Item, ItemCache, ItemMapper
31from rtemsqual.tests.util import create_item_cache_config_and_copy_spec
32
33
34def test_add_label():
35    sc = SphinxContent()
36    sc.add_label("x")
37    assert str(sc) == """.. _x:
38"""
39
40
41def test_add_header():
42    sc = SphinxContent()
43    sc.add_header("x")
44    assert str(sc) == """x
45=
46"""
47
48
49def test_append():
50    sc = SphinxContent()
51    sc.append("x")
52    assert str(sc) == """x
53"""
54    with sc.indent():
55        sc.append("y")
56        assert str(sc) == """x
57    y
58"""
59        sc.append("")
60        assert str(sc) == """x
61    y
62
63"""
64
65
66def test_add_index_entries():
67    sc = SphinxContent()
68    sc.add_index_entries(["x", "y"])
69    assert str(sc) == """.. index:: x
70.. index:: y
71"""
72    sc.add_index_entries("z")
73    assert str(sc) == """.. index:: x
74.. index:: y
75
76.. index:: z
77"""
78
79
80def test_add_definition_item():
81    sc = SphinxContent()
82    sc.add_definition_item("x", ["y", "z"])
83    assert str(sc) == """x
84    y
85    z
86"""
87    sc = SphinxContent()
88    sc.add_definition_item("a", "\n b\n")
89    assert str(sc) == """a
90     b
91"""
92
93
94def test_license():
95    sc = SphinxContent()
96    with pytest.raises(ValueError):
97        sc.register_license("x")
98    sc.register_license("CC-BY-SA-4.0")
99    assert str(sc) == ""
100    sc.add_licence_and_copyrights()
101    assert str(sc) == """.. SPDX-License-Identifier: CC-BY-SA-4.0
102
103"""
104
105
106def test_license_and_copyrights():
107    sc = SphinxContent()
108    with pytest.raises(ValueError):
109        sc.register_license("x")
110    sc.register_copyright("Copyright (C) A")
111    assert str(sc) == ""
112    sc.add_licence_and_copyrights()
113    assert str(sc) == """.. SPDX-License-Identifier: CC-BY-SA-4.0
114
115.. Copyright (C) A
116
117"""
118
119
120def test_substitute(tmpdir):
121    config = create_item_cache_config_and_copy_spec(tmpdir, "spec-sphinx")
122    item_cache = ItemCache(config)
123    mapper = SphinxMapper(item_cache["/x"])
124    with pytest.raises(KeyError):
125        mapper.substitute("${x:/y}")
126    assert ":term:`y`" == mapper.substitute("${x:/glossary-term}")
Note: See TracBrowser for help on using the repository browser.