Coverage for tsfpga/test/test_module_documentation.py: 100%
55 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-21 20:51 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-21 20:51 +0000
1# --------------------------------------------------------------------------------------------------
2# Copyright (c) Lukas Vik. All rights reserved.
3#
4# This file is part of the tsfpga project, a project platform for modern FPGA development.
5# https://tsfpga.com
6# https://github.com/tsfpga/tsfpga
7# --------------------------------------------------------------------------------------------------
9# Standard libraries
10from unittest.mock import MagicMock
12# Third party libraries
13import pytest
14from hdl_registers.register_list import RegisterList
16# First party libraries
17from tsfpga.module import BaseModule
18from tsfpga.module_documentation import ModuleDocumentation
19from tsfpga.system_utils import create_file
21# pylint: disable=redefined-outer-name
24@pytest.fixture
25def module_documentation(tmp_path):
26 module = BaseModule(path=tmp_path / "apa", library_name="apa")
27 module_documentation_object = ModuleDocumentation(module)
29 data = """\
30-- -------------------------------------------------------------------------------------------------
31-- Copyright (c) Lukas Vik. All rights reserved.
32-- -------------------------------------------------------------------------------------------------
33-- Dummy from hest.vhd.
34-- -------------------------------------------------------------------------------------------------
36"""
37 create_file(module.path / "src" / "hest.vhd", contents=data)
39 return module_documentation_object
42def test_documentation_header_with_no_overview_and_no_registers(module_documentation):
43 rst = module_documentation.get_rst_document()
45 assert "\nhest.vhd\n--------" in rst
46 assert "Dummy from hest.vhd." in rst
48 assert "Register interface" not in rst
51def test_documentation_header_with_overview_and_registers(module_documentation):
52 # pylint: disable=protected-access
53 module = module_documentation._module
54 module._registers = MagicMock(spec=RegisterList)
55 module._registers.register_objects = MagicMock(spec=list)
57 data = "Dummy from apa.rst."
58 create_file(module.path / "doc" / "apa.rst", contents=data)
60 rst = module_documentation.get_rst_document()
62 assert "\nhest.vhd\n--------" in rst
63 assert "Dummy from hest.vhd." in rst
65 assert "Dummy from apa.rst" in rst
67 assert "Register interface" in rst
68 assert ":download:`separate HTML page <apa_regs.html>`" in rst
71def test_submodule_documentation_with_file_exclude(module_documentation):
72 data = """\
73-- -------------------------------------------------------------------------------------------------
74-- Copyright (c) Lukas Vik. All rights reserved.
75-- -------------------------------------------------------------------------------------------------
76-- Dummy from excluded.vhd.
77-- -------------------------------------------------------------------------------------------------
79"""
80 # pylint: disable=protected-access
81 excluded_vhd = create_file(
82 module_documentation._module.path / "rtl" / "excluded.vhd", contents=data
83 )
85 rst = module_documentation.get_submodule_rst(heading_character="-", heading_character_2="_")
86 assert "Dummy from excluded.vhd." in rst
88 rst = module_documentation.get_submodule_rst(
89 heading_character="-", heading_character_2="_", exclude_files={excluded_vhd}
90 )
91 assert "Dummy from excluded.vhd." not in rst
94def test_submodule_documentation_with_folder_exclude(module_documentation):
95 data = """\
96-- -------------------------------------------------------------------------------------------------
97-- Copyright (c) Lukas Vik. All rights reserved.
98-- -------------------------------------------------------------------------------------------------
99-- Dummy from excluded.vhd.
100-- -------------------------------------------------------------------------------------------------
102"""
103 # pylint: disable=protected-access
104 create_file(module_documentation._module.path / "rtl" / "excluded.vhd", contents=data)
106 rst = module_documentation.get_submodule_rst(heading_character="-", heading_character_2="_")
107 assert "Dummy from excluded.vhd." in rst
109 rst = module_documentation.get_submodule_rst(
110 heading_character="-",
111 heading_character_2="_",
112 exclude_module_folders=["rtl"],
113 )
114 assert "Dummy from excluded.vhd." not in rst
117def test_include_sim_but_not_test_folder(module_documentation):
118 data = """\
119-- -------------------------------------------------------------------------------------------------
120-- Copyright (c) Lukas Vik. All rights reserved.
121-- -------------------------------------------------------------------------------------------------
122-- Dummy from bfm.vhd.
123-- -------------------------------------------------------------------------------------------------
125"""
126 # pylint: disable=protected-access
127 create_file(module_documentation._module.path / "sim" / "bfm.vhd", contents=data)
129 data = """\
130-- -------------------------------------------------------------------------------------------------
131-- Copyright (c) Lukas Vik. All rights reserved.
132-- -------------------------------------------------------------------------------------------------
133-- Dummy from tb.vhd.
134-- -------------------------------------------------------------------------------------------------
136"""
137 # pylint: disable=protected-access
138 create_file(module_documentation._module.path / "test" / "tb.vhd", contents=data)
140 rst = module_documentation.get_submodule_rst(heading_character="-", heading_character_2="_")
141 assert "Dummy from bfm.vhd." in rst
142 assert "Dummy from tb.vhd." not in rst
144 rst = module_documentation.get_submodule_rst(
145 heading_character="-", heading_character_2="_", exclude_module_folders=["sim"]
146 )
147 assert "Dummy from bfm.vhd." not in rst
148 assert "Dummy from tb.vhd." not in rst