コード例 #1
0
def test_selects_the_div_ancestors_of_the_context_node_and_if_the_context_node_is_a_div_element_the_context_node_as_well(
):
    html = """
    <div>
        <div/>
        <notdiv/>
    </div>"""
    soup = make_soup(html)
    assert query_context_node(soup.div.div,
                              'ancestor-or-self::div') == expected_result("""
    <div>
     <div>
     </div>
     <notdiv>
     </notdiv>
    </div>
    <div>
    </div>""")
    assert query_context_node(soup.div.notdiv,
                              'ancestor-or-self::div') == expected_result("""
    <div>
     <div>
     </div>
     <notdiv>
     </notdiv>
    </div>""")
コード例 #2
0
def test_selects_the_fifth_para_child_of_the_context_node_if_that_child_has_a_type_attribute_with_value_warning():
    html_with = """
    <context>
        <para type="warning">para one</para>
        <para type="warning">para two</para>
        <para type="warning">para three</para>
        <para type="warning">para four</para>
        <para type="warning">para five</para>
    </context>"""
    html_without = """
    <context>
        <para type="warning">para one</para>
        <para type="warning">para two</para>
        <para type="warning">para three</para>
        <para type="warning">para four</para>
        <para type="error">para five</para>
    </context>"""

    actual_with = query_context_node(html_with, 'child::para[position()=5][attribute::type="warning"]')
    actual_without = query_context_node(html_without, 'child::para[position()=5][attribute::type="warning"]')

    assert actual_with == expected_result("""
    <para type="warning">
     para five
    </para>""")
    assert actual_without == expected_result('')
コード例 #3
0
def test_selects_the_fifth_para_child_of_the_context_node_if_that_child_has_a_type_attribute_with_value_warning(
):
    html_with = """
    <context>
        <para type="warning">para one</para>
        <para type="warning">para two</para>
        <para type="warning">para three</para>
        <para type="warning">para four</para>
        <para type="warning">para five</para>
    </context>"""
    html_without = """
    <context>
        <para type="warning">para one</para>
        <para type="warning">para two</para>
        <para type="warning">para three</para>
        <para type="warning">para four</para>
        <para type="error">para five</para>
    </context>"""

    actual_with = query_context_node(
        html_with, 'child::para[position()=5][attribute::type="warning"]')
    actual_without = query_context_node(
        html_without, 'child::para[position()=5][attribute::type="warning"]')

    assert actual_with == expected_result("""
    <para type="warning">
     para five
    </para>""")
    assert actual_without == expected_result('')
コード例 #4
0
def test_selects_the_context_node_if_it_is_a_para_element_and_otherwise_selects_nothing():
    is_para = "<para></para>"
    is_not_para = "<notpara></notpara>"
    assert query_context_node(is_para, 'self::para') == expected_result("""
    <para>
    </para>""")
    assert query_context_node(is_not_para, 'self::para') == ''
コード例 #5
0
def test_selects_the_last_chapter_or_appendix_child_of_the_context_node():
    html_with_last_chapter = """
    <context>
        <chapter></chapter>
        <appendix></appendix>
        <chapter>selected</chapter>
    </context>"""
    html_with_last_appendix = """
    <context>
        <appendix></appendix>
        <chapter></chapter>
        <appendix>selected</appendix>
    </context>"""
    actual_last_chapter = query_context_node(html_with_last_chapter,
                                             'child::*[self::chapter or self::appendix][position()=last()]')
    actual_last_appendix = query_context_node(html_with_last_appendix,
                                              'child::*[self::chapter or self::appendix][position()=last()]')
    assert actual_last_chapter == expected_result("""
    <chapter>
     selected
    </chapter>""")
    assert actual_last_appendix == expected_result("""
    <appendix>
     selected
    </appendix>""")
