本文整理汇总了Python中test.hquery.hquery_test_util.query_html_doc函数的典型用法代码示例。如果您正苦于以下问题:Python query_html_doc函数的具体用法?Python query_html_doc怎么用?Python query_html_doc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了query_html_doc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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'
示例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'
示例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')
示例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'
示例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
示例6: test_escapes_work_in_string_literals
def test_escapes_work_in_string_literals():
assert query_html_doc('', '"foo bar"') == expected_result("""
foo
bar""")
assert query_html_doc('', "'foo bar'") == expected_result("""
foo
bar""")
assert query_html_doc('', '`foo bar`') == expected_result("""
foo
bar""")
示例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'
示例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>""")
示例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'
示例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""")
示例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'
示例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)
示例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'
示例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>""")
示例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>""")