Debian Codegraph @

tests/test_builders/test_build_manpage.py

raw
1 """Test the build process with manpage builder with the test root."""
2
3 from __future__ import annotations
4
5 from typing import TYPE_CHECKING
6
7 import pytest
8
9 from sphinx.builders.manpage import default_man_pages
10 from sphinx.config import Config
11
12 if TYPE_CHECKING:
13 from sphinx.testing.util import SphinxTestApp
14
15
16 @pytest.mark.sphinx('man', testroot='root')
17 def test_all(app: SphinxTestApp) -> None:
18 app.build(force_all=True)
19 assert (app.outdir / 'sphinxtests.1').exists()
20
21 content = (app.outdir / 'sphinxtests.1').read_text(encoding='utf8')
22 assert r'\fBprint \fP\fIi\fP\fB\en\fP' in content
23 assert r'\fBmanpage\en\fP' in content
24
25 # heading (title + description)
26 assert r'sphinxtests \- Sphinx <Tests> 0.6alpha1' in content
27
28 # term of definition list including nodes.strong
29 assert '\n.B term1\n' in content
30 assert '\nterm2 (\\fBstronged partially\\fP)\n' in content
31
32 # test samp with braces
33 assert '\n\\fIvariable_only\\fP\n' in content
34 assert '\n\\fIvariable\\fP\\fB and text\\fP\n' in content
35 assert '\n\\fBShow \\fP\\fIvariable\\fP\\fB in the middle\\fP\n' in content
36
37 assert 'Footnotes' not in content
38
39
40 @pytest.mark.sphinx(
41 'man',
42 testroot='basic',
43 confoverrides={'man_pages': [('index', 'title', None, [], 1)]},
44 )
45 def test_man_pages_empty_description(app: SphinxTestApp) -> None:
46 app.build(force_all=True)
47
48 content = (app.outdir / 'title.1').read_text(encoding='utf8')
49 assert r'title \-' not in content
50
51
52 @pytest.mark.sphinx(
53 'man',
54 testroot='basic',
55 confoverrides={'man_make_section_directory': True},
56 )
57 def test_man_make_section_directory(app: SphinxTestApp) -> None:
58 app.build()
59 assert (app.outdir / 'man1' / 'projectnamenotset.1').exists()
60
61
62 @pytest.mark.sphinx('man', testroot='directive-code')
63 def test_captioned_code_block(app: SphinxTestApp) -> None:
64 app.build(force_all=True)
65 content = (app.outdir / 'projectnamenotset.1').read_text(encoding='utf8')
66
67 expected = """\
68 .sp
69 caption \\fItest\\fP rb
70 .INDENT 0.0
71 .INDENT 3.5
72 .sp
73 .EX
74 def ruby?
75 false
76 end
77 .EE
78 .UNINDENT
79 .UNINDENT
80 """
81
82 assert expected in content
83
84
85 def test_default_man_pages() -> None:
86 config = Config({
87 'project': 'STASI™ Documentation',
88 'author': "Wolfgang Schäuble & G'Beckstein",
89 'release': '1.0',
90 })
91 expected = [
92 (
93 'index',
94 'stasi',
95 'STASI™ Documentation 1.0',
96 ["Wolfgang Schäuble & G'Beckstein"],
97 1,
98 )
99 ]
100 assert default_man_pages(config) == expected
101
102
103 @pytest.mark.sphinx('man', testroot='markup-rubric')
104 def test_rubric(app: SphinxTestApp) -> None:
105 app.build()
106 content = (app.outdir / 'projectnamenotset.1').read_text(encoding='utf8')
107 assert 'This is a rubric\n' in content