コード例 #6
0
def test_selects_the_last_chapter_or_appendix_child_of_the_context_node():
    html_with_last_chapter = """
    <context>
        <chapter></chapter>
        <appendix></appendix>
        <chapter>selected</chapter>
    </context>"""
    html_with_last_appendix = """
    <context>
        <appendix></appendix>
        <chapter></chapter>
        <appendix>selected</appendix>
    </context>"""
    actual_last_chapter = query_context_node(
        html_with_last_chapter,
        'child::*[self::chapter or self::appendix][position()=last()]')
    actual_last_appendix = query_context_node(
        html_with_last_appendix,
        'child::*[self::chapter or self::appendix][position()=last()]')
    assert actual_last_chapter == expected_result("""
    <chapter>
     selected
    </chapter>""")
    assert actual_last_appendix == expected_result("""
    <appendix>
     selected
    </appendix>""")
コード例 #7
0
def test_selects_the_para_element_descendants_of_the_context_node_and_if_the_context_node_is_a_para_element_the_context_node_as_well():
    context_is_para = """
    <para>
        <para>foo</para>
        <para>bar</para>
    </para>"""
    context_is_not_para = """
    <notpara>
        <para>foo</para>
        <para>bar</para>
    </notpara>"""
    assert query_context_node(context_is_para, 'descendant-or-self::para') == expected_result("""
    <para>
     <para>
      foo
     </para>
     <para>
      bar
     </para>
    </para>
    <para>
     foo
    </para>
    <para>
     bar
    </para>""")
    assert query_context_node(context_is_not_para, 'descendant-or-self::para') == expected_result("""
    <para>
     foo
    </para>
    <para>
     bar
    </para>""")
コード例 #8
0
def test_selects_the_context_node_if_it_is_a_para_element_and_otherwise_selects_nothing(
):
    is_para = "<para></para>"
    is_not_para = "<notpara></notpara>"
    assert query_context_node(is_para, 'self::para') == expected_result("""
    <para>
    </para>""")
    assert query_context_node(is_not_para, 'self::para') == ''
コード例 #9
0
def test_selects_the_fifth_para_child_of_the_context_node_if_that_child_has_a_type_attribute_with_value_warning():
    html = """
    <context>
        <para>not selected</para>
        <para>not selected</para>
        <para>not selected</para>
        <para>not selected</para>
        <para type="error">selected</para>
    </context>"""
    assert query_context_node(html, 'para[5][@type="warning"]') == expected_result("")
    assert query_context_node(html.replace('error', 'warning'), 'para[5][@type="warning"]') == expected_result("""
    <para type="warning">
     selected
    </para>""")
コード例 #10
0
def test_selects_the_document_root_which_is_always_the_parent_of_the_document_element(
):
    html = """
    <!-- comment -->
    <root-tag>
    </root-tag>"""
    assert query_context_node(html, '/') == expected_result(html)
コード例 #11
0
def test_selects_the_lang_attribute_of_the_parent_of_the_context_node():
    html = """
    <root lang="English">
        <context></context>
    </root>"""
    soup = make_soup(html)
    assert query_context_node(soup.root.context, '../@lang') == expected_result('lang="English"')
コード例 #12
0
def test_selects_the_para_element_descendants_of_the_context_node():
    html = """
    <para>
        <context>
            <para>selected</para>
            <not-para>not selected</not-para>
            <para>
                <para>also selected</para>
            </para>
        </context>
    </para>"""
    soup = make_soup(html)
    assert query_context_node(soup.para.context,
                              './/para') == expected_result("""
    <para>
     selected
    </para>
    <para>
     <para>
      also selected
     </para>
    </para>
    <para>
     also selected
    </para>""")
コード例 #13
0
def test_selects_the_chapter_children_of_the_context_node_that_have_one_or_more_title_children_with_string_value_equal_to_Introduction(
):
    html = """
    <context>
        <chapter>
            <title>Introduction</title>
        </chapter>
        <chapter>not selected</chapter>
        <chapter>
            <title>Author's Note</title>
        </chapter>
        <chapter>
            <title>Introduction</title>
            <content>Hello, I'm chapter.</content>
        </chapter>
    </context>"""
    assert query_context_node(
        html, 'chapter[title="Introduction"]') == expected_result("""
    <chapter>
     <title>
      Introduction
     </title>
    </chapter>
    <chapter>
     <title>
      Introduction
     </title>
     <content>
      Hello, I'm chapter.
     </content>
    </chapter>""")
