Coverage for tsfpga/test/unit/test_module_documentation.py: 100%

54 statements  

« prev     ^ index     » next       coverage.py v6.4, created at 2022-05-28 04:01 +0000

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the tsfpga project. 

5# https://tsfpga.com 

6# https://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9from unittest.mock import MagicMock 

10import pytest 

11 

12from hdl_registers.register_list import RegisterList 

13 

14from tsfpga.module import BaseModule 

15from tsfpga.module_documentation import ModuleDocumentation 

16from tsfpga.system_utils import create_file 

17 

18# pylint: disable=redefined-outer-name 

19 

20 

21@pytest.fixture 

22def module_documentation(tmp_path): 

23 module = BaseModule(path=tmp_path / "apa", library_name="apa") 

24 module_documentation_object = ModuleDocumentation(module) 

25 

26 data = """\ 

27-- ------------------------------------------------------------------------------------------------- 

28-- Copyright (c) Lukas Vik. All rights reserved. 

29-- ------------------------------------------------------------------------------------------------- 

30-- Dummy from hest.vhd. 

31-- ------------------------------------------------------------------------------------------------- 

32 

33""" 

34 create_file(module.path / "src" / "hest.vhd", contents=data) 

35 

36 return module_documentation_object 

37 

38 

39def test_documentation_header_with_no_overview_and_no_registers(module_documentation): 

40 rst = module_documentation.get_rst_document() 

41 

42 assert "\nhest.vhd\n--------" in rst 

43 assert "Dummy from hest.vhd." in rst 

44 

45 assert "Register interface" not in rst 

46 

47 

48def test_documentation_header_with_overview_and_registers(module_documentation): 

49 # pylint: disable=protected-access 

50 module = module_documentation._module 

51 module._registers = MagicMock(spec=RegisterList) 

52 

53 data = "Dummy from apa.rst." 

54 create_file(module.path / "doc" / "apa.rst", contents=data) 

55 

56 rst = module_documentation.get_rst_document() 

57 

58 assert "\nhest.vhd\n--------" in rst 

59 assert "Dummy from hest.vhd." in rst 

60 

61 assert "Dummy from apa.rst" in rst 

62 

63 assert "Register interface" in rst 

64 assert ":download:`separate HTML page <apa_regs.html>`" in rst 

65 

66 

67def test_submodule_documentation_with_file_exclude(module_documentation): 

68 data = """\ 

69-- ------------------------------------------------------------------------------------------------- 

70-- Copyright (c) Lukas Vik. All rights reserved. 

71-- ------------------------------------------------------------------------------------------------- 

72-- Dummy from excluded.vhd. 

73-- ------------------------------------------------------------------------------------------------- 

74 

75""" 

76 # pylint: disable=protected-access 

77 excluded_vhd = create_file( 

78 module_documentation._module.path / "rtl" / "excluded.vhd", contents=data 

79 ) 

80 

81 rst = module_documentation.get_submodule_rst(heading_character="-", heading_character_2="_") 

82 assert "Dummy from excluded.vhd." in rst 

83 

84 rst = module_documentation.get_submodule_rst( 

85 heading_character="-", heading_character_2="_", exclude_files={excluded_vhd} 

86 ) 

87 assert "Dummy from excluded.vhd." not in rst 

88 

89 

90def test_submodule_documentation_with_folder_exclude(module_documentation): 

91 data = """\ 

92-- ------------------------------------------------------------------------------------------------- 

93-- Copyright (c) Lukas Vik. All rights reserved. 

94-- ------------------------------------------------------------------------------------------------- 

95-- Dummy from excluded.vhd. 

96-- ------------------------------------------------------------------------------------------------- 

97 

98""" 

99 # pylint: disable=protected-access 

100 create_file(module_documentation._module.path / "rtl" / "excluded.vhd", contents=data) 

101 

102 rst = module_documentation.get_submodule_rst(heading_character="-", heading_character_2="_") 

103 assert "Dummy from excluded.vhd." in rst 

104 

105 rst = module_documentation.get_submodule_rst( 

106 heading_character="-", 

107 heading_character_2="_", 

108 exclude_module_folders=["rtl"], 

109 ) 

110 assert "Dummy from excluded.vhd." not in rst 

111 

112 

113def test_include_sim_but_not_test_folder(module_documentation): 

114 data = """\ 

115-- ------------------------------------------------------------------------------------------------- 

116-- Copyright (c) Lukas Vik. All rights reserved. 

117-- ------------------------------------------------------------------------------------------------- 

118-- Dummy from bfm.vhd. 

119-- ------------------------------------------------------------------------------------------------- 

120 

121""" 

122 # pylint: disable=protected-access 

123 create_file(module_documentation._module.path / "sim" / "bfm.vhd", contents=data) 

124 

125 data = """\ 

126-- ------------------------------------------------------------------------------------------------- 

127-- Copyright (c) Lukas Vik. All rights reserved. 

128-- ------------------------------------------------------------------------------------------------- 

129-- Dummy from tb.vhd. 

130-- ------------------------------------------------------------------------------------------------- 

131 

132""" 

133 # pylint: disable=protected-access 

134 create_file(module_documentation._module.path / "test" / "tb.vhd", contents=data) 

135 

136 rst = module_documentation.get_submodule_rst(heading_character="-", heading_character_2="_") 

137 assert "Dummy from bfm.vhd." in rst 

138 assert "Dummy from tb.vhd." not in rst 

139 

140 rst = module_documentation.get_submodule_rst( 

141 heading_character="-", heading_character_2="_", exclude_module_folders=["sim"] 

142 ) 

143 assert "Dummy from bfm.vhd." not in rst 

144 assert "Dummy from tb.vhd." not in rst