File: test_base_add_content_directive.py

package info (click to toggle)
python-globus-sdk 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 35,227; sh: 44; makefile: 35
file content (49 lines) | stat: -rw-r--r-- 1,415 bytes parent folder | download | duplicates (2)
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
import textwrap


def test_addcontent_generating_text(
    sphinxext, docutils_runner, register_temporary_directive
):

    class MyDirective(sphinxext.directives.AddContentDirective):
        def gen_rst(self):
            yield "a"
            yield "b"

    register_temporary_directive("mydirective", MyDirective)

    etree = docutils_runner.to_etree(".. mydirective::")

    assert etree.tag == "document"
    assert etree.get("source") == "TEST"
    paragraph_element = etree.find("paragraph")
    assert paragraph_element is not None
    assert paragraph_element.text == textwrap.dedent(
        """\
        a
        b"""
    )


def test_addcontent_generating_warning(
    sphinxext, docutils_runner, register_temporary_directive
):

    class MyDirective(sphinxext.directives.AddContentDirective):
        def gen_rst(self):
            yield ".. note::"
            yield ""
            yield "     Some note content here."
            yield "     Multiline."

    register_temporary_directive("mydirective", MyDirective)

    etree = docutils_runner.to_etree(".. mydirective::")

    assert etree.tag == "document"
    assert etree.get("source") == "TEST"
    note_element = etree.find("note")
    assert note_element is not None
    paragraph_element = note_element.find("paragraph")
    assert paragraph_element is not None
    assert paragraph_element.text == "Some note content here.\nMultiline."