コード例 #14
0
def test_selects_all_the_item_elements_in_the_same_document_as_the_context_node_that_have_an_olist_parent(
):
    html = """
    <root>
        <olist>no items</olist>
        <item>not selected</item>
        <context></context>
        <olist>
            <item>first</item>
        </olist>
        <item>
            <olist>
                <item>second</item>
            <olist>
        </item>
    </root>"""
    soup = make_soup(html)
    assert query_context_node(soup.root.context,
                              '//olist/item') == expected_result("""
    <item>
     first
    </item>
    <item>
     second
    </item>""")
コード例 #15
0
def test_selects_the_chapter_children_of_the_context_node_that_have_one_or_more_title_children(
):
    html = """
    <context>
        <chapter>
            <title>selected</title>
        </chapter>
        <chapter>
            <not-title></not-title>
        </chapter>
        <chapter>
            <title>also selected</title>
        </chapter>
    </context>"""
    assert query_context_node(html, 'chapter[title]') == expected_result("""
    <chapter>
     <title>
      selected
     </title>
    </chapter>
    <chapter>
     <title>
      also selected
     </title>
    </chapter>""")
コード例 #16
0
def test_selects_the_chapter_children_of_the_context_node_that_have_one_or_more_title_children_with_string_value_equal_to_Introduction():
    html = """
    <context>
        <chapter>
            <title>Introduction</title>
        </chapter>
        <chapter>not selected</chapter>
        <chapter>
            <title>Author's Note</title>
        </chapter>
        <chapter>
            <title>Introduction</title>
            <content>Hello, I'm chapter.</content>
        </chapter>
    </context>"""
    assert query_context_node(html, 'chapter[title="Introduction"]') == expected_result("""
    <chapter>
     <title>
      Introduction
     </title>
    </chapter>
    <chapter>
     <title>
      Introduction
     </title>
     <content>
      Hello, I'm chapter.
     </content>
    </chapter>""")
コード例 #17
0
def test_selects_the_lang_attribute_of_the_parent_of_the_context_node():
    html = """
    <root lang="English">
        <context></context>
    </root>"""
    soup = make_soup(html)
    assert query_context_node(soup.root.context,
                              '../@lang') == expected_result('lang="English"')
コード例 #18
0
def test_selects_the_fifth_para_child_of_the_context_node_if_that_child_has_a_type_attribute_with_value_warning(
):
    html = """
    <context>
        <para>not selected</para>
        <para>not selected</para>
        <para>not selected</para>
        <para>not selected</para>
        <para type="error">selected</para>
    </context>"""
    assert query_context_node(
        html, 'para[5][@type="warning"]') == expected_result("")
    assert query_context_node(html.replace(
        'error', 'warning'), 'para[5][@type="warning"]') == expected_result("""
    <para type="warning">
     selected
    </para>""")
コード例 #19
0
def test_selects_the_context_node():
    html = """
    <context>
        selected
    </context>"""
    assert query_context_node(html, '.') == expected_result("""
    <context>
     selected
    </context>""")
コード例 #20
0
def test_selects_the_context_node():
    html = """
    <context>
        selected
    </context>"""
    assert query_context_node(html, '.') == expected_result("""
    <context>
     selected
    </context>""")
コード例 #21
0
def test_selects_the_first_para_child_of_the_context_node():
    html = """
    <context>
        <para>selected</para>
        <para>not selected</para>
    </context>"""
    assert query_context_node(html, 'para[1]') == expected_result("""
    <para>
     selected
    </para>""")
