File: test_debug.py

package info (click to toggle)
sphinxcontrib-bibtex 2.6.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,140 kB
  • sloc: python: 4,668; makefile: 245
file content (114 lines) | stat: -rw-r--r-- 4,189 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""Some tests purely used for stepping into the debugger
to help understand what docutils/sphinx are doing.
"""

import shutil

import docutils
import pytest

docutils_citation_xml = """
    <paragraph>
        <reference ids="id1" internal="1" refid="label">
            <inline>
                [Label]
    <citation backrefs="id1" docname="index" ids="label" names="label">
        <label support_smartquotes="0">
            Label
        <paragraph>
            The title.
"""

bibtex_citation_xml = """
    <paragraph>
        <inline ids="id1">
            [
            <reference internal="1" refid="id3" reftitle="The title.">
                tes
            ]
    <container ids="id2">
        <citation backrefs="id1" docname="index" ids="id3">
            <label support_smartquotes="0">
                tes
            <paragraph>
                The title.
"""

if docutils.__version_info__ < (0, 22):
    docutils_citation_xml = docutils_citation_xml.replace('="1"', '="True"')
    docutils_citation_xml = docutils_citation_xml.replace('="0"', '="False"')
    bibtex_citation_xml = bibtex_citation_xml.replace('="1"', '="True"')
    bibtex_citation_xml = bibtex_citation_xml.replace('="0"', '="False"')


@pytest.mark.sphinx("pseudoxml", testroot="debug_docutils_citation")
def test_debug_docutils_citation(app, warning):
    """A simple test with a single standard docutils citation."""
    app.build()
    assert not warning.getvalue()
    output = (app.outdir / "index.pseudoxml").read_text()
    assert output.split("\n")[1:] == docutils_citation_xml.split("\n")[1:]


@pytest.mark.sphinx("pseudoxml", testroot="debug_bibtex_citation")
def test_debug_bibtex_citation(app, warning):
    """A simple test with a single standard docutils citation."""
    app.build()
    assert not warning.getvalue()
    output = (app.outdir / "index.pseudoxml").read_text()
    assert output.split("\n")[1:] == bibtex_citation_xml.split("\n")[1:]


# see issue 226
@pytest.mark.sphinx("pseudoxml", testroot="debug_bibtex_citation")
def test_rebuild_empty_outdir(make_app, app_params):
    args, kwargs = app_params
    app0 = make_app(freshenv=True, *args, **kwargs)
    app0.build()
    assert not app0._warning.getvalue()
    shutil.rmtree(app0.outdir)
    app1 = make_app(freshenv=False, *args, **kwargs)
    app1.build()
    assert "could not find bibtex key" not in app1._warning.getvalue()


@pytest.mark.sphinx("pseudoxml", testroot="debug_minimal_example")
def test_debug_minimal_example(app, warning) -> None:
    app.build()
    assert not warning.getvalue()
    output = (app.outdir / "index.pseudoxml").read_text()
    docutils_0_22 = docutils.__version_info__ >= (0, 22)
    assert [line for line in output.split("\n")][1:] == [
        "    <paragraph>",
        "        See ",
        '        <inline ids="id1">',
        "            Nelson [",
        f'            <reference internal="{1 if docutils_0_22 else True}" refid="id4" '
        'reftitle="Edward Nelson. Radically Elementary Probability Theory. '
        'Princeton University Press, 1987.">',
        "                Nel87",
        "            ]",
        "         for an introduction to non-standard analysis.",
        "        Non-standard analysis is fun ",
        '        <inline ids="id2">',
        "            [",
        f'            <reference internal="{1 if docutils_0_22 else True}" refid="id4" '
        'reftitle="Edward Nelson. Radically Elementary Probability Theory. '
        'Princeton University Press, 1987.">',
        "                Nel87",
        "            ]",
        "        .",
        '    <container ids="id3">',
        '        <citation backrefs="id1 id2" docname="index" ids="id4">',
        f'            <label support_smartquotes="{0 if docutils_0_22 else False}">',
        "                Nel87",
        "            <paragraph>",
        "                Edward Nelson.",
        "                 ",
        "                <emphasis>",
        "                    Radically Elementary Probability Theory",
        "                .",
        "                 ",
        "                Princeton University Press, 1987.",
        "",
    ]