# Path: kubeface/client.py
# def run_multiple(function, values):
#     def add_args(parser):
#     def from_args(args):
#     def __init__(
#             self,
#             backend,
#             max_simultaneous_tasks=10,
#             poll_seconds=30.0,
#             storage="gs://kubeface",
#             cache_key_prefix=None,
#             never_cleanup=False,
#             wait_to_raise_task_exception=False,
#             speculation_percent=0,
#             speculation_runtime_percentile=99,
#             speculation_max_reruns=1):
#     def __getstate__(self):
#     def next_cache_key(self):
#     def submit(self, tasks, num_tasks=None, cache_key=None):
#     def map(
#             self,
#             function,
#             iterable,
#             items_per_task=1,
#             num_items=None,
#             cache_key=None):
#         def grouped():
#     def mark_jobs_done(self, job_names=None):
#     def cleanup_job(self, job_name):
#     def job_summary(self, job_names=None, include_done=False):
#     def cleanup(self):
#     def remote_object(self, value):
# class Client(object):
# 
# Path: kubeface/local_process_backend.py
# class LocalProcessBackend(Backend):
#     def add_args(parser):
#     def from_args(args):
#     def __init__(self, worker_configuration=DEFAULT_WORKER_CONFIG):
#     def submit_task(self, task_name, task_input, task_output):
# 
# Path: kubeface/local_process_docker_backend.py
# DOCKER_MOUNT = "/kubeface-data"
# KUBEFACE_MOUNT = "/kubeface-package"
# class LocalProcessDockerBackend(Backend):
#     def add_args(parser):
#     def from_args(args):
#     def __init__(
#             self,
#             worker_configuration=DEFAULT_WORKER_CONFIG,
#             docker_command="docker"):
#     def submit_task(self, task_name, task_input, task_output):
# 
# Path: kubeface/worker_configuration.py
# class WorkerConfiguration(object):
#     def add_args(parser):
#     def from_args(args):
#     def __init__(
#             self,
#             image='continuumio/anaconda3',
#             path_prefix='',
#             pip='pip',
#             pip_packages=[],
#             kubeface_install_policy='if-not-present',
# 
#             # TODO: this should default to installing the version of kubeface
#             # running in the current process, not HEAD.
#             kubeface_install_command=(
#                 "{pip} install "
#                 "https://github.com/hammerlab/kubeface/archive/master.zip"
#             )):
#     def non_default_fields(self):
#     def command(self, task_input, task_output, extra_task_args=[]):
#         def quote_and_join(arguments):
# DEFAULT = WorkerConfiguration()
# 
# Path: kubeface/serialization.py
# PICKLE_PROTOCOL = 2
# CHECK_SERIALIZATION = False
# def check(obj):
# def dumps(obj):
# def dump(obj, fd):
# def loads(s):
# def load(fd):
# 
# Path: kubeface/common.py
# def check_call(*args, **kwargs):
# def configure_logging(args=None, verbose=False):
# def human_readable_memory_size(num, suffix='B'):
# def truncate(s, max_length):


import numpy
import argparse
from numpy import testing
from kubeface import (
    client,
    local_process_backend,
    local_process_docker_backend,
    worker_configuration,
    serialization,
    common)
from . import util
            "--kubeface-storage", "/tmp",
        ])


@util.with_local_and_bucket_storage
def test_remote_object(bucket):
    c = client_from_commandline_args([
        "--kubeface-poll-seconds", "1.1",
        "--kubeface-backend", "local-process",
        "--kubeface-storage", bucket,
    ])
    data = numpy.arange(10000)**2
    serialized_data = serialization.dumps(data)
    testing.assert_equal(serialization.loads(serialized_data), data)

    remote = c.remote_object(data)
    serialized_remote = serialization.dumps(remote)
    assert len(serialized_remote) < len(serialized_data) / 10
    testing.assert_equal(serialization.loads(serialized_remote).value, data)


