# 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
        # Use good path
        raw_arguments = MultiDict({'x': 'xyz/x/x.txt'})
        result = result_request.prepare_arguments(
            tool_definition, raw_arguments)
        assert open(result.arguments['x_path']).read() == 'whee'

    def test_accept_upload_id(
            self, result_request, tool_definition, data_folder):
        tool_definition['argument_names'] = ('x_path',)
        # Use bad upload_id
        raw_arguments = MultiDict({'x': 'a'})
        with raises(HTTPBadRequest) as e:
            result_request.prepare_arguments(tool_definition, raw_arguments)
        assert e.value.detail['x'] == 'invalid'
        # Use upload_id that does not have expected data_type
        upload = Upload.save(data_folder, 'anonymous', 32, 'x.txt', 'x')
        raw_arguments = MultiDict({'x': upload.id})
        with raises(HTTPBadRequest) as e:
            result_request.prepare_arguments(tool_definition, raw_arguments)
        assert e.value.detail['x'] == 'invalid'
        # Use upload_id that has expected data_type
        upload = Upload.save(data_folder, 'anonymous', 32, 'x.txt', 'whee')
        copy_path(join(upload.folder, WheeType.get_file_name()), upload.path)
        raw_arguments = MultiDict({'x': upload.id})
        result = result_request.prepare_arguments(
            tool_definition, raw_arguments)
        assert open(result.arguments['x_path']).read() == 'whee'


def test_parse_result_relative_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

        # Use good path
        raw_arguments = MultiDict({'x': 'xyz/x/x.txt'})
        result = result_request.prepare_arguments(
            tool_definition, raw_arguments)
        assert open(result.arguments['x_path']).read() == 'whee'

    def test_accept_upload_id(
            self, result_request, tool_definition, data_folder):
        tool_definition['argument_names'] = ('x_path',)
        # Use bad upload_id
        raw_arguments = MultiDict({'x': 'a'})
        with raises(HTTPBadRequest) as e:
            result_request.prepare_arguments(tool_definition, raw_arguments)
        assert e.value.detail['x'] == 'invalid'
        # Use upload_id that does not have expected data_type
        upload = Upload.save(data_folder, 'anonymous', 32, 'x.txt', 'x')
        raw_arguments = MultiDict({'x': upload.id})
        with raises(HTTPBadRequest) as e:
            result_request.prepare_arguments(tool_definition, raw_arguments)
        assert e.value.detail['x'] == 'invalid'
        # Use upload_id that has expected data_type
        upload = Upload.save(data_folder, 'anonymous', 32, 'x.txt', 'whee')
        copy_path(join(upload.folder, WheeType.get_file_name()), upload.path)
        raw_arguments = MultiDict({'x': upload.id})
        result = result_request.prepare_arguments(
            tool_definition, raw_arguments)
        assert open(result.arguments['x_path']).read() == 'whee'


def test_parse_result_relative_path():

    f = parse_result_relative_path