# Path: hq/soup_util.py
# def make_soup(source):
#     soup = BeautifulSoup(source, 'html.parser')
#     counter = [0]
# 
#     def visit_node(node):
#         node.hq_doc_index = counter[0]
#         counter[0] += 1
#         if is_tag_node(node):
#             attr_names = sorted(node.attrs.keys(), key=lambda name: name.lower())
#             node.hq_attrs = [AttributeNode(name, node.attrs[name]) for name in attr_names]
#             for attr in node.hq_attrs:
#                 visit_node(attr)
# 
#     preorder_traverse_node_tree(soup, visit_node, filter=is_any_node)
#     verbose_print('Loaded HTML document containing {0} indexed nodes.'.format(counter[0]))
#     return soup
# 
# Path: test/common_test_util.py
# def expected_result(contents):
#     return dedent(contents.lstrip('\n'))
# 
# Path: test/hquery/hquery_test_util.py
# def query_context_node(node_or_source, hquery):
#     if not is_any_node(node_or_source):
#         node_or_source = root_tag_from_soup(make_soup(node_or_source))
#     raw_result = HqueryProcessor(hquery).query(node_or_source)
#     return eliminate_blank_lines(convert_results_to_output_text(raw_result).strip())


from hq.soup_util import make_soup
from test.common_test_util import expected_result
from test.hquery.hquery_test_util import query_context_node


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>"""

# Path: hq/soup_util.py
# def make_soup(source):
#     soup = BeautifulSoup(source, 'html.parser')
#     counter = [0]
# 
#     def visit_node(node):
#         node.hq_doc_index = counter[0]
#         counter[0] += 1
#         if is_tag_node(node):
#             attr_names = sorted(node.attrs.keys(), key=lambda name: name.lower())
#             node.hq_attrs = [AttributeNode(name, node.attrs[name]) for name in attr_names]
#             for attr in node.hq_attrs:
#                 visit_node(attr)
# 
#     preorder_traverse_node_tree(soup, visit_node, filter=is_any_node)
#     verbose_print('Loaded HTML document containing {0} indexed nodes.'.format(counter[0]))
#     return soup
# 
# Path: test/common_test_util.py
# def expected_result(contents):
#     return dedent(contents.lstrip('\n'))
# 
# Path: test/hquery/hquery_test_util.py
# def query_context_node(node_or_source, hquery):
#     if not is_any_node(node_or_source):
#         node_or_source = root_tag_from_soup(make_soup(node_or_source))
#     raw_result = HqueryProcessor(hquery).query(node_or_source)
#     return eliminate_blank_lines(convert_results_to_output_text(raw_result).strip())


# Path: test/hquery/test_xpath1_abbreviated_samples.py
from hq.soup_util import make_soup
from test.common_test_util import expected_result
from test.hquery.hquery_test_util import query_context_node



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("""