@util.with_local_and_bucket_storage
def test_pickle_client(bucket):
    c = client_from_commandline_args([
        "--kubeface-poll-seconds", "1.1",
        "--kubeface-backend", "local-process",
        "--kubeface-storage", bucket,
    ])
    testing.assert_equal(
        c.cache_key_prefix,

# Path: kubeface/client.py
# def run_multiple(function, values):
#     def add_args(parser):
#     def from_args(args):
#     def __init__(
#             self,
#             backend,
#             max_simultaneous_tasks=10,
#             poll_seconds=30.0,
#             storage="gs://kubeface",
#             cache_key_prefix=None,
#             never_cleanup=False,
#             wait_to_raise_task_exception=False,
#             speculation_percent=0,
#             speculation_runtime_percentile=99,
#             speculation_max_reruns=1):
#     def __getstate__(self):
#     def next_cache_key(self):
#     def submit(self, tasks, num_tasks=None, cache_key=None):
#     def map(
#             self,
#             function,
#             iterable,
#             items_per_task=1,
#             num_items=None,
#             cache_key=None):
#         def grouped():
#     def mark_jobs_done(self, job_names=None):
#     def cleanup_job(self, job_name):
#     def job_summary(self, job_names=None, include_done=False):
#     def cleanup(self):
#     def remote_object(self, value):
# class Client(object):
# 
# Path: kubeface/local_process_backend.py
# class LocalProcessBackend(Backend):
#     def add_args(parser):
#     def from_args(args):
#     def __init__(self, worker_configuration=DEFAULT_WORKER_CONFIG):
#     def submit_task(self, task_name, task_input, task_output):
# 
# Path: kubeface/local_process_docker_backend.py
# DOCKER_MOUNT = "/kubeface-data"
# KUBEFACE_MOUNT = "/kubeface-package"
# class LocalProcessDockerBackend(Backend):
#     def add_args(parser):
#     def from_args(args):
#     def __init__(
#             self,
#             worker_configuration=DEFAULT_WORKER_CONFIG,
#             docker_command="docker"):
#     def submit_task(self, task_name, task_input, task_output):
# 
# Path: kubeface/worker_configuration.py
# class WorkerConfiguration(object):
#     def add_args(parser):
#     def from_args(args):
#     def __init__(
#             self,
#             image='continuumio/anaconda3',
#             path_prefix='',
#             pip='pip',
#             pip_packages=[],
#             kubeface_install_policy='if-not-present',
# 
#             # TODO: this should default to installing the version of kubeface
#             # running in the current process, not HEAD.
#             kubeface_install_command=(
#                 "{pip} install "
#                 "https://github.com/hammerlab/kubeface/archive/master.zip"
#             )):
#     def non_default_fields(self):
#     def command(self, task_input, task_output, extra_task_args=[]):
#         def quote_and_join(arguments):
# DEFAULT = WorkerConfiguration()
# 
# Path: kubeface/serialization.py
# PICKLE_PROTOCOL = 2
# CHECK_SERIALIZATION = False
# def check(obj):
# def dumps(obj):
# def dump(obj, fd):
# def loads(s):
# def load(fd):
# 
# Path: kubeface/common.py
# def check_call(*args, **kwargs):
# def configure_logging(args=None, verbose=False):
# def human_readable_memory_size(num, suffix='B'):
# def truncate(s, max_length):


# Path: tests/test_client.py
import numpy
import argparse
from numpy import testing
from kubeface import (
    client,
    local_process_backend,
    local_process_docker_backend,
    worker_configuration,
    serialization,
    common)
from . import util

            "--kubeface-storage", "/tmp",
        ])


@util.with_local_and_bucket_storage
def test_remote_object(bucket):
    c = client_from_commandline_args([
        "--kubeface-poll-seconds", "1.1",
        "--kubeface-backend", "local-process",
        "--kubeface-storage", bucket,
    ])
    data = numpy.arange(10000)**2
    serialized_data = serialization.dumps(data)
    testing.assert_equal(serialization.loads(serialized_data), data)

    remote = c.remote_object(data)
    serialized_remote = serialization.dumps(remote)
    assert len(serialized_remote) < len(serialized_data) / 10
    testing.assert_equal(serialization.loads(serialized_remote).value, data)


@util.with_local_and_bucket_storage
def test_pickle_client(bucket):
    c = client_from_commandline_args([
        "--kubeface-poll-seconds", "1.1",
        "--kubeface-backend", "local-process",
        "--kubeface-storage", bucket,
    ])
    testing.assert_equal(
        c.cache_key_prefix,

        serialization.loads(serialization.dumps(c)).cache_key_prefix)