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

Last change on this file since a87154a was 2ac9fc8, checked in by Sebastian Huber <sebastian.huber@…>, on 04/15/20 at 09:30:21

Move and split test files

Remove test grouping through test classes.

  • Property mode set to 100644
File size: 4.0 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
30from rtemsqual.content import MacroToSphinx
31from rtemsqual.items import Item
32
33
34def test_add_label():
35    sc = SphinxContent()
36    sc.add_label("x")
37    assert ".. _x:\n" == sc.content
38
39
40def test_add_header():
41    sc = SphinxContent()
42    sc.add_header("x")
43    assert "x\n=\n" == sc.content
44
45
46def test_add_blank_line():
47    sc = SphinxContent()
48    sc.add_blank_line()
49    assert "\n" == sc.content
50
51
52def test_add_line():
53    sc = SphinxContent()
54    sc.add_line("x")
55    assert "x\n" == sc.content
56    sc.add_line("y", 1)
57    assert "x\n    y\n" == sc.content
58    sc.add_line("")
59    assert "x\n    y\n\n" == sc.content
60
61
62def test_add_lines():
63    sc = SphinxContent()
64    sc.add_lines("x")
65    assert sc.content == "x\n"
66    sc.add_lines("y", 1)
67    assert sc.content == "x\n    y\n"
68    sc.add_lines(["a", "b"])
69    assert sc.content == "x\n    y\na\nb\n"
70
71
72def test_add_index_entries():
73    sc = SphinxContent()
74    sc.add_index_entries(["x", "y"])
75    assert "\n.. index:: x\n.. index:: y\n" == sc.content
76    sc.add_index_entries("z")
77    assert "\n.. index:: x\n.. index:: y\n\n.. index:: z\n" == sc.content
78
79
80def test_add_definition_item():
81    sc = SphinxContent()
82    sc.add_definition_item("x", ["y", "z"])
83    assert sc.content == "\nx\n    y\n    z\n"
84    sc = SphinxContent()
85    sc.add_definition_item("a", "\n b\n")
86    assert sc.content == "\na\n     b\n"
87
88
89def test_license():
90    sc = SphinxContent()
91    with pytest.raises(ValueError):
92        sc.register_license("x")
93    sc.register_license("CC-BY-SA-4.0")
94    assert "" == sc.content
95    sc.add_licence_and_copyrights()
96    assert ".. SPDX-License-Identifier: CC-BY-SA-4.0\n\n" == sc.content
97
98
99def test_license_and_copyrights():
100    sc = SphinxContent()
101    with pytest.raises(ValueError):
102        sc.register_license("x")
103    sc.register_copyright("Copyright (C) A")
104    assert "" == sc.content
105    sc.add_licence_and_copyrights()
106    assert ".. SPDX-License-Identifier: CC-BY-SA-4.0\n\n.. Copyright (C) A\n\n" == sc.content
107
108
109def test_write(tmpdir):
110    sc = SphinxContent()
111    sc.add_line("x")
112    path = tmpdir + "/y/z"
113    sc.write(path)
114    with open(path, "r") as src:
115        assert "x\n" == src.read()
116
117
118def test_substitute():
119    macro_to_sphinx = MacroToSphinx()
120    data = {}
121    data["glossary-term"] = "y"
122    terms = {}
123    terms["x"] = Item("x", data)
124    macro_to_sphinx.set_terms(terms)
125    assert "@" == macro_to_sphinx.substitute("@@")
126    assert "@x" == macro_to_sphinx.substitute("@x")
127    with pytest.raises(KeyError):
128        macro_to_sphinx.substitute("@x{y}")
129    assert ":term:`y`" == macro_to_sphinx.substitute("@term{x}")
Note: See TracBrowser for help on using the repository browser.