# Path: studio/model.py
# def reset_storage_providers():
# def get_config(config_file=None):
# def get_db_provider(config=None, blocking_auth=True):
# def get_queue(
#         queue_name=None,
#         cloud=None,
#         config=None,
#         logger=None,
#         close_after=None,
#         verbose=10):
# def shutdown_queue(queue, logger=None, delete_queue=True):
# def get_worker_manager(config, cloud=None, verbose=10):
# 
# Path: studio/util/logs.py
# DEBUG = logging.DEBUG
# INFO = logging.INFO
# ERROR = logging.ERROR
# def get_logger(name):
# def debug(line):
# def error(line):
# def info(line):
# 
# Path: studio/queues/local_queue.py
# LOCK_FILE_NAME = 'lock.lock'
# class LocalQueue:
#     def __init__(self, name: str, path: str = None, logger=None):
#     def _get_queue_status(self):
#     def _get_queue_directory(self):
#     def has_next(self):
#     def is_active(self):
#     def clean(self, timeout=0):
#     def delete(self):
#     def _get_time(self, file: str):
#     def dequeue(self, acknowledge=True, timeout=0):
#     def enqueue(self, data):
#     def acknowledge(self, key):
#     def hold(self, key, minutes):
#     def get_name(self):
#     def get_path(self):
#     def shutdown(self, delete_queue=True):
# 
# Path: studio/util/util.py
# def sixdecode(sval):
#     if isinstance(sval, str):
#         return sval
#     if isinstance(sval, bytes):
#         return sval.decode('utf8')
#     raise TypeError("Unknown type of " + str(sval))
# 
# def retry(f,
#           no_retries=5, sleep_time=1,
#           exception_class=BaseException, logger=None):
#     for i in range(no_retries):
#         try:
#             return f()
#         except exception_class as exc:
#             check_for_kb_interrupt()
#             if i == no_retries - 1:
#                 raise exc
# 
#             if logger:
#                 logger.info(
#                     ('Exception {0} is caught, ' +
#                      'sleeping {1}s and retrying (attempt {2} of {3})')
#                         .format(exc, sleep_time, i, no_retries))
#             time.sleep(sleep_time)
#     return None
# 
# Path: studio/extra_util.py
# def has_aws_credentials():
#     artifact_store = storage_setup.get_storage_artifact_store()
#     if artifact_store is None:
#         return False
#     storage_handler = artifact_store.get_storage_handler()
#     if storage_handler.type == StorageType.storageS3:
#         storage_client = storage_handler.get_client()
#         return storage_client._request_signer._credentials is not None
#     else:
#         return False


import unittest
import os
import shutil
import tempfile
import uuid
import subprocess
import time
import traceback
import numpy as np
import glob
    import keras
            import keras
from timeout_decorator import timeout
from studio import model
from studio.util import logs
from studio.queues.local_queue import LocalQueue, get_local_queue_lock
from studio.util.util import sixdecode, retry
from studio.extra_util import has_aws_credentials
from env_detect import on_gcp, on_aws
        if test_output:
            with open(db.get_artifact(experiment.artifacts['output']),
                      'r') as f:
                data = f.read()
                split_data = data.strip().split('\n')
                print(data)
                testclass.assertEqual(split_data[-1], expected_output)

        if test_workspace:
            check_workspace(testclass, db, experiment_name)

        if delete_when_done:
            retry(lambda: db.delete_experiment(experiment_name), sleep_time=10)

        return db

    except Exception as e:
        print("Exception {} raised during test".format(e))
        print("worker output: \n {}".format(pout))
        print("Exception trace:")
        print(traceback.format_exc())
        raise e


def check_workspace(testclass, db, key):

    tmpdir = os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))
    os.mkdir(tmpdir)
    experiment = retry(lambda: db.get_experiment(key), sleep_time=5)
    artifact = experiment.artifacts['workspace']

