# Path: loom/test/util.py
# def for_each_dataset(fun):
#     @functools.wraps(fun)
#     def test_one(dataset):
#         paths = loom.store.get_paths(dataset, sample_count=2)
#         for key, path in loom.store.iter_paths(dataset, paths):
#             if not os.path.exists(path):
#                 raise ValueError(
#                     'missing {} at {},\n  first `python -m loom.datasets test`'
#                     .format(key, path))
#         kwargs = {'name': dataset}
#         kwargs.update(paths['query'])
#         kwargs.update(paths['consensus'])
#         kwargs.update(paths['samples'][0])
#         kwargs.update(paths['ingest'])
#         kwargs.update(paths)
#         fun(**kwargs)
# 
#     @functools.wraps(fun)
#     def test_all():
#         for dataset in loom.datasets.TEST_CONFIGS:
#             yield test_one, dataset
# 
#     return test_all
# 
# CLEANUP_ON_ERROR = int(os.environ.get('CLEANUP_ON_ERROR', 1))
# 
# def assert_found(*filenames):
#     for name in filenames:
#         assert_true(os.path.exists(name), 'missing file: {}'.format(name))


import os
import loom.generate
from distributions.fileutil import tempdir
from loom.test.util import for_each_dataset, CLEANUP_ON_ERROR, assert_found
FEATURE_TYPES = loom.schema.MODELS.keys()
FEATURE_TYPES += ['mixed']


def test_generate():
    for feature_type in FEATURE_TYPES:
        yield _test_generate, feature_type


def _test_generate(feature_type):
    root = os.getcwd()
    with tempdir(cleanup_on_error=CLEANUP_ON_ERROR):
        init_out = os.path.abspath('init.pb.gz')
        rows_out = os.path.abspath('rows.pbs.gz')
        model_out = os.path.abspath('model.pb.gz')
        groups_out = os.path.abspath('groups')
        os.chdir(root)
        loom.generate.generate(
            feature_type=feature_type,
            row_count=100,
            feature_count=100,
            density=0.5,
            init_out=init_out,
            rows_out=rows_out,
            model_out=model_out,
            groups_out=groups_out,
            debug=True,
            profile=None)



# Path: loom/test/util.py
# def for_each_dataset(fun):
#     @functools.wraps(fun)
#     def test_one(dataset):
#         paths = loom.store.get_paths(dataset, sample_count=2)
#         for key, path in loom.store.iter_paths(dataset, paths):
#             if not os.path.exists(path):
#                 raise ValueError(
#                     'missing {} at {},\n  first `python -m loom.datasets test`'
#                     .format(key, path))
#         kwargs = {'name': dataset}
#         kwargs.update(paths['query'])
#         kwargs.update(paths['consensus'])
#         kwargs.update(paths['samples'][0])
#         kwargs.update(paths['ingest'])
#         kwargs.update(paths)
#         fun(**kwargs)
# 
#     @functools.wraps(fun)
#     def test_all():
#         for dataset in loom.datasets.TEST_CONFIGS:
#             yield test_one, dataset
# 
#     return test_all
# 
# CLEANUP_ON_ERROR = int(os.environ.get('CLEANUP_ON_ERROR', 1))
# 
# def assert_found(*filenames):
#     for name in filenames:
#         assert_true(os.path.exists(name), 'missing file: {}'.format(name))


# Path: loom/test/test_generate.py
import os
import loom.generate
from distributions.fileutil import tempdir
from loom.test.util import for_each_dataset, CLEANUP_ON_ERROR, assert_found

FEATURE_TYPES = loom.schema.MODELS.keys()
FEATURE_TYPES += ['mixed']


def test_generate():
    for feature_type in FEATURE_TYPES:
        yield _test_generate, feature_type


def _test_generate(feature_type):
    root = os.getcwd()
    with tempdir(cleanup_on_error=CLEANUP_ON_ERROR):
        init_out = os.path.abspath('init.pb.gz')
        rows_out = os.path.abspath('rows.pbs.gz')
        model_out = os.path.abspath('model.pb.gz')
        groups_out = os.path.abspath('groups')
        os.chdir(root)
        loom.generate.generate(
            feature_type=feature_type,
            row_count=100,
            feature_count=100,
            density=0.5,
            init_out=init_out,
            rows_out=rows_out,
            model_out=model_out,
            groups_out=groups_out,
            debug=True,
            profile=None)



@for_each_dataset