# Path: mlens/testing/dummy.py
# def get_layer(self, kls, proba, preprocessing, *args, **kwargs):
#     """Generate a layer instance.
# 
#     Parameters
#     ----------
#     kls : str
#         class type
# 
#     proba : bool
#         whether to set ``proba`` to ``True``
# 
#     preprocessing : bool
#         layer with preprocessing cases
#     """
#     indexer, kwargs = self.load_indexer(kls, args, kwargs)
# 
#     learner_kwargs = {'proba': kwargs.pop('proba', proba),
#                       'scorer': kwargs.pop('scorer', None)}
# 
#     layer = Layer(name='layer', dtype=np.float64, **kwargs)
# 
#     if preprocessing:
#         ests = ESTIMATORS_PROBA if proba else ESTIMATORS
#         prep = PREPROCESSING
#     else:
#         ests = ECM_PROBA if proba else ECM
#         prep = []
# 
#     group = make_group(indexer, ests, prep,
#                        learner_kwargs=learner_kwargs, name='group')
#     layer.push(group)
#     return layer
# 
# def run_layer(job, layer, X, y, F, wf=None):
#     """Sub-routine for running learner job"""
#     if job != 'fit':
#         run_layer('fit', layer, X, y, F)
# 
#     P = np.zeros(F.shape)
# 
#     path = _get_path(layer.backend, is_learner=False)
#     args = {
#         'dir': path,
#         'job': job,
#         'auxiliary': {'X': X, 'y': y} if job == 'fit' else {'X': X},
#         'main': {'X': X, 'y': y, 'P': P} if job == 'fit' else {'X': X, 'P': P}
#         }
# 
#     if layer.backend == 'manual':
#         # Run manually
#         layer.setup(X, y, job)
#         if layer.transformers:
#             for transformer in layer.transformers:
#                 for subtransformer in transformer(args, 'auxiliary'):
#                     subtransformer()
#         for learner in layer.learners:
#             for sublearner in learner(args, 'main'):
#                 sublearner()
# 
#         if job == 'fit':
#             layer.collect()
# 
#     else:
#         args = (X, y) if job == 'fit' else (X,)
#         with ParallelProcessing(layer.backend, layer.n_jobs) as manager:
#             P = manager.map(layer, job, *args, path=path, return_preds=True)
# 
#     if isinstance(path, str) and layer.backend == 'manual':
#         try:
#             shutil.rmtree(path)
#         except OSError:
#             warnings.warn(
#                 "Failed to destroy temporary test cache at %s" % path)
# 
#     if wf is not None:
#         if job in ['fit', 'transform']:
#             w = [obj.estimator.coef_
#                  for lr in layer.learners for obj in lr.sublearners]
#         else:
#             w = [obj.estimator.coef_
#                  for lr in layer.learners for obj in lr.learner]
#         np.testing.assert_array_equal(P, F)
#         np.testing.assert_array_equal(w, wf)
# 
#         assert P.__class__.__name__ == 'ndarray'
#         assert w[0].__class__.__name__ == 'ndarray'


from mlens.testing import get_layer, run_layer
""""ML-ENSEMBLE

Testing suite for Layer and Transformer
"""


def test_fit():
    """[Parallel | Layer | Threading | Subset | No Proba | No Prep] test fit"""
    args = get_layer('fit', 'threading', 'subsemble', False, False)
    run_layer(*args)


def test_predict():
    """[Parallel | Layer | Threading | Subset | No Proba | No Prep] test predict"""
    args = get_layer('predict', 'threading', 'subsemble', False, False)
    run_layer(*args)


def test_transform():
    """[Parallel | Layer | Threading | Subset | No Proba | No Prep] test transform"""
    args = get_layer('transform', 'threading', 'subsemble', False, False)
    run_layer(*args)


def test_fit_prep():
    """[Parallel | Layer | Threading | Subset | No Proba | Prep] test fit"""
    args = get_layer('fit', 'threading', 'subsemble', False, True)