コード例 #22
0
def test_selects_all_div_ancestors_of_the_context_node():
    html = """
    <div>
        <notdiv/>
    </div>"""
    assert query_context_node(make_soup(html).div.notdiv, 'ancestor::div') == expected_result("""
    <div>
     <notdiv>
     </notdiv>
    </div>""")
コード例 #23
0
def test_selects_the_first_para_child_of_the_context_node():
    html = """
    <context>
        <para>selected</para>
        <para>not selected</para>
    </context>"""
    assert query_context_node(html, 'para[1]') == expected_result("""
    <para>
     selected
    </para>""")
コード例 #24
0
def test_selects_the_last_para_child_of_the_context_node():
    html = """
    <context>
        <para>not selected</para>
        <para>selected</para>
    </context>"""
    assert query_context_node(html, 'child::para[position()=last()]') == expected_result("""
    <para>
     selected
    </para>""")
コード例 #25
0
def test_selects_all_text_node_children_of_the_context_node():
    html = """
    <context>
        first
        <element>second</element>
        third
    </context>"""
    actual = query_context_node(html, 'text()')
    assert 'first' in actual
    assert 'second' not in actual
    assert 'third' in actual
コード例 #26
0
def test_selects_the_parent_of_the_context_node():
    html = """
    <root>
        <context></context>
    </root>"""
    soup = make_soup(html)
    assert query_context_node(html, '..') == expected_result("""
    <root>
     <context>
     </context>
    </root>""")
コード例 #27
0
def test_selects_all_text_node_children_of_the_context_node():
    html = """
    <context>
        first
        <element>second</element>
        third
    </context>"""
    actual = query_context_node(html, 'text()')
    assert 'first' in actual
    assert 'second' not in actual
    assert 'third' in actual
コード例 #28
0
def test_selects_all_the_para_elements_in_the_same_document_as_the_context_node():
    html = """
    <root>
        <notpara/>
        <para>selected</para>
    </root>"""
    soup = make_soup(html)
    assert query_context_node(soup.root.notpara, '/descendant::para') == expected_result("""
    <para>
     selected
    </para>""")
コード例 #29
0
def test_selects_all_the_children_of_the_context_node_whatever_their_node_type():
    html = """
    <context>selected text<selected-element>
        </selected-element>
        <!-- selected comment -->
    </context>"""
    assert query_context_node(html, 'child::node()') == expected_result("""
    selected text
    <selected-element>
    </selected-element>
    <!-- selected comment -->""")
コード例 #30
0
def test_selects_all_div_ancestors_of_the_context_node():
    html = """
    <div>
        <notdiv/>
    </div>"""
    assert query_context_node(make_soup(html).div.notdiv,
                              'ancestor::div') == expected_result("""
    <div>
     <notdiv>
     </notdiv>
    </div>""")
コード例 #31
0
def test_selects_the_chapter_children_of_the_context_node_that_have_one_or_more_title_children():
    html = """
    <context>
        <chapter>not selected</chapter>
        <chapter><title></title></chapter>
    </context>"""
    assert query_context_node(html, 'child::chapter[child::title]') == expected_result("""
    <chapter>
     <title>
     </title>
    </chapter>""")
コード例 #32
0
def test_selects_the_last_para_child_of_the_context_node():
    html = """
    <context>
        <para>not selected</para>
        <para>selected</para>
    </context>"""
    assert query_context_node(
        html, 'child::para[position()=last()]') == expected_result("""
    <para>
     selected
    </para>""")
コード例 #33
0
def test_selects_the_parent_of_the_context_node():
    html = """
    <root>
        <context></context>
    </root>"""
    soup = make_soup(html)
    assert query_context_node(html, '..') == expected_result("""
    <root>
     <context>
     </context>
    </root>""")
コード例 #34
0
def test_selects_the_previous_chapter_sibling_of_the_context_node():
    html = """
    <root>
        <chapter>not selected</chapter>
        <chapter>selected</chapter>
        <context/>
    </root>"""
    soup = make_soup(html)
    assert query_context_node(soup.root.context, 'preceding-sibling::chapter[position()=1]') == expected_result("""
    <chapter>
     selected
    </chapter>""")
