# Path: crosscompute/scripts/serve.py
# def do(arguments=None):
# def configure_argument_parser_for_serving(a):
# def serve_with(automation, args):
# def serve(
#         automation, host=HOST, port=PORT, with_browser=True,
#         is_static=False, is_production=False,
#         base_uri='', allowed_origins=None,
#         disk_poll_in_milliseconds=DISK_POLL_IN_MILLISECONDS,
#         disk_debounce_in_milliseconds=DISK_DEBOUNCE_IN_MILLISECONDS):
# L = getLogger(__name__)


from crosscompute.models import Result
from crosscompute.types import DataItem
from crosscompute.scripts.serve import (
    get_result_file_response, get_tool_file_response,
    parse_result_relative_path, parse_template_parts)
from invisibleroads_macros.disk import copy_path, make_folder
from invisibleroads_macros.exceptions import BadPath
from invisibleroads_uploads.models import Upload
from invisibleroads_uploads.tests import prepare_field_storage
from os.path import join
from pyramid.httpexceptions import HTTPBadRequest, HTTPForbidden, HTTPNotFound
from pytest import raises
from webob.multidict import MultiDict
from conftest import TOOL_FOLDER, WheeType

    def test_reject_mismatched_data_type(
            self, result_request, tool_definition):
        tool_definition['argument_names'] = ('x_whee',)
        # Run with incompatible value
        raw_arguments = MultiDict({'x_whee': 'x'})
        with raises(HTTPBadRequest) as e:
            result_request.prepare_arguments(tool_definition, raw_arguments)
        assert e.value.detail['x_whee'] == 'whee expected'
        # Run with compatible value
        raw_arguments = MultiDict({'x_whee': 'whee'})
        result = result_request.prepare_arguments(
            tool_definition, raw_arguments)
        assert result.arguments == {'x_whee': 'whee'}

    def test_accept_direct_content(self, result_request, tool_definition):
        tool_definition['argument_names'] = ('x_path',)
        raw_arguments = MultiDict({'x_txt': 'whee'})
        result = result_request.prepare_arguments(
            tool_definition, raw_arguments)
        assert open(result.arguments['x_path']).read() == 'whee'

    def test_accept_empty_content(self, result_request, tool_definition):
        tool_definition['argument_names'] = ('x_path',)
        raw_arguments = MultiDict({'x': ''})
        # Run without default_path
        with raises(HTTPBadRequest) as e:
            result_request.prepare_arguments(tool_definition, raw_arguments)
        assert e.value.detail['x'] == 'required'
        # Run with default_path

# Path: crosscompute/scripts/serve.py
# def do(arguments=None):
# def configure_argument_parser_for_serving(a):
# def serve_with(automation, args):
# def serve(
#         automation, host=HOST, port=PORT, with_browser=True,
#         is_static=False, is_production=False,
#         base_uri='', allowed_origins=None,
#         disk_poll_in_milliseconds=DISK_POLL_IN_MILLISECONDS,
#         disk_debounce_in_milliseconds=DISK_DEBOUNCE_IN_MILLISECONDS):
# L = getLogger(__name__)


# Path: experiments/0.7/tests/x_serve.py
from crosscompute.models import Result
from crosscompute.types import DataItem
from crosscompute.scripts.serve import (
    get_result_file_response, get_tool_file_response,
    parse_result_relative_path, parse_template_parts)
from invisibleroads_macros.disk import copy_path, make_folder
from invisibleroads_macros.exceptions import BadPath
from invisibleroads_uploads.models import Upload
from invisibleroads_uploads.tests import prepare_field_storage
from os.path import join
from pyramid.httpexceptions import HTTPBadRequest, HTTPForbidden, HTTPNotFound
from pytest import raises
from webob.multidict import MultiDict
from conftest import TOOL_FOLDER, WheeType


    def test_reject_mismatched_data_type(
            self, result_request, tool_definition):
        tool_definition['argument_names'] = ('x_whee',)
        # Run with incompatible value
        raw_arguments = MultiDict({'x_whee': 'x'})
        with raises(HTTPBadRequest) as e:
            result_request.prepare_arguments(tool_definition, raw_arguments)
        assert e.value.detail['x_whee'] == 'whee expected'
        # Run with compatible value
        raw_arguments = MultiDict({'x_whee': 'whee'})
        result = result_request.prepare_arguments(
            tool_definition, raw_arguments)
        assert result.arguments == {'x_whee': 'whee'}

    def test_accept_direct_content(self, result_request, tool_definition):
        tool_definition['argument_names'] = ('x_path',)
        raw_arguments = MultiDict({'x_txt': 'whee'})
        result = result_request.prepare_arguments(
            tool_definition, raw_arguments)
        assert open(result.arguments['x_path']).read() == 'whee'

    def test_accept_empty_content(self, result_request, tool_definition):
        tool_definition['argument_names'] = ('x_path',)
        raw_arguments = MultiDict({'x': ''})
        # Run without default_path
        with raises(HTTPBadRequest) as e:
            result_request.prepare_arguments(tool_definition, raw_arguments)
        assert e.value.detail['x'] == 'required'
        # Run with default_path

        default_path = join(tool_definition['configuration_folder'], 'cc.ini')