Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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 tsfpga.module import BaseModule 

13from tsfpga.module_documentation import ModuleDocumentation 

14from tsfpga.system_utils import create_file 

15from tsfpga.registers.register_list import RegisterList 

16 

17# pylint: disable=redefined-outer-name 

18 

19 

20@pytest.fixture 

21def module_documentation(tmp_path): 

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

23 module_documentation_object = ModuleDocumentation(module) 

24 

25 data = """\ 

26-- ------------------------------------------------------------------------------------------------- 

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

28-- ------------------------------------------------------------------------------------------------- 

29-- Dummy from hest.vhd. 

30-- ------------------------------------------------------------------------------------------------- 

31 

32""" 

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

34 

35 return module_documentation_object 

36 

37 

38def test_documentation_header_with_no_overview_and_no_registers(module_documentation): 

39 rst = module_documentation.get_rst_document() 

40 

41 assert "Sub-module hest.vhd" in rst 

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

43 

44 assert "Register interface" not in rst 

45 

46 

47def test_documentation_header_with_overview_and_registers(module_documentation): 

48 # pylint: disable=protected-access 

49 module = module_documentation._module 

50 module._registers = MagicMock(spec=RegisterList) 

51 

52 data = "Dummy from apa.rst." 

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

54 

55 rst = module_documentation.get_rst_document() 

56 

57 assert "Sub-module hest.vhd" in rst 

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

59 

60 assert "Dummy from apa.rst" in rst 

61 

62 assert "Register interface" in rst 

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

64 

65 

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-- ------------------------------------------------------------------------------------------------- 

73 

74""" 

75 # pylint: disable=protected-access 

76 excluded_vhd = create_file( 

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

78 ) 

79 

80 rst = module_documentation.get_submodule_rst(heading_character="-") 

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

82 

83 rst = module_documentation.get_submodule_rst( 

84 heading_character="-", exclude_files={excluded_vhd} 

85 ) 

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