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


import numpy
import loom.datasets
import loom.preql
import loom.query
from math import log
from nose.tools import assert_almost_equal
from nose.tools import assert_greater
from nose.tools import assert_less
from nose.tools import assert_less_equal
from distributions.fileutil import tempdir
from distributions.util import density_goodness_of_fit
from distributions.util import discrete_goodness_of_fit
from loom.test.util import for_each_dataset, load_rows
# - Neither the name of Salesforce.com nor the names of its contributors
#   may be used to endorse or promote products derived from this
#   software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



MIN_GOODNESS_OF_FIT = 1e-4
SCORE_PLACES = 3
SCORE_TOLERANCE = 10.0 ** -SCORE_PLACES

SAMPLE_COUNT = 500

# tests are inaccurate with highly imbalanced data
MIN_CATEGORICAL_PROB = .03

SEED = 1234



# 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
# 
# 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_math.py
import numpy
import loom.datasets
import loom.preql
import loom.query
from math import log
from nose.tools import assert_almost_equal
from nose.tools import assert_greater
from nose.tools import assert_less
from nose.tools import assert_less_equal
from distributions.fileutil import tempdir
from distributions.util import density_goodness_of_fit
from distributions.util import discrete_goodness_of_fit
from loom.test.util import for_each_dataset, load_rows

# - Neither the name of Salesforce.com nor the names of its contributors
#   may be used to endorse or promote products derived from this
#   software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



MIN_GOODNESS_OF_FIT = 1e-4
SCORE_PLACES = 3
SCORE_TOLERANCE = 10.0 ** -SCORE_PLACES

SAMPLE_COUNT = 500

# tests are inaccurate with highly imbalanced data
MIN_CATEGORICAL_PROB = .03

SEED = 1234



@for_each_dataset