コード例 #35
0
def test_selects_all_the_children_of_the_context_node_whatever_their_node_type(
):
    html = """
    <context>selected text<selected-element>
        </selected-element>
        <!-- selected comment -->
    </context>"""
    assert query_context_node(html, 'child::node()') == expected_result("""
    selected text
    <selected-element>
    </selected-element>
    <!-- selected comment -->""")
コード例 #36
0
def test_selects_the_chapter_and_appendix_children_of_the_context_node():
    html = """
    <context>
        <title>not selected</title>
        <chapter></chapter>
        <appendix></appendix>
    </context>"""
    assert query_context_node(html, 'child::*[self::chapter or self::appendix]') == expected_result("""
    <chapter>
    </chapter>
    <appendix>
    </appendix>""")
コード例 #37
0
def test_selects_all_the_para_elements_in_the_same_document_as_the_context_node(
):
    html = """
    <root>
        <notpara/>
        <para>selected</para>
    </root>"""
    soup = make_soup(html)
    assert query_context_node(soup.root.notpara,
                              '/descendant::para') == expected_result("""
    <para>
     selected
    </para>""")
コード例 #38
0
def test_selects_the_para_element_children_of_the_context_node():
    html = """
    <context>
        <para>selected</para>
        <not-para>not selected</not-para>
        <para>also selected</para>
    </context>"""
    assert query_context_node(html, 'para') == expected_result("""
    <para>
     selected
    </para>
    <para>
     also selected
    </para>""")
コード例 #39
0
def test_selects_the_para_element_descendants_of_the_context_node():
    html = """
    <context>
        <para>
            <para/>
        </para>
    </context>"""
    assert query_context_node(html, 'descendant::para') == expected_result("""
    <para>
     <para>
     </para>
    </para>
    <para>
    </para>""")
コード例 #40
0
def test_selects_the_chapter_and_appendix_children_of_the_context_node():
    html = """
    <context>
        <title>not selected</title>
        <chapter></chapter>
        <appendix></appendix>
    </context>"""
    assert query_context_node(
        html,
        'child::*[self::chapter or self::appendix]') == expected_result("""
    <chapter>
    </chapter>
    <appendix>
    </appendix>""")
コード例 #41
0
def test_selects_the_previous_chapter_sibling_of_the_context_node():
    html = """
    <root>
        <chapter>not selected</chapter>
        <chapter>selected</chapter>
        <context/>
    </root>"""
    soup = make_soup(html)
    assert query_context_node(
        soup.root.context,
        'preceding-sibling::chapter[position()=1]') == expected_result("""
    <chapter>
     selected
    </chapter>""")
コード例 #42
0
def test_selects_the_para_element_children_of_the_context_node():
    html = """
    <context>
        <para>selected</para>
        <not-para>not selected</not-para>
        <para>also selected</para>
    </context>"""
    assert query_context_node(html, 'para') == expected_result("""
    <para>
     selected
    </para>
    <para>
     also selected
    </para>""")
コード例 #43
0
def test_selects_the_fifth_para_child_of_the_context_node_that_has_a_type_attribute_with_value_warning():
    html = """
    <context>
        <para type="warning">warning one</para>
        <para type="error">error type</para>
        <para type="warning">warning two</para>
        <para type="warning">warning three</para>
        <para type="warning">warning four</para>
        <para type="warning">warning five</para>
    </context>"""
    assert query_context_node(html, "child::para[attribute::type='warning'][position()=5]") == expected_result("""
    <para type="warning">
     warning five
    </para>""")
コード例 #44
0
def test_selects_all_the_item_elements_that_have_an_olist_parent_and_that_are_in_the_same_document_as_the_context_node():
    html = """
    <root>
        <notolist/>
        <olist>
            <notitem>not selected</notitem>
            <item>selected</item>
        <olist>
    </root>"""
    soup = make_soup(html)
    assert query_context_node(soup.root.notolist, '/descendant::olist/child::item') == expected_result("""
    <item>
     selected
    </item>""")
