# 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
# 
# Path: loom/query.py
# def protobuf_to_data_row(diff):
#     assert isinstance(diff, ProductValue.Diff)
#     assert diff.neg.observed.sparsity == NONE
#     data = diff.pos
#     packed = chain(data.booleans, data.counts, data.reals)
#     return [
#         packed.next() if observed else None
#         for observed in data.observed.dense
#     ]
# 
# Path: loom/test/util.py
# def load_rows(filename):
#     rows = []
#     for string in protobuf_stream_load(filename):
#         row = Row()
#         row.ParseFromString(string)
#         rows.append(row)
#     return rows


from itertools import izip
from nose.tools import assert_true, assert_equal, assert_not_equal
from distributions.dbg.random import sample_bernoulli
from distributions.io.stream import open_compressed
from distributions.fileutil import tempdir
from loom.schema_pb2 import ProductValue, CrossCat, Query
from loom.test.util import for_each_dataset
from loom.query import protobuf_to_data_row
from loom.test.util import load_rows
import loom.query
import loom.config
    for f, nontrivial in izip(featureids, nontrivials):
        if nontrivial:
            observed = all_observed[:]
            observed[f] = False
            observeds.append(observed)
    for f in featureids:
        observed = [
            nontrivial and sample_bernoulli(0.5)
            for nontrivial in nontrivials
        ]
        observeds.append(observed)
    for f, nontrivial in izip(featureids, nontrivials):
        if nontrivial:
            observed = none_observed[:]
            observed[f] = True
            observeds.append(observed)
    observeds.append(none_observed)

    requests = []
    for i, observed in enumerate(observeds):
        request = Query.Request()
        request.id = "example-{}".format(i)
        if query_type in ['sample', 'mixed']:
            set_diff(request.sample.data, none_observed)
            request.sample.to_sample.sparsity = DENSE
            request.sample.to_sample.dense[:] = observed
            request.sample.sample_count = 1
        if query_type in ['score', 'mixed']:
            set_diff(request.score.data, none_observed)
        requests.append(request)

# 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
# 
# Path: loom/query.py
# def protobuf_to_data_row(diff):
#     assert isinstance(diff, ProductValue.Diff)
#     assert diff.neg.observed.sparsity == NONE
#     data = diff.pos
#     packed = chain(data.booleans, data.counts, data.reals)
#     return [
#         packed.next() if observed else None
#         for observed in data.observed.dense
#     ]
# 
# Path: loom/test/util.py
# def load_rows(filename):
#     rows = []
#     for string in protobuf_stream_load(filename):
#         row = Row()
#         row.ParseFromString(string)
#         rows.append(row)
#     return rows


# Path: loom/test/test_query.py
from itertools import izip
from nose.tools import assert_true, assert_equal, assert_not_equal
from distributions.dbg.random import sample_bernoulli
from distributions.io.stream import open_compressed
from distributions.fileutil import tempdir
from loom.schema_pb2 import ProductValue, CrossCat, Query
from loom.test.util import for_each_dataset
from loom.query import protobuf_to_data_row
from loom.test.util import load_rows
import loom.query
import loom.config

    for f, nontrivial in izip(featureids, nontrivials):
        if nontrivial:
            observed = all_observed[:]
            observed[f] = False
            observeds.append(observed)
    for f in featureids:
        observed = [
            nontrivial and sample_bernoulli(0.5)
            for nontrivial in nontrivials
        ]
        observeds.append(observed)
    for f, nontrivial in izip(featureids, nontrivials):
        if nontrivial:
            observed = none_observed[:]
            observed[f] = True
            observeds.append(observed)
    observeds.append(none_observed)

    requests = []
    for i, observed in enumerate(observeds):
        request = Query.Request()
        request.id = "example-{}".format(i)
        if query_type in ['sample', 'mixed']:
            set_diff(request.sample.data, none_observed)
            request.sample.to_sample.sparsity = DENSE
            request.sample.to_sample.dense[:] = observed
            request.sample.sample_count = 1
        if query_type in ['score', 'mixed']:
            set_diff(request.score.data, none_observed)
        requests.append(request)

    for row in load_rows(rows)[:20]: