# 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


from textwrap import dedent
from hq.soup_util import make_soup


def expected_result(contents):
    return dedent(contents.lstrip('\n'))


def simulate_args_dict(**kwargs):
    args = {
        '<expression>': '',
        '-f': False,
        '--file': False,
        '--preserve': False,
        '--program': '',
        '-u': False,
        '--ugly': False,
        '-v': False,
        '--verbose': False
    }
    for key, value in kwargs.items():
        if key == 'expression':
            format_string = '<{0}>'
        elif len(key) == 1:
            format_string = '-{0}'
        else:
            format_string = '--{0}'
        args[format_string.format(key)] = value
    return args


def soup_with_body(contents):

# 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
from textwrap import dedent
from hq.soup_util import make_soup



def expected_result(contents):
    return dedent(contents.lstrip('\n'))


def simulate_args_dict(**kwargs):
    args = {
        '<expression>': '',
        '-f': False,
        '--file': False,
        '--preserve': False,
        '--program': '',
        '-u': False,
        '--ugly': False,
        '-v': False,
        '--verbose': False
    }
    for key, value in kwargs.items():
        if key == 'expression':
            format_string = '<{0}>'
        elif len(key) == 1:
            format_string = '-{0}'
        else:
            format_string = '--{0}'
        args[format_string.format(key)] = value
    return args


def soup_with_body(contents):

    return make_soup(wrap_html_body(contents))