コード例 #45
0
def test_selects_the_div_ancestors_of_the_context_node_and_if_the_context_node_is_a_div_element_the_context_node_as_well():
    html = """
    <div>
        <div/>
        <notdiv/>
    </div>"""
    soup = make_soup(html)
    assert query_context_node(soup.div.div, 'ancestor-or-self::div') == expected_result("""
    <div>
     <div>
     </div>
     <notdiv>
     </notdiv>
    </div>
    <div>
    </div>""")
    assert query_context_node(soup.div.notdiv, 'ancestor-or-self::div') == expected_result("""
    <div>
     <div>
     </div>
     <notdiv>
     </notdiv>
    </div>""")
コード例 #46
0
def test_selects_all_the_para_children_of_the_context_node_other_than_the_first_para_child_of_the_context_node():
    html = """
    <context>
        <para>not selected</para>
        <para>selected</para>
        <para>also selected</para>
    </context>"""
    assert query_context_node(html, 'child::para[position()>1]') == expected_result("""
    <para>
     selected
    </para>
    <para>
     also selected
    </para>""")
コード例 #47
0
def test_selects_all_the_employee_children_of_the_context_node_that_have_both_a_secretary_attribute_and_an_assistant_attribute():
    html = """
    <context>
        <employee secretary="not selected"></employee>
        <employee assistant="" secretary="">selected</employee>
        <employee assistant="not selected"></employee>
        <employee secretary="also" assistant="selected"></employee>
    </context>"""
    assert query_context_node(html, 'employee[@secretary and @assistant]') == expected_result("""
    <employee assistant="" secretary="">
     selected
    </employee>
    <employee assistant="selected" secretary="also">
    </employee>""")
コード例 #48
0
def test_selects_the_para_element_descendants_of_the_context_node():
    html = """
    <context>
        <para>
            <para/>
        </para>
    </context>"""
    assert query_context_node(html, 'descendant::para') == expected_result("""
    <para>
     <para>
     </para>
    </para>
    <para>
    </para>""")
コード例 #49
0
def test_selects_all_element_children_of_the_context_node():
    html = """
    <context>
        <!-- comment -->
        <element>selected</element>
        non-selected text
        <para>also selected</para>
    </context>"""
    assert query_context_node(html, '*') == expected_result("""
    <element>
     selected
    </element>
    <para>
     also selected
    </para>""")
コード例 #50
0
def test_selects_all_para_children_of_the_context_node_that_have_a_type_attribute_with_value_warning():
    html = """
    <context>
        <para>not selected</para>
        <para type="warning">selected</para>
        <para type="error">not selected</para>
        <para type="warning">also selected</para>
    </context>"""
    assert query_context_node(html, 'para[@type="warning"]') == expected_result("""
    <para type="warning">
     selected
    </para>
    <para type="warning">
     also selected
    </para>""")
コード例 #51
0
def test_selects_all_element_children_of_the_context_node():
    html = """
    <context>
        <!-- comment -->
        <element>selected</element>
        non-selected text
        <para>also selected</para>
    </context>"""
    assert query_context_node(html, '*') == expected_result("""
    <element>
     selected
    </element>
    <para>
     also selected
    </para>""")
コード例 #52
0
def test_selects_all_para_children_of_the_context_node_that_have_a_type_attribute_with_value_warning():
    html = """
    <context>
        <para>no type</para>
        <para type="warning">warning one</para>
        <para type="error">error type</para>
        <para type="warning">warning two</para>
    </context>"""
    assert query_context_node(html, 'child::para[attribute::type="warning"]') == expected_result("""
    <para type="warning">
     warning one
    </para>
    <para type="warning">
     warning two
    </para>""")
