# Path: crosscompute/constants.py
# class Error(IntEnum):
#     CONFIGURATION_NOT_FOUND = -100
#     COMMAND_NOT_FOUND = -10
# PACKAGE_FOLDER = Path(__file__).parent
# TEMPLATES_FOLDER = PACKAGE_FOLDER / 'templates'
# ID_LENGTH = 16
# AUTOMATION_NAME = 'Automation X'
# AUTOMATION_VERSION = '0.0.0'
# AUTOMATION_PATH = Path('automate.yml')
# HOST = '127.0.0.1'
# PORT = 7000
# DISK_POLL_IN_MILLISECONDS = 1000
# DISK_DEBOUNCE_IN_MILLISECONDS = 1000
# AUTOMATION_ROUTE = '/a/{automation_slug}'
# BATCH_ROUTE = '/b/{batch_slug}'
# VARIABLE_ROUTE = '/{variable_id}'
# MODE_ROUTE = '/{mode_code}'
# RUN_ROUTE = '/r/{run_slug}'
# STYLE_ROUTE = '/s/{style_name}.css'
# MUTATIONS_ROUTE = '/mutations'
# MODE_NAMES = 'input', 'output', 'log', 'debug'
# MODE_NAME_BY_CODE = {_[0]: _ for _ in MODE_NAMES}
# MODE_CODE_BY_NAME = {k: v for v, k in MODE_NAME_BY_CODE.items()}
# PING_INTERVAL_IN_SECONDS = 1
# FUNCTION_BY_NAME = {
#     'slug': format_slug,
#     'title': str.title,
# }
# VARIABLE_ID_PATTERN = re.compile(r'{\s*([^}]+?)\s*}')
# MAXIMUM_FILE_CACHE_LENGTH = 256
# 
# Path: crosscompute/exceptions.py
# class CrossComputeError(Exception):
# class CrossComputeConfigurationError(CrossComputeError):
# class CrossComputeConfigurationNotFoundError(CrossComputeConfigurationError):
# class CrossComputeConfigurationFormatError(CrossComputeError):
# class CrossComputeDataError(CrossComputeError):
# class CrossComputeExecutionError(CrossComputeError):
#     def __str__(self):


from crosscompute.constants import CLIENT_URL, SERVER_URL
from crosscompute.exceptions import (
    CrossComputeConnectionError,
    CrossComputeExecutionError,
    CrossComputeImplementationError)
from crosscompute.routines import (
    fetch_resource,
    get_bash_configuration_text,
    get_echoes_client,
    get_resource_url)
from http.server import BaseHTTPRequestHandler
from os import environ
from pytest import raises
from conftest import start_server
        self.end_headers()
        try:
            length = int(self.headers['Content-Length'])
        except TypeError:
            pass
        else:
            self.wfile.write(self.rfile.read(length))


def test_get_bash_configuration_text():
    environ['CROSSCOMPUTE_CLIENT'] = CLIENT_URL
    environ['CROSSCOMPUTE_SERVER'] = SERVER_URL
    try:
        del environ['CROSSCOMPUTE_TOKEN']
    except KeyError:
        pass
    bash_configuration_text = get_bash_configuration_text()
    assert CLIENT_URL in bash_configuration_text
    assert SERVER_URL in bash_configuration_text
    assert 'YOUR-TOKEN' in bash_configuration_text


def test_fetch_resource():
    server_url = 'http://localhost:9999'
    with raises(CrossComputeConnectionError):
        fetch_resource('tools', server_url=server_url, token='a')

    server_url = start_server(FetchResourceRequestHandler)
    with raises(CrossComputeImplementationError):
        fetch_resource('a', data={}, server_url=server_url, token='a')

# Path: crosscompute/constants.py
# class Error(IntEnum):
#     CONFIGURATION_NOT_FOUND = -100
#     COMMAND_NOT_FOUND = -10
# PACKAGE_FOLDER = Path(__file__).parent
# TEMPLATES_FOLDER = PACKAGE_FOLDER / 'templates'
# ID_LENGTH = 16
# AUTOMATION_NAME = 'Automation X'
# AUTOMATION_VERSION = '0.0.0'
# AUTOMATION_PATH = Path('automate.yml')
# HOST = '127.0.0.1'
# PORT = 7000
# DISK_POLL_IN_MILLISECONDS = 1000
# DISK_DEBOUNCE_IN_MILLISECONDS = 1000
# AUTOMATION_ROUTE = '/a/{automation_slug}'
# BATCH_ROUTE = '/b/{batch_slug}'
# VARIABLE_ROUTE = '/{variable_id}'
# MODE_ROUTE = '/{mode_code}'
# RUN_ROUTE = '/r/{run_slug}'
# STYLE_ROUTE = '/s/{style_name}.css'
# MUTATIONS_ROUTE = '/mutations'
# MODE_NAMES = 'input', 'output', 'log', 'debug'
# MODE_NAME_BY_CODE = {_[0]: _ for _ in MODE_NAMES}
# MODE_CODE_BY_NAME = {k: v for v, k in MODE_NAME_BY_CODE.items()}
# PING_INTERVAL_IN_SECONDS = 1
# FUNCTION_BY_NAME = {
#     'slug': format_slug,
#     'title': str.title,
# }
# VARIABLE_ID_PATTERN = re.compile(r'{\s*([^}]+?)\s*}')
# MAXIMUM_FILE_CACHE_LENGTH = 256
# 
# Path: crosscompute/exceptions.py
# class CrossComputeError(Exception):
# class CrossComputeConfigurationError(CrossComputeError):
# class CrossComputeConfigurationNotFoundError(CrossComputeConfigurationError):
# class CrossComputeConfigurationFormatError(CrossComputeError):
# class CrossComputeDataError(CrossComputeError):
# class CrossComputeExecutionError(CrossComputeError):
#     def __str__(self):


# Path: experiments/0.8/tests/test_routines_connection.py
from crosscompute.constants import CLIENT_URL, SERVER_URL
from crosscompute.exceptions import (
    CrossComputeConnectionError,
    CrossComputeExecutionError,
    CrossComputeImplementationError)
from crosscompute.routines import (
    fetch_resource,
    get_bash_configuration_text,
    get_echoes_client,
    get_resource_url)
from http.server import BaseHTTPRequestHandler
from os import environ
from pytest import raises
from conftest import start_server

        self.end_headers()
        try:
            length = int(self.headers['Content-Length'])
        except TypeError:
            pass
        else:
            self.wfile.write(self.rfile.read(length))


def test_get_bash_configuration_text():
    environ['CROSSCOMPUTE_CLIENT'] = CLIENT_URL
    environ['CROSSCOMPUTE_SERVER'] = SERVER_URL
    try:
        del environ['CROSSCOMPUTE_TOKEN']
    except KeyError:
        pass
    bash_configuration_text = get_bash_configuration_text()
    assert CLIENT_URL in bash_configuration_text
    assert SERVER_URL in bash_configuration_text
    assert 'YOUR-TOKEN' in bash_configuration_text


def test_fetch_resource():
    server_url = 'http://localhost:9999'
    with raises(CrossComputeConnectionError):
        fetch_resource('tools', server_url=server_url, token='a')

    server_url = start_server(FetchResourceRequestHandler)
    with raises(CrossComputeImplementationError):
        fetch_resource('a', data={}, server_url=server_url, token='a')

    with raises(CrossComputeConnectionError):