# Path: mlens/testing/dummy.py
# def get_layer(self, kls, proba, preprocessing, *args, **kwargs):
#     """Generate a layer instance.
# 
#     Parameters
#     ----------
#     kls : str
#         class type
# 
#     proba : bool
#         whether to set ``proba`` to ``True``
# 
#     preprocessing : bool
#         layer with preprocessing cases
#     """
#     indexer, kwargs = self.load_indexer(kls, args, kwargs)
# 
#     learner_kwargs = {'proba': kwargs.pop('proba', proba),
#                       'scorer': kwargs.pop('scorer', None)}
# 
#     layer = Layer(name='layer', dtype=np.float64, **kwargs)
# 
#     if preprocessing:
#         ests = ESTIMATORS_PROBA if proba else ESTIMATORS
#         prep = PREPROCESSING
#     else:
#         ests = ECM_PROBA if proba else ECM
#         prep = []
# 
#     group = make_group(indexer, ests, prep,
#                        learner_kwargs=learner_kwargs, name='group')
#     layer.push(group)
#     return layer
# 
# def run_layer(job, layer, X, y, F, wf=None):
#     """Sub-routine for running learner job"""
#     if job != 'fit':
#         run_layer('fit', layer, X, y, F)
# 
#     P = np.zeros(F.shape)
# 
#     path = _get_path(layer.backend, is_learner=False)
#     args = {
#         'dir': path,
#         'job': job,
#         'auxiliary': {'X': X, 'y': y} if job == 'fit' else {'X': X},
#         'main': {'X': X, 'y': y, 'P': P} if job == 'fit' else {'X': X, 'P': P}
#         }
# 
#     if layer.backend == 'manual':
#         # Run manually
#         layer.setup(X, y, job)
#         if layer.transformers:
#             for transformer in layer.transformers:
#                 for subtransformer in transformer(args, 'auxiliary'):
#                     subtransformer()
#         for learner in layer.learners:
#             for sublearner in learner(args, 'main'):
#                 sublearner()
# 
#         if job == 'fit':
#             layer.collect()
# 
#     else:
#         args = (X, y) if job == 'fit' else (X,)
#         with ParallelProcessing(layer.backend, layer.n_jobs) as manager:
#             P = manager.map(layer, job, *args, path=path, return_preds=True)
# 
#     if isinstance(path, str) and layer.backend == 'manual':
#         try:
#             shutil.rmtree(path)
#         except OSError:
#             warnings.warn(
#                 "Failed to destroy temporary test cache at %s" % path)
# 
#     if wf is not None:
#         if job in ['fit', 'transform']:
#             w = [obj.estimator.coef_
#                  for lr in layer.learners for obj in lr.sublearners]
#         else:
#             w = [obj.estimator.coef_
#                  for lr in layer.learners for obj in lr.learner]
#         np.testing.assert_array_equal(P, F)
#         np.testing.assert_array_equal(w, wf)
# 
#         assert P.__class__.__name__ == 'ndarray'
#         assert w[0].__class__.__name__ == 'ndarray'


# Path: mlens/parallel/tests/test_b2_layer_subset.py
from mlens.testing import get_layer, run_layer

""""ML-ENSEMBLE

Testing suite for Layer and Transformer
"""


def test_fit():
    """[Parallel | Layer | Threading | Subset | No Proba | No Prep] test fit"""
    args = get_layer('fit', 'threading', 'subsemble', False, False)
    run_layer(*args)


def test_predict():
    """[Parallel | Layer | Threading | Subset | No Proba | No Prep] test predict"""
    args = get_layer('predict', 'threading', 'subsemble', False, False)
    run_layer(*args)


def test_transform():
    """[Parallel | Layer | Threading | Subset | No Proba | No Prep] test transform"""
    args = get_layer('transform', 'threading', 'subsemble', False, False)
    run_layer(*args)


def test_fit_prep():
    """[Parallel | Layer | Threading | Subset | No Proba | Prep] test fit"""
    args = get_layer('fit', 'threading', 'subsemble', False, True)

    run_layer(*args)