1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
import io
import os
import shutil
from contextlib import contextmanager
from sphinx.application import Sphinx
@contextmanager
def sphinx_build(test_dir, confoverrides=None):
os.chdir(f"tests/{test_dir}")
try:
app = Sphinx(
srcdir=".",
confdir=".",
outdir="_build/text",
doctreedir="_build/.doctrees",
buildername="text",
confoverrides=confoverrides,
)
app.build(force_all=True)
yield
finally:
if os.path.exists("_build"):
shutil.rmtree("_build")
os.chdir("../..")
class LanguageIntegrationTests:
def _run_test(self, test_dir, test_file, test_string):
with sphinx_build(test_dir):
with open(test_file, encoding="utf8") as fin:
text = fin.read().strip()
assert test_string in text
class TestIntegration(LanguageIntegrationTests):
def test_template_overrides(self):
self._run_test(
"templateexample",
"_build/text/autoapi/example/index.txt",
"This is a function template override",
)
class TestTOCTree(LanguageIntegrationTests):
def test_toctree_overrides(self):
self._run_test("toctreeexample", "_build/text/index.txt", "API Reference")
def test_toctree_domain_insertion(self):
"""
Test that the example_function gets added to the TOC Tree
"""
self._run_test(
"toctreeexample", "_build/text/index.txt", '* "example_function()"'
)
|