summaryrefslogtreecommitdiff
path: root/src/tools/docwriter/tests/test_siteconfig.py
blob: 32fb00577548d9b3f9fea576ef60dd280481b44c (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#
#  test_siteconfig.py
#
#    Tests for site config generation (siteconfig.py).
#
#  Copyright 2018 by
#  Nikhil Ramakrishnan.
#
#  This file is part of the FreeType project, and may only be used,
#  modified, and distributed under the terms of the FreeType project
#  license, LICENSE.TXT.  By continuing to use, modify, or distribute
#  this file you indicate that you have read the license and
#  understand and accept it fully.

"""Docwriter site config tests.

This module tests the validity of the `yml` configuration
generated by `siteconfig.py`.
"""
import os

import yaml

import siteconfig
import utils

config = siteconfig.SiteConfig()

# Config vars
site_name        = "Foo Bar Test"
site_description = "Test documentation for Foo Bar."
site_author      = "Pytest"
toc_filename     = "foo-toc.md"
index_filename   = "foo-index.md"

# Add chapters and pagess
c1_sec   = ["c1s1", "c1s2", "c1s3"]
c2_sec   = ["c2s1", "c2s2"]

pages = {}
pages['chap1'] = c1_sec
pages['chap2'] = c2_sec

def test_config( tmpdir, caplog ):
    utils.output_dir = str( tmpdir )
    # Set site config
    config.set_site_info( site_name, site_description,
                        site_author )
    # Add toc and index
    config.add_single_page( "TOC", toc_filename )
    config.add_single_page( "Index", index_filename )

    # Add chapters and pages
    for chap, parts in pages.items():
        config.start_chapter( chap )
        for sec in parts:
            config.add_chapter_page( sec, sec + ".md" )
        config.end_chapter()

    # Done, Build config
    config.build_config()

    # Open file and parse yml
    filepath = os.path.join( str( tmpdir ), 'mkdocs.yml' )
    result = open( filepath, 'rb' ).read()
    data = yaml.safe_load(result)

    # Assertions
    assert data is not None
    for record in caplog.records:
        # Strict build - there should be no warnings
        assert record.levelname != 'WARNING'