# 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))
# 
# def load_rows(filename):
#     rows = []
#     for string in protobuf_stream_load(filename):
#         row = Row()
#         row.ParseFromString(string)
#         rows.append(row)
#     return rows
# 
# def load_rows_raw(filename):
#     return list(protobuf_stream_load(filename))


import os
import loom.runner
from nose.tools import assert_equal, assert_not_equal, assert_list_equal
from loom.test.util import (
    for_each_dataset,
    CLEANUP_ON_ERROR,
    assert_found,
    load_rows,
    load_rows_raw,
)
from distributions.fileutil import tempdir
            rows_in=rows,
            rows_out=rows_out,
            seed=seed)
        assert_found(rows_out)

        original = load_rows(rows)
        shuffled = load_rows(rows_out)
        assert_equal(len(shuffled), len(original))
        assert_not_equal(shuffled, original)

        actual = sorted(shuffled, key=lambda row: row.id)
        expected = sorted(original, key=lambda row: row.id)
        assert_list_equal(expected, actual)


@for_each_dataset
def test_chunking(rows, **unused):
    targets = [10.0 ** i for i in xrange(6)]
    with tempdir(cleanup_on_error=CLEANUP_ON_ERROR):
        seed = 12345
        rows_out = os.path.abspath('rows.out.{}.pbs.gz')

        for i, target in enumerate(targets):
            loom.runner.shuffle(
                rows_in=rows,
                rows_out=rows_out.format(i),
                seed=seed,
                target_mem_bytes=target)

        results = [

# 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))
# 
# def load_rows(filename):
#     rows = []
#     for string in protobuf_stream_load(filename):
#         row = Row()
#         row.ParseFromString(string)
#         rows.append(row)
#     return rows
# 
# def load_rows_raw(filename):
#     return list(protobuf_stream_load(filename))


# Path: loom/test/test_shuffle.py
import os
import loom.runner
from nose.tools import assert_equal, assert_not_equal, assert_list_equal
from loom.test.util import (
    for_each_dataset,
    CLEANUP_ON_ERROR,
    assert_found,
    load_rows,
    load_rows_raw,
)
from distributions.fileutil import tempdir

            rows_in=rows,
            rows_out=rows_out,
            seed=seed)
        assert_found(rows_out)

        original = load_rows(rows)
        shuffled = load_rows(rows_out)
        assert_equal(len(shuffled), len(original))
        assert_not_equal(shuffled, original)

        actual = sorted(shuffled, key=lambda row: row.id)
        expected = sorted(original, key=lambda row: row.id)
        assert_list_equal(expected, actual)


@for_each_dataset
def test_chunking(rows, **unused):
    targets = [10.0 ** i for i in xrange(6)]
    with tempdir(cleanup_on_error=CLEANUP_ON_ERROR):
        seed = 12345
        rows_out = os.path.abspath('rows.out.{}.pbs.gz')

        for i, target in enumerate(targets):
            loom.runner.shuffle(
                rows_in=rows,
                rows_out=rows_out.format(i),
                seed=seed,
                target_mem_bytes=target)

        results = [

            load_rows_raw(rows_out.format(i))