コード例 #1
0
def test_remove_trailing_whitespace():
    description = ET.Element("description")
    sub_element(description, "para", text="Actual description text.")
    sub_element(description,
                "para",
                text="And some more text.",
                tail="   \n   ")
    result = DescriptionParser("lang").parse(description)
    assert result == """Actual description text.
コード例 #2
0
def test_nested_para():
    description = ET.Element("description")
    sub_element(description, "para", text="Outer text.")
    sub_element(description,
                "para",
                text="Inner text.",
                tail="Tail outer text.")
    result = DescriptionParser("lang").parse(description)
    assert result == """Outer text.
コード例 #3
0
def test_computeroutput():
    description = ET.Element("description")
    para = sub_element(description, "para", text="The computer says: ")
    sub_element(para,
                "computeroutput",
                text="I cannot do that, Dave",
                tail="!")

    result = DescriptionParser("lang").parse(description)
    assert result == "The computer says: `I cannot do that, Dave`!"
コード例 #4
0
def test_simplesect_ignore_other_kinds(kind):
    description = ET.Element("description")
    para = sub_element(description, "para", "Some normal text first.")
    simplesect = sub_element(para,
                             "simplesect",
                             kind=kind,
                             tail="More text after the note.")
    sub_element(simplesect, "para", text="Some kind of note.")

    result = DescriptionParser("lang").parse(description)
    assert result == "Some normal text first."
コード例 #5
0
def test_ignore_parameterlist():
    description = ET.Element("description")
    para = sub_element(description, "para")
    parameterlist = sub_element(para,
                                "parameterlist",
                                text="Ignored",
                                tail="Also ignored")
    sub_element(parameterlist, "para", text="Ignored", tail="Ignored as well")

    result = DescriptionParser("lang").parse(description)
    assert result == ""
コード例 #6
0
def test_highlight(nested_elements, nested_result):
    description = ET.Element("description")
    para = sub_element(description, "para", text="I want to ")
    highlight = sub_element(para,
                            "highlight",
                            text="highlight these words",
                            tail=" properly.")
    highlight.extend(nested_elements)

    result = DescriptionParser("lang").parse(description)
    assert result == f"I want to __highlight these words{nested_result}__ properly."
コード例 #7
0
def test_bold(nested_elements, nested_result):
    description = ET.Element("description")
    para = sub_element(description, "para", text="The following is ")
    bold = sub_element(para,
                       "bold",
                       text="very, very, very",
                       tail=" important!")
    bold.extend(nested_elements)

    result = DescriptionParser("lang").parse(description)
    assert result == f"The following is **very, very, very{nested_result}** important!"
コード例 #8
0
def test_ref(nested_elements, nested_result):
    description = ET.Element("description")
    para = sub_element(description, "para", text="See ")
    link = sub_element(para,
                       "ref",
                       text="Class",
                       tail=" for more information.",
                       refid="compound_class")
    link.extend(nested_elements)

    result = DescriptionParser("lang").parse(description)
    assert result == f"See xref:lang-compound_class[Class{nested_result}] for more information."
コード例 #9
0
def test_programlisting():
    description = ET.Element("description")
    para = sub_element(description, "para", text="Example of code:")
    listing = sub_element(para,
                          "programlisting",
                          tail="You know what it does.")
    sub_element(listing, "codeline", text="def main():")
    sub_element(listing, "codeline", text="    print('Hello world!')")
    sub_element(listing, "codeline")

    result = DescriptionParser("lang").parse(description)
    assert result == """Example of code:
コード例 #10
0
def test_unknown_tag(nested_elements, nested_result):
    description = ET.Element("description")
    para = sub_element(description, "para", text="The following is ")
    unknown = sub_element(para,
                          "unknown",
                          text="very, very, very",
                          tail=" important!")
    unknown.extend(nested_elements)

    result = DescriptionParser("lang").parse(description)
    assert result == re.sub(
        "\n ", "\n",
        f"The following is very, very, very{nested_result} important!")
コード例 #11
0
def test_ulink(nested_elements, nested_result):
    description = ET.Element("description")
    para = sub_element(description, "para", text="Follow ")
    link = sub_element(para,
                       "ulink",
                       text="this link",
                       tail=" for more information.",
                       url="https://www.tomtom.com")
    link.extend(nested_elements)

    result = DescriptionParser("lang").parse(description)
    assert (
        result ==
        f"Follow https://www.tomtom.com[this link{nested_result}] for more information."
    )
コード例 #12
0
def test_itemizedlist(nested_elements, nested_result):
    description = ET.Element("description")
    para = sub_element(description, "para", text="This is a list of items:")
    itemized_list = sub_element(para,
                                "itemizedlist",
                                tail="And some text after the list")

    list_item_1 = sub_element(itemized_list, "listitem")
    para_1 = sub_element(list_item_1, "para", text="List item 1")
    para_1.extend(nested_elements)

    list_item_2 = sub_element(itemized_list, "listitem")
    sub_element(list_item_2, "para", text="List item 2")

    result = DescriptionParser("lang").parse(description)
    assert result == re.sub(
        "\n{3,}", "\n\n", f"""This is a list of items:

* List item 1{nested_result}

* List item 2

And some text after the list""")
コード例 #13
0
def test_multiple_para():
    description = ET.Element("description")
    sub_element(description, "para", text="Actual description text.")
    sub_element(description, "para", text="And some more text.")
    result = DescriptionParser("lang").parse(description)
    assert result == """Actual description text.
コード例 #14
0
def test_single_para():
    description = ET.Element("description")
    sub_element(description, "para", text="Actual description text.")
    result = DescriptionParser("lang").parse(description)
    assert result == f"Actual description text."
コード例 #15
0
def test_text_only():
    description = ET.Element("description", text="A text only description")
    result = DescriptionParser("lang").parse(description)
    assert result == ""
コード例 #16
0
def test_remove_single_leading_space():
    description = ET.Element("description")
    sub_element(description, "para", text=" Actual description text.")
    sub_element(description, "para", text=" And some more text.")
    result = DescriptionParser("lang").parse(description)
    assert result == """Actual description text.