コード例 #53
0
def test_selects_the_para_element_descendants_of_the_context_node_and_if_the_context_node_is_a_para_element_the_context_node_as_well(
):
    context_is_para = """
    <para>
        <para>foo</para>
        <para>bar</para>
    </para>"""
    context_is_not_para = """
    <notpara>
        <para>foo</para>
        <para>bar</para>
    </notpara>"""
    assert query_context_node(
        context_is_para, 'descendant-or-self::para') == expected_result("""
    <para>
     <para>
      foo
     </para>
     <para>
      bar
     </para>
    </para>
    <para>
     foo
    </para>
    <para>
     bar
    </para>""")
    assert query_context_node(
        context_is_not_para, 'descendant-or-self::para') == expected_result("""
    <para>
     foo
    </para>
    <para>
     bar
    </para>""")
コード例 #54
0
def test_selects_all_the_para_children_of_the_context_node_other_than_the_first_para_child_of_the_context_node(
):
    html = """
    <context>
        <para>not selected</para>
        <para>selected</para>
        <para>also selected</para>
    </context>"""
    assert query_context_node(
        html, 'child::para[position()>1]') == expected_result("""
    <para>
     selected
    </para>
    <para>
     also selected
    </para>""")
コード例 #55
0
def test_selects_all_para_grandchildren_of_the_context_node():
    html = """
    <context>
        <para>
            not selected
            <para>selected</para>
            <para>also selected</para>
        </para>
    </context>"""
    assert query_context_node(html, '*/para') == expected_result("""
    <para>
     selected
    </para>
    <para>
     also selected
    </para>""")
コード例 #56
0
def test_selects_all_the_employee_children_of_the_context_node_that_have_both_a_secretary_attribute_and_an_assistant_attribute(
):
    html = """
    <context>
        <employee secretary="not selected"></employee>
        <employee assistant="" secretary="">selected</employee>
        <employee assistant="not selected"></employee>
        <employee secretary="also" assistant="selected"></employee>
    </context>"""
    assert query_context_node(
        html, 'employee[@secretary and @assistant]') == expected_result("""
    <employee assistant="" secretary="">
     selected
    </employee>
    <employee assistant="selected" secretary="also">
    </employee>""")
コード例 #57
0
def test_selects_all_para_grandchildren_of_the_context_node():
    html = """
    <context>
        <para>
            not selected
            <para>selected</para>
            <para>also selected</para>
        </para>
    </context>"""
    assert query_context_node(html, '*/para') == expected_result("""
    <para>
     selected
    </para>
    <para>
     also selected
    </para>""")
コード例 #58
0
def test_selects_the_second_section_of_the_fifth_chapter_of_the_doc():
    html = """
    <doc>
        <chapter>one</chapter>
        <chapter>two</chapter>
        <chapter>three</chapter>
        <chapter>four</chapter>
        <chapter>
            <section>five point one</section>
            <section>five point two</section>
        </chapter>
    </doc>"""
    assert query_context_node(html, '/doc/chapter[5]/section[2]') == expected_result("""
    <section>
     five point two
    </section>""")
コード例 #59
0
def test_selects_the_second_section_of_the_fifth_chapter_of_the_doc():
    html = """
    <doc>
        <chapter>one</chapter>
        <chapter>two</chapter>
        <chapter>three</chapter>
        <chapter>four</chapter>
        <chapter>
            <section>five point one</section>
            <section>five point two</section>
        </chapter>
    </doc>"""
    assert query_context_node(
        html, '/doc/chapter[5]/section[2]') == expected_result("""
    <section>
     five point two
    </section>""")
コード例 #60
0
def test_selects_all_para_children_of_the_context_node_that_have_a_type_attribute_with_value_warning(
):
    html = """
    <context>
        <para>not selected</para>
        <para type="warning">selected</para>
        <para type="error">not selected</para>
        <para type="warning">also selected</para>
    </context>"""
    assert query_context_node(html,
                              'para[@type="warning"]') == expected_result("""
    <para type="warning">
     selected
    </para>
    <para type="warning">
     also selected
    </para>""")