# Path: studio/model.py
# def reset_storage_providers():
# def get_config(config_file=None):
# def get_db_provider(config=None, blocking_auth=True):
# def get_queue(
#         queue_name=None,
#         cloud=None,
#         config=None,
#         logger=None,
#         close_after=None,
#         verbose=10):
# def shutdown_queue(queue, logger=None, delete_queue=True):
# def get_worker_manager(config, cloud=None, verbose=10):
# 
# Path: studio/util/logs.py
# DEBUG = logging.DEBUG
# INFO = logging.INFO
# ERROR = logging.ERROR
# def get_logger(name):
# def debug(line):
# def error(line):
# def info(line):
# 
# Path: studio/queues/local_queue.py
# LOCK_FILE_NAME = 'lock.lock'
# class LocalQueue:
#     def __init__(self, name: str, path: str = None, logger=None):
#     def _get_queue_status(self):
#     def _get_queue_directory(self):
#     def has_next(self):
#     def is_active(self):
#     def clean(self, timeout=0):
#     def delete(self):
#     def _get_time(self, file: str):
#     def dequeue(self, acknowledge=True, timeout=0):
#     def enqueue(self, data):
#     def acknowledge(self, key):
#     def hold(self, key, minutes):
#     def get_name(self):
#     def get_path(self):
#     def shutdown(self, delete_queue=True):
# 
# Path: studio/util/util.py
# def sixdecode(sval):
#     if isinstance(sval, str):
#         return sval
#     if isinstance(sval, bytes):
#         return sval.decode('utf8')
#     raise TypeError("Unknown type of " + str(sval))
# 
# def retry(f,
#           no_retries=5, sleep_time=1,
#           exception_class=BaseException, logger=None):
#     for i in range(no_retries):
#         try:
#             return f()
#         except exception_class as exc:
#             check_for_kb_interrupt()
#             if i == no_retries - 1:
#                 raise exc
# 
#             if logger:
#                 logger.info(
#                     ('Exception {0} is caught, ' +
#                      'sleeping {1}s and retrying (attempt {2} of {3})')
#                         .format(exc, sleep_time, i, no_retries))
#             time.sleep(sleep_time)
#     return None
# 
# Path: studio/extra_util.py
# def has_aws_credentials():
#     artifact_store = storage_setup.get_storage_artifact_store()
#     if artifact_store is None:
#         return False
#     storage_handler = artifact_store.get_storage_handler()
#     if storage_handler.type == StorageType.storageS3:
#         storage_client = storage_handler.get_client()
#         return storage_client._request_signer._credentials is not None
#     else:
#         return False


# Path: tests/local_worker_test.py
import unittest
import os
import shutil
import tempfile
import uuid
import subprocess
import time
import traceback
import numpy as np
import glob
    import keras
            import keras
from timeout_decorator import timeout
from studio import model
from studio.util import logs
from studio.queues.local_queue import LocalQueue, get_local_queue_lock
from studio.util.util import sixdecode, retry
from studio.extra_util import has_aws_credentials
from env_detect import on_gcp, on_aws

        if test_output:
            with open(db.get_artifact(experiment.artifacts['output']),
                      'r') as f:
                data = f.read()
                split_data = data.strip().split('\n')
                print(data)
                testclass.assertEqual(split_data[-1], expected_output)

        if test_workspace:
            check_workspace(testclass, db, experiment_name)

        if delete_when_done:
            retry(lambda: db.delete_experiment(experiment_name), sleep_time=10)

        return db

    except Exception as e:
        print("Exception {} raised during test".format(e))
        print("worker output: \n {}".format(pout))
        print("Exception trace:")
        print(traceback.format_exc())
        raise e


def check_workspace(testclass, db, key):

    tmpdir = os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))
    os.mkdir(tmpdir)
    experiment = retry(lambda: db.get_experiment(key), sleep_time=5)
    artifact = experiment.artifacts['workspace']

    localpath = retry(