Coverage for tsfpga/test/test_module_documentation.py: 100%
55 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-21 20:51 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-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# --------------------------------------------------------------------------------------------------
9from unittest.mock import MagicMock
11import pytest
12from hdl_registers.register_list import RegisterList
14from tsfpga.module import BaseModule
15from tsfpga.module_documentation import ModuleDocumentation
16from tsfpga.system_utils import create_file
19@pytest.fixture
20def module_documentation(tmp_path):
21 module = BaseModule(path=tmp_path / "apa", library_name="apa")
22 module_documentation_object = ModuleDocumentation(module)
24 data = """\
25-- -------------------------------------------------------------------------------------------------
26-- Copyright (c) Lukas Vik. All rights reserved.
27-- -------------------------------------------------------------------------------------------------
28-- Dummy from hest.vhd.
29-- -------------------------------------------------------------------------------------------------
31"""
32 create_file(module.path / "src" / "hest.vhd", contents=data)
34 return module_documentation_object
37def test_documentation_header_with_no_overview_and_no_registers(module_documentation):
38 rst = module_documentation.get_rst_document()
40 assert "\nhest.vhd\n--------" in rst
41 assert "Dummy from hest.vhd." in rst
43 assert "Register interface" not in rst
46def test_documentation_header_with_overview_and_registers(module_documentation):
47 # ruff: noqa: SLF001
48 module = module_documentation._module
49 module._registers = MagicMock(spec=RegisterList)
50 module._registers.register_objects = MagicMock(spec=list)
52 data = "Dummy from apa.rst."
53 create_file(module.path / "doc" / "apa.rst", contents=data)
55 rst = module_documentation.get_rst_document()
57 assert "\nhest.vhd\n--------" in rst
58 assert "Dummy from hest.vhd." in rst
60 assert "Dummy from apa.rst" in rst
62 assert "Register interface" in rst
63 assert ":download:`separate HTML page <apa_regs.html>`" in rst
66def test_submodule_documentation_with_file_exclude(module_documentation):
67 data = """\
68-- -------------------------------------------------------------------------------------------------
69-- Copyright (c) Lukas Vik. All rights reserved.
70-- -------------------------------------------------------------------------------------------------
71-- Dummy from excluded.vhd.
72-- -------------------------------------------------------------------------------------------------
74"""
76 excluded_vhd = create_file(
77 module_documentation._module.path / "rtl" / "excluded.vhd", contents=data
78 )
80 rst = module_documentation.get_submodule_rst(heading_character="-", heading_character_2="_")
81 assert "Dummy from excluded.vhd." in rst
83 rst = module_documentation.get_submodule_rst(
84 heading_character="-", heading_character_2="_", exclude_files={excluded_vhd}
85 )
86 assert "Dummy from excluded.vhd." not in rst
89def test_submodule_documentation_with_folder_exclude(module_documentation):
90 data = """\
91-- -------------------------------------------------------------------------------------------------
92-- Copyright (c) Lukas Vik. All rights reserved.
93-- -------------------------------------------------------------------------------------------------
94-- Dummy from excluded.vhd.
95-- -------------------------------------------------------------------------------------------------
97"""
99 create_file(module_documentation._module.path / "rtl" / "excluded.vhd", contents=data)
101 rst = module_documentation.get_submodule_rst(heading_character="-", heading_character_2="_")
102 assert "Dummy from excluded.vhd." in rst
104 rst = module_documentation.get_submodule_rst(
105 heading_character="-",
106 heading_character_2="_",
107 exclude_module_folders=["rtl"],
108 )
109 assert "Dummy from excluded.vhd." not in rst
112def test_include_sim_but_not_test_folder(module_documentation):
113 data = """\
114-- -------------------------------------------------------------------------------------------------
115-- Copyright (c) Lukas Vik. All rights reserved.
116-- -------------------------------------------------------------------------------------------------
117-- Dummy from bfm.vhd.
118-- -------------------------------------------------------------------------------------------------
120"""
122 create_file(module_documentation._module.path / "sim" / "bfm.vhd", contents=data)
124 data = """\
125-- -------------------------------------------------------------------------------------------------
126-- Copyright (c) Lukas Vik. All rights reserved.
127-- -------------------------------------------------------------------------------------------------
128-- Dummy from tb.vhd.
129-- -------------------------------------------------------------------------------------------------
131"""
133 create_file(module_documentation._module.path / "test" / "tb.vhd", contents=data)
135 rst = module_documentation.get_submodule_rst(heading_character="-", heading_character_2="_")
136 assert "Dummy from bfm.vhd." in rst
137 assert "Dummy from tb.vhd." not in rst
139 rst = module_documentation.get_submodule_rst(
140 heading_character="-", heading_character_2="_", exclude_module_folders=["sim"]
141 )
142 assert "Dummy from bfm.vhd." not in rst
143 assert "Dummy from tb.vhd." not in rst