Debian Codegraph @

mkdocs/tests/integration.py

raw
1 """
2 # MkDocs Integration tests.
3
4 This is a simple integration test that builds the MkDocs
5 documentation against all of the builtin themes.
6
7 From the root of the MkDocs git repo, use:
8
9 python -m mkdocs.tests.integration --help
10
11
12 TODOs
13 - Build with different configuration options.
14 - Build documentation other than just MkDocs as it is relatively simple.
15 """
16
17
18 import logging
19 import os
20 import subprocess
21 import tempfile
22
23 import click
24
25 log = logging.getLogger('mkdocs')
26
27 DIR = os.path.dirname(__file__)
28 MKDOCS_CONFIG = os.path.abspath(os.path.join(DIR, '../../mkdocs.yml'))
29 MKDOCS_THEMES = ['mkdocs', 'readthedocs']
30 TEST_PROJECTS = os.path.abspath(os.path.join(DIR, 'integration'))
31
32
33 @click.command()
34 @click.option(
35 '--output',
36 help="The output directory to use when building themes",
37 type=click.Path(file_okay=False, writable=True),
38 )
39 def main(output=None):
40 if output is None:
41 directory = tempfile.TemporaryDirectory(prefix='mkdocs_integration-')
42 output = directory.name
43
44 log.propagate = False
45 stream = logging.StreamHandler()
46 formatter = logging.Formatter("\033[1m\033[1;32m *** %(message)s *** \033[0m")
47 stream.setFormatter(formatter)
48 log.addHandler(stream)
49 log.setLevel(logging.DEBUG)
50
51 base_cmd = ['mkdocs', 'build', '-q', '-s', '--site-dir']
52
53 log.debug("Building installed themes.")
54 for theme in sorted(MKDOCS_THEMES):
55 log.debug(f"Building theme: {theme}")
56 project_dir = os.path.dirname(MKDOCS_CONFIG)
57 out = os.path.join(output, theme)
58 command = [*base_cmd, out, '--theme', theme]
59 subprocess.check_call(command, cwd=project_dir)
60
61 log.debug("Building test projects.")
62 for project in os.listdir(TEST_PROJECTS):
63 project_dir = os.path.join(TEST_PROJECTS, project)
64 if not os.path.isdir(project_dir):
65 continue
66 log.debug(f"Building test project: {project}")
67 out = os.path.join(output, project)
68 command = [*base_cmd, out]
69 subprocess.check_call(command, cwd=project_dir)
70
71 log.debug(f"Theme and integration builds are in {output}")
72
73
74 if __name__ == '__main__':
75 main()