• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python hquery_test_util.query_html_doc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中test.hquery.hquery_test_util.query_html_doc函数的典型用法代码示例。如果您正苦于以下问题:Python query_html_doc函数的具体用法?Python query_html_doc怎么用?Python query_html_doc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了query_html_doc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_string_value_of_a_sequence_is_concatenation_of_all_items_unlike_node_set

def test_string_value_of_a_sequence_is_concatenation_of_all_items_unlike_node_set():
    html_body = """
    <p>one</p>
    <p>two</p>"""

    assert query_html_doc(html_body, 'let $_ := //p/text() return string($_)') == 'one'
    assert query_html_doc(html_body, 'let $_ := ("one", "two") return string($_)') == 'onetwo'
开发者ID:rbwinslow,项目名称:hq,代码行数:7,代码来源:test_sequences_and_ranges.py


示例2: test_comma_as_sequence_cat_operator_does_not_bind_at_end_of_return_clause

def test_comma_as_sequence_cat_operator_does_not_bind_at_end_of_return_clause():
    assert query_html_doc('', 'for $x in (1 to 2) return $x, "!"') == expected_result("""
    1
    2
    !""")
    assert query_html_doc('', 'sum(for $x in //span return $x, "zero")') == 'zero'
    assert query_html_doc('', 'sum(//span -> $_, "zero")') == 'zero'
开发者ID:rbwinslow,项目名称:hq,代码行数:7,代码来源:test_flwor.py


示例3: test_matches_function_performs_regex_matching_as_per_xpath_30_functions_spec

def test_matches_function_performs_regex_matching_as_per_xpath_30_functions_spec():
    html_body = """
    <p>moe</p>
    <p>larry</p>
    <p>curly</p>"""

    assert query_html_doc(html_body, '//p[matches(text(), "^l[ary]+")]/text()') == expected_result('larry')
    assert query_html_doc(html_body, '//p[matches(text(), ".URL.", "i")]/text()') == expected_result('curly')
开发者ID:rbwinslow,项目名称:hq,代码行数:8,代码来源:test_extended_functions.py


示例4: test_class_function_returns_true_when_element_has_name_in_class_attribute

def test_class_function_returns_true_when_element_has_name_in_class_attribute():
    html_body = """
    <p class="not selected">not selected</p>
    <p class="foo bar">expected</p>"""

    assert query_html_doc(html_body, 'class(//p[1], "foo")') == 'false'
    assert query_html_doc(html_body, 'class(//p[2], "foo")') == 'true'
    assert query_html_doc(html_body, '//p[class("bar")]/text()') == 'expected'
开发者ID:rbwinslow,项目名称:hq,代码行数:8,代码来源:test_extended_functions.py


示例5: test_text_content_normalization_is_applied_to_attribute_values_in_hash_constructor

def test_text_content_normalization_is_applied_to_attribute_values_in_hash_constructor():
    preserved = u'\u00a0non\u00a0breaking\u00a0spaces '
    html_body = u'<p>{0}</p>'.format(preserved)

    actual = json.loads(query_html_doc(html_body, 'hash {para: //p/text()}'))
    assert actual['para'] == 'non breaking spaces'

    actual = json.loads(query_html_doc(html_body, 'hash {para: //p/text()}', preserve_space=True))
    assert actual['para'] == preserved
开发者ID:rbwinslow,项目名称:hq,代码行数:9,代码来源:test_computed_json_construction.py


示例6: test_escapes_work_in_string_literals

def test_escapes_work_in_string_literals():
    assert query_html_doc('', '"foo&#10;bar"') == expected_result("""
    foo
    bar""")
    assert query_html_doc('', "'foo&#10;bar'") == expected_result("""
    foo
    bar""")
    assert query_html_doc('', '`foo&#10;bar`') == expected_result("""
    foo
    bar""")
开发者ID:rbwinslow,项目名称:hq,代码行数:10,代码来源:test_strings.py


示例7: test_tokenize_function_breaks_up_strings_as_per_xpath_30_functions_spec

def test_tokenize_function_breaks_up_strings_as_per_xpath_30_functions_spec():
    assert query_html_doc('', 'tokenize("Moe:Larry:..Curly", ":\.*")') == expected_result("""
    Moe
    Larry
    Curly""")
    assert query_html_doc('', 'tokenize("HaxtaXpatience", "x", "i")') == expected_result("""
    Ha
    ta
    patience""")
    assert query_html_doc('', 'count(tokenize("haxtaxstax", "x"))') == '4'
开发者ID:rbwinslow,项目名称:hq,代码行数:10,代码来源:test_extended_functions.py


