summaryrefslogtreecommitdiff
path: root/tests/test_ext_autosectionlabel.py
blob: 42ef0c31ab25a9d92d9ee5f82d4dc1e63c5fb25e (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
# -*- coding: utf-8 -*-
"""
    test_ext_autosectionlabel
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    Test sphinx.ext.autosectionlabel extension.

    :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import re

import pytest


@pytest.mark.sphinx('html', testroot='ext-autosectionlabel')
def test_autosectionlabel_html(app, status, warning):
    app.builder.build_all()

    content = (app.outdir / 'index.html').text()
    html = ('<li><a class="reference internal" href="#introduce-of-sphinx">'
            '<span class=".*?">Introduce of Sphinx</span></a></li>')
    assert re.search(html, content, re.S)

    html = ('<li><a class="reference internal" href="#installation">'
            '<span class="std std-ref">Installation</span></a></li>')
    assert re.search(html, content, re.S)

    html = ('<li><a class="reference internal" href="#for-windows-users">'
            '<span class="std std-ref">For Windows users</span></a></li>')
    assert re.search(html, content, re.S)

    html = ('<li><a class="reference internal" href="#for-unix-users">'
            '<span class="std std-ref">For UNIX users</span></a></li>')
    assert re.search(html, content, re.S)

    # for smart_quotes (refs: #4027)
    html = ('<li><a class="reference internal" '
            'href="#this-one-s-got-an-apostrophe">'
            '<span class="std std-ref">This one’s got an apostrophe'
            '</span></a></li>')
    assert re.search(html, content, re.S)


# Re-use test definition from above, just change the test root directory
@pytest.mark.sphinx('html', testroot='ext-autosectionlabel-prefix-document')
def test_autosectionlabel_prefix_document_html(app, status, warning):
    return test_autosectionlabel_html(app, status, warning)