Coverage for tests/test_directives.py: 100%
48 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-03-26 16:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-03-26 16:18 +0000
1import os
2import pytest
3from io import StringIO
4from sphinx.application import Sphinx
6def test_example_project():
8 # Get test project dir
9 current_dir = os.path.dirname(os.path.abspath(__file__))
10 project_dir = os.path.join(current_dir, "test_project")
11 src_dir = os.path.join(project_dir, "source")
12 build_dir = os.path.join(project_dir, "build")
14 # Run Sphinx build
15 statusObject = StringIO()
16 warningObject = StringIO()
17 app = Sphinx(
18 srcdir = src_dir,
19 confdir = src_dir,
20 outdir = build_dir,
21 doctreedir = build_dir,
22 buildername = "html",
23 status = statusObject,
24 warning = warningObject,
25 freshenv = True,
26 )
27 app.build()
29 # Verify the output
30 output_file_index = os.path.join(build_dir, "index.html")
31 assert os.path.exists(output_file_index)
33 output_file_elif_else_examples = os.path.join(build_dir, "elif_else_examples.html")
34 assert os.path.exists(output_file_elif_else_examples)
35 with open(output_file_elif_else_examples, "r") as f:
36 output_content = f.read()
37 assert "Coded variants.1.1 shall not be in the output." not in output_content
38 assert "Coded variants.1.2 shall not be in the output." not in output_content
39 assert "Coded variants.1.3 shall be in the output." in output_content
40 assert "Coded variants.1.4 shall not be in the output." not in output_content
41 assert "Coded variants.2.1 shall not be in the output." not in output_content
42 assert "Coded variants.2.2 shall not be in the output." not in output_content
43 assert "Coded variants.2.3 shall be in the output." in output_content
44 assert "Coded variants.2.4 shall not be in the output." not in output_content
46 output_file_minimum_example = os.path.join(build_dir, "minimum_example.html")
47 assert os.path.exists(output_file_minimum_example)
48 with open(output_file_minimum_example, "r") as f:
49 output_content = f.read()
50 assert "This content is included." in output_content
51 assert "This content is excluded." not in output_content
52 assert "This content is also excluded." not in output_content
54 output_file_spacing_examples = os.path.join(build_dir, "spacing_examples.html")
55 assert os.path.exists(output_file_spacing_examples)
56 with open(output_file_spacing_examples, "r") as f:
57 output_content = f.read()
58 assert "Working spaces.1.1 shall not be in the output." not in output_content
59 assert "Working spaces.1.2 shall be in the output." in output_content
60 assert "Working spaces.2.1 shall not be in the output." not in output_content
61 assert "Working spaces.2.2 shall be in the output." in output_content
62 assert "Working spaces.3.1 shall not be in the output." not in output_content
63 assert "Working spaces.3.2 shall be in the output." in output_content
64 assert "Working spaces.4.1 shall not be in the output." not in output_content
65 assert "Working spaces.4.2 shall be in the output." in output_content
66 assert "Working spaces.5.1 shall not be in the output." not in output_content
67 assert "Working spaces.5.2 shall be in the output." in output_content