# Path: mlens/config.py
# _DTYPE = getattr(numpy, os.environ.get('MLENS_DTYPE', 'float32'))
# _TMPDIR = os.environ.get('MLENS_TMPDIR', tempfile.gettempdir())
# _PREFIX = os.environ.get('MLENS_PREFIX', ".mlens_tmp_cache_")
# _BACKEND = os.environ.get('MLENS_BACKEND', 'threading')
# _START_METHOD = os.environ.get('MLENS_START_METHOD', '')
# _VERBOSE = os.environ.get('MLENS_VERBOSE', 'Y')
# _IVALS = os.environ.get('MLENS_IVALS', '0.01_120').split('_')
# _IVALS = (float(_IVALS[0]), float(_IVALS[1]))
# _PY_VERSION = float(sysconfig._PY_VERSION_SHORT)
#     _TMPDIR = tmp
#     _PREFIX = prefix
#     _DTYPE = dtype
#     _BACKEND = backend
#     _START_METHOD = method
#     _IVALS = (interval, limit)
#     _START_METHOD = __get_default_start_method(_START_METHOD)
# def get_ivals():
# def get_dtype():
# def get_prefix():
# def get_backend():
# def get_start_method():
# def get_tmpdir():
# def set_tmpdir(tmp):
# def set_prefix(prefix):
# def set_dtype(dtype):
# def set_backend(backend):
# def set_start_method(method):
# def set_ivals(interval, limit):
# def __get_default_start_method(method):
# def clear_cache(tmp):
# def print_settings():
# 
# Path: mlens/utils/utils.py
# def pickled(name):
# def pickle_save(obj, name):
# def pickle_load(name):
# def load(file, enforce_filetype=True):
# def clone_attribute(iterable, attribute):
# def kwarg_parser(func, kwargs):
# def safe_print(*objects, **kwargs):
# def print_time(t0, message='', **kwargs):
#     def __init__(self, verbose=False):
#     def monitor(self, stop=None, ival=0.1, kill=True):
#     def collect(self):
# def _recorder(pid, stop, ival):
# class CMLog(object):
# 
# Path: mlens/utils/exceptions.py
# class ParallelProcessingError(AttributeError, RuntimeError):
# 
#     """Error class for fatal errors related to :class:`ParallelProcessing`.
# 
#     Can be subclassed for more specific error classes.
#     """


import os
import numpy as np
import sysconfig
import subprocess
    import psutil
from mlens import config
from mlens.utils import utils
from mlens.utils.exceptions import ParallelProcessingError
from time import sleep
    from time import perf_counter as time
    from time import time
    from contextlib import redirect_stdout, redirect_stderr
    from mlens.externals.fixes import redirect as redirect_stdout

def test_cm_exception():
    """[Utils] CMLog: test collecting un-monitored returns None."""
    if psutil is not None and not __version__.startswith('2.'):
        cm = utils.CMLog(verbose=False)
        with open(os.devnull, 'w') as f, redirect_stdout(f):
            out = cm.collect()
        assert out is None


def test_pickle():
    """[Utils] Check that pickling a standard object works."""
    utils.pickle_save(d, 'd')
    test = utils.pickle_load('d')

    subprocess.check_call(['rm', 'd.pkl'])

    assert isinstance(d, dict)
    assert test['entry1'] == 'test'
    assert test['entry2'] == 'also_test'


def test_load():
    """[Utils] Check that load handles exceptions gracefully"""

    config.set_ivals(0.1, 0.1)

    with open(os.devnull, 'w') as f, redirect_stderr(f):
        np.testing.assert_raises(
            ParallelProcessingError,

# Path: mlens/config.py
# _DTYPE = getattr(numpy, os.environ.get('MLENS_DTYPE', 'float32'))
# _TMPDIR = os.environ.get('MLENS_TMPDIR', tempfile.gettempdir())
# _PREFIX = os.environ.get('MLENS_PREFIX', ".mlens_tmp_cache_")
# _BACKEND = os.environ.get('MLENS_BACKEND', 'threading')
# _START_METHOD = os.environ.get('MLENS_START_METHOD', '')
# _VERBOSE = os.environ.get('MLENS_VERBOSE', 'Y')
# _IVALS = os.environ.get('MLENS_IVALS', '0.01_120').split('_')
# _IVALS = (float(_IVALS[0]), float(_IVALS[1]))
# _PY_VERSION = float(sysconfig._PY_VERSION_SHORT)
#     _TMPDIR = tmp
#     _PREFIX = prefix
#     _DTYPE = dtype
#     _BACKEND = backend
#     _START_METHOD = method
#     _IVALS = (interval, limit)
#     _START_METHOD = __get_default_start_method(_START_METHOD)
# def get_ivals():
# def get_dtype():
# def get_prefix():
# def get_backend():
# def get_start_method():
# def get_tmpdir():
# def set_tmpdir(tmp):
# def set_prefix(prefix):
# def set_dtype(dtype):
# def set_backend(backend):
# def set_start_method(method):
# def set_ivals(interval, limit):
# def __get_default_start_method(method):
# def clear_cache(tmp):
# def print_settings():
# 
# Path: mlens/utils/utils.py
# def pickled(name):
# def pickle_save(obj, name):
# def pickle_load(name):
# def load(file, enforce_filetype=True):
# def clone_attribute(iterable, attribute):
# def kwarg_parser(func, kwargs):
# def safe_print(*objects, **kwargs):
# def print_time(t0, message='', **kwargs):
#     def __init__(self, verbose=False):
#     def monitor(self, stop=None, ival=0.1, kill=True):
#     def collect(self):
# def _recorder(pid, stop, ival):
# class CMLog(object):
# 
# Path: mlens/utils/exceptions.py
# class ParallelProcessingError(AttributeError, RuntimeError):
# 
#     """Error class for fatal errors related to :class:`ParallelProcessing`.
# 
#     Can be subclassed for more specific error classes.
#     """


# Path: mlens/utils/tests/test_utils.py
import os
import numpy as np
import sysconfig
import subprocess
    import psutil
from mlens import config
from mlens.utils import utils
from mlens.utils.exceptions import ParallelProcessingError
from time import sleep
    from time import perf_counter as time
    from time import time
    from contextlib import redirect_stdout, redirect_stderr
    from mlens.externals.fixes import redirect as redirect_stdout


def test_cm_exception():
    """[Utils] CMLog: test collecting un-monitored returns None."""
    if psutil is not None and not __version__.startswith('2.'):
        cm = utils.CMLog(verbose=False)
        with open(os.devnull, 'w') as f, redirect_stdout(f):
            out = cm.collect()
        assert out is None


def test_pickle():
    """[Utils] Check that pickling a standard object works."""
    utils.pickle_save(d, 'd')
    test = utils.pickle_load('d')

    subprocess.check_call(['rm', 'd.pkl'])

    assert isinstance(d, dict)
    assert test['entry1'] == 'test'
    assert test['entry2'] == 'also_test'


def test_load():
    """[Utils] Check that load handles exceptions gracefully"""

    config.set_ivals(0.1, 0.1)

    with open(os.devnull, 'w') as f, redirect_stderr(f):
        np.testing.assert_raises(
            ParallelProcessingError,

            utils.load, os.path.join(os.getcwd(), 'nonexist'))