# Path: hq/hq.py
# def main():
#     from sys import stderr, stdin   # So py.tests have a chance to hook stdout & stderr
# 
#     args = docopt(__doc__, version='HQ {0}'.format(__version__))
#     preserve_space = bool(args['--preserve'])
#     set_verbosity(bool(args['--verbose']))
# 
#     try:
#         if args['--file']:
#             with open(args['--file']) as file:
#                 source = file.read()
#         else:
#             source = stdin.read()
#         verbose_print('Read {0} characters of input'.format(len(source)))
#         soup = make_soup(source)
# 
#         if args['--program']:
#             with open(args['--program']) as file:
#                 expression = file.read()
#         else:
#             expression = args['<expression>']
#         if len(expression) > 0:
#             result = HqueryProcessor(expression, preserve_space).query(soup)
#         else:
#             result = [soup]
# 
#         print(convert_results_to_output_text(result, pretty=(not args['--ugly']), preserve_space=preserve_space))
# 
#     except HquerySyntaxError as error:
#         print('\nSYNTAX ERROR: {0}\n'.format(str(error)), file=stderr)
#     except HqueryEvaluationError as error:
#         print('\nQUERY ERROR: {0}\n'.format(str(error)), file=stderr)
# 
# Path: test/common_test_util.py
# 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 wrap_html_body(contents):
#     return u'<html><body>{0}</body></html>'.format(contents)
# 
# def capture_console_output(capsys, strip=True):
#     output, errors = capsys.readouterr()
#     output = output.rstrip('\n')
#     return eliminate_blank_lines(output.strip()) if strip else output, eliminate_blank_lines(errors.strip())


import re
    from mock import mock_open
    from unittest.mock import mock_open
from hq.hq import main
from test.common_test_util import simulate_args_dict, wrap_html_body, capture_console_output

try:
except ImportError:



def test_preserve_space_flag_turns_off_space_normalization(capsys, mocker):
    hquery = '`${//p}`'
    content_with_spaces = '   PyCharm     rocks!    '
    mocker.patch('sys.stdin.read').return_value = wrap_html_body('<p>{0}</p>'.format(content_with_spaces))

    mocker.patch('hq.hq.docopt').return_value = simulate_args_dict(expression=hquery, preserve='s')

# Path: hq/hq.py
# def main():
#     from sys import stderr, stdin   # So py.tests have a chance to hook stdout & stderr
# 
#     args = docopt(__doc__, version='HQ {0}'.format(__version__))
#     preserve_space = bool(args['--preserve'])
#     set_verbosity(bool(args['--verbose']))
# 
#     try:
#         if args['--file']:
#             with open(args['--file']) as file:
#                 source = file.read()
#         else:
#             source = stdin.read()
#         verbose_print('Read {0} characters of input'.format(len(source)))
#         soup = make_soup(source)
# 
#         if args['--program']:
#             with open(args['--program']) as file:
#                 expression = file.read()
#         else:
#             expression = args['<expression>']
#         if len(expression) > 0:
#             result = HqueryProcessor(expression, preserve_space).query(soup)
#         else:
#             result = [soup]
# 
#         print(convert_results_to_output_text(result, pretty=(not args['--ugly']), preserve_space=preserve_space))
# 
#     except HquerySyntaxError as error:
#         print('\nSYNTAX ERROR: {0}\n'.format(str(error)), file=stderr)
#     except HqueryEvaluationError as error:
#         print('\nQUERY ERROR: {0}\n'.format(str(error)), file=stderr)
# 
# Path: test/common_test_util.py
# 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 wrap_html_body(contents):
#     return u'<html><body>{0}</body></html>'.format(contents)
# 
# def capture_console_output(capsys, strip=True):
#     output, errors = capsys.readouterr()
#     output = output.rstrip('\n')
#     return eliminate_blank_lines(output.strip()) if strip else output, eliminate_blank_lines(errors.strip())


# Path: test/test_cli.py
import re
    from mock import mock_open
    from unittest.mock import mock_open
from hq.hq import main
from test.common_test_util import simulate_args_dict, wrap_html_body, capture_console_output


try:
except ImportError:



def test_preserve_space_flag_turns_off_space_normalization(capsys, mocker):
    hquery = '`${//p}`'
    content_with_spaces = '   PyCharm     rocks!    '
    mocker.patch('sys.stdin.read').return_value = wrap_html_body('<p>{0}</p>'.format(content_with_spaces))

    mocker.patch('hq.hq.docopt').return_value = simulate_args_dict(expression=hquery, preserve='s')

    main()