File: test_site.py

package info (click to toggle)
mkdocs-macros-plugin 1.3.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 316 kB
  • sloc: python: 1,199; makefile: 4
file content (64 lines) | stat: -rw-r--r-- 1,560 bytes parent folder | download
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
"""
Testing the project

(C) Laurent Franceschetti 2024
"""


import pytest

from mkdocs_test import DocProject





def test_pages():
    project = DocProject(".")
    build_result = project.build(strict=False)
    # did not fail
    return_code = project.build_result.returncode
    assert not return_code, f"Build returned with {return_code} {build_result.args})" 

    # ----------------
    # First page
    # ----------------
    VARIABLE_NAME = 'greeting'

    # it is defined in the config file (extra)
    assert VARIABLE_NAME in project.config.extra

    page = project.get_page('index')
    assert page.is_markdown_rendered()
    
    # check that the `greeting` variable (defined under 'extra') is rendered:
    variables = project.config.extra
    assert VARIABLE_NAME in variables
    assert variables.greeting in page.markdown
    

    # ----------------
    # Second page
    # ----------------
    # there is intentionally an error (`foo` does not exist)
    page = project.get_page('second')
    assert 'foo' not in project.config.extra
    assert page.is_markdown_rendered()
    assert page.find('Macro Rendering Error')
    
def test_strict():
    "This project must fail"
    project = DocProject(".")

    # it must fail with the --strict option,
    # because the second page contains an error
    project.build(strict=True)
    assert project.build_result.returncode
    warning = project.find_entry("Macro Rendering", 
                              severity='warning')
    assert warning, "No warning found"
    print(warning)