示例8: test_element_constructor_accepts_numbers_and_booleans

def test_element_constructor_accepts_numbers_and_booleans():
    assert query_html_doc('', 'element test { 98.6 }') == expected_result("""
    <test>
     98.6
    </test>""")

    assert query_html_doc('', 'element test { false() }') == expected_result("""
    <test>
     false
    </test>""")
开发者ID:rbwinslow,项目名称:hq,代码行数:10,代码来源:test_computed_html_construction.py


示例9: test_interpretation_of_div_and_mod_and_other_arithmetic_operators_as_operators_vs_node_tests

def test_interpretation_of_div_and_mod_and_other_arithmetic_operators_as_operators_vs_node_tests():
    div = """
    <div>
    </div>"""
    mod = """
    <mod>
    </mod>"""

    assert query_html_doc(div, 'div', wrap_body=False) == expected_result(div)
    assert query_html_doc(mod, '/ mod', wrap_body=False) == expected_result(mod)
    assert query_html_doc(div, 'boolean(div)', wrap_body=False) == 'true'
    assert query_html_doc(mod, 'boolean(div)', wrap_body=False) == 'false'

    div_with_text = '<div>bar</div>'
    query_with_div_after_comma = 'starts-with(concat("foo ", div), "foo ba")'
    assert query_html_doc(div_with_text, query_with_div_after_comma, wrap_body=False) == 'true'

    assert query_html_doc(div, 'number("84")div2') == '42'
    assert query_html_doc(div, 'let $x := 4 return $x div 2') == '2'

    rect = '<rect id="foo" height="2" width="10"/>'
    assert query_html_doc(rect, 'let $r := //rect return $r/@height * $r/@width') == '20'

    num_in_text = """
    <span>not selected</span>
    <span id="foo">42</span>"""
    assert query_html_doc(num_in_text, '//span[@id="foo"] mod 10') == '2'
开发者ID:rbwinslow,项目名称:hq,代码行数:27,代码来源:test_arithmetic_operators.py


示例10: test_if_then_else_works_with_node_sets

def test_if_then_else_works_with_node_sets():
    html_body = """
    <p>eekaboo</p>"""
    assert query_html_doc(html_body, 'if (//p) then //p else 1 to 3') == expected_result("""
    <p>
     eekaboo
    </p>""")
    assert query_html_doc(html_body, 'if (//div) then //p else 1 to 3') == expected_result("""
    1
    2
    3""")
开发者ID:rbwinslow,项目名称:hq,代码行数:11,代码来源:test_if_then_else.py


示例11: test_hash_constructor_turns_tags_into_tag_name_keys_with_tag_content_values

def test_hash_constructor_turns_tags_into_tag_name_keys_with_tag_content_values():
    html_body = """
    <p>foo</p>
    <div>bar</div>"""
    actual = json.loads(query_html_doc(html_body, 'hash { /html/body/* }'))
    assert actual['p'] == 'foo'
    assert actual['div'] == 'bar'
开发者ID:rbwinslow,项目名称:hq,代码行数:7,代码来源:test_computed_json_construction.py


示例12: test_non_string_types_survive_conversion_to_json

def test_non_string_types_survive_conversion_to_json():
    actual = json.loads(query_html_doc('', 'hash { integer: 1, float: 1.1, boolean: true() }'))

    assert all(name in actual for name in ('integer', 'float', 'boolean'))
    assert isinstance(actual['integer'], int)
    assert isinstance(actual['float'], float)
    assert isinstance(actual['boolean'], bool)
开发者ID:rbwinslow,项目名称:hq,代码行数:7,代码来源:test_computed_json_construction.py


示例13: test_hash_keys_can_be_used_to_define_attributes_in_a_constructed_hash

def test_hash_keys_can_be_used_to_define_attributes_in_a_constructed_hash():
    actual = json.loads(query_html_doc('', 'hash {foo: "bar", moe: "larry"}'))

    assert 'foo' in actual
    assert actual['foo'] == 'bar'
    assert 'moe' in actual
    assert actual['moe'] == 'larry'
开发者ID:rbwinslow,项目名称:hq,代码行数:7,代码来源:test_computed_json_construction.py


示例14: test_abbreviated_context_node_works_in_predicate

def test_abbreviated_context_node_works_in_predicate():
    html_body = """
    <div>
        <p>one</p>
    </div>
    <p>two</p>
    <div>
        three
    </div>
    <div>
        <p>four</p>
    </div>
    """
    actual = query_html_doc(html_body, '/html/body/node()[./p]')
    assert actual == expected_result("""
    <div>
     <p>
      one
     </p>
    </div>
    <div>
     <p>
      four
     </p>
    </div>""")
开发者ID:rbwinslow,项目名称:hq,代码行数:25,代码来源:test_location_paths.py


示例15: test_double_slash_works_within_path

def test_double_slash_works_within_path():
    html_body = """
    <section>
        <p>moe</p>
        <div>
            <div>
                <p>larry</p>
            </div>
            <p>curly</p>
        </div>
    </section>
    <p>joe besser</p>
    <section>
        <p>shemp</p>
    </section>"""
    assert query_html_doc(html_body, '//section//p') == expected_result("""
    <p>
     moe
    </p>
    <p>
     larry
    </p>
    <p>
     curly
    </p>
    <p>
     shemp
    </p>""")
开发者ID:rbwinslow,项目名称:hq,代码行数:28,代码来源:test_location_paths.py


示例16: query_html_doc

def test_element_constructor_accepts_attributes_from_original_document_including_multi_values_like_classes():
    html_body = """
    <p class="one two" three="four">
        contents
    </p>"""

    assert query_html_doc(html_body, 'element test { //p/@* }') == expected_result("""
    <test class="one two" three="four">
    </test>""")

    assert query_html_doc(html_body, 'element test { //p/@three, //p }') == expected_result("""
    <test three="four">
     <p class="one two" three="four">
      contents
     </p>
    </test>""")
开发者ID:rbwinslow,项目名称:hq,代码行数:16,代码来源:test_computed_html_construction.py


示例17: test_predicate_can_be_applied_to_variable_containing_node_set

def test_predicate_can_be_applied_to_variable_containing_node_set():
    html_body = """
    <p>not selected</p>
    <p id="foo">selected</p>"""
    assert query_html_doc(html_body, 'let $x := //p return $x[@id="foo"]') == expected_result("""
    <p id="foo">
     selected
    </p>""")
开发者ID:rbwinslow,项目名称:hq,代码行数:8,代码来源:test_location_paths.py


示例18: test_even_and_odd_functions_select_the_appropriate_elements_based_on_position

def test_even_and_odd_functions_select_the_appropriate_elements_based_on_position():
    html_body = """
    <p>You</p>
    <p>I</p>
    <p>are</p>
    <p>am</p>
    <p>odd.</p>
    <p>even.</p>"""

    assert query_html_doc(html_body, '//p[even()]/text()') == expected_result("""
    I
    am
    even.""")
    assert query_html_doc(html_body, '//p[odd()]/text()') == expected_result("""
    You
    are
    odd.""")
开发者ID:rbwinslow,项目名称:hq,代码行数:17,代码来源:test_extended_functions.py


示例19: test_matches_function_supports_a_subset_of_xpath_30_flag_values

def test_matches_function_supports_a_subset_of_xpath_30_flag_values():
    html_body = """
    <p>first</p>
    <p>second one</p>
    <p>
        multiple
        lines
        of
        text
    </p>"""
    multiline_pattern = r'.+multiple.+text.+'

    assert query_html_doc(html_body, r'//p[matches(text(), "\w+RST", "i")]/text()') == expected_result('first')
    assert query_html_doc(html_body, r'//p[matches(text(), ".+lines.+text")]', preserve_space=True) == ''
    assert re.match(
        multiline_pattern,
        query_html_doc(html_body, r'//p[matches(text(), ".+lines.+text", "s")]', preserve_space=True),
        re.S
    )
    assert query_html_doc(html_body, r'//p[matches(text(), "^ *lines$")]', preserve_space=True) == ''
    assert re.match(
        multiline_pattern,
        query_html_doc(html_body, r'//p[matches(text(), "^\s*lines$", "m")]', preserve_space=True),
        re.S
    )
    assert query_html_doc(html_body, r'//p[matches(text(), "sec  ond\sone")]/text()') == ''
    assert query_html_doc(html_body, r'//p[matches(text(), "sec  ond\sone", "x")]/text()') == 'second one'
开发者ID:rbwinslow,项目名称:hq,代码行数:27,代码来源:test_extended_functions.py


示例20: test_absolute_location_path_should_find_multiple_grandchildren

def test_absolute_location_path_should_find_multiple_grandchildren():
    actual = query_html_doc('<div>one</div><p>not a div</p><div>two</div>', '/html/body/div')
    assert actual == expected_result("""
    <div>
     one
    </div>
    <div>
     two
    </div>""")
开发者ID:rbwinslow,项目名称:hq,代码行数:9,代码来源:test_location_paths.py



注:本文中的test.hquery.hquery_test_util.query_html_doc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python engines.testing_engine函数代码示例发布时间:2022-05-27
下一篇:
Python helper.FakeYDL类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap