def test_or(strict_schema, strict_file):
    assert not StrictMetricsEvaluator(strict_schema,
                                      Expressions.or_(Expressions.less_than("id", 5),
                                                      Expressions.greater_than_or_equal("id", 80))).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema,
                                      Expressions.or_(Expressions.less_than("id", 5),
                                                      Expressions.greater_than_or_equal("id", 60))).eval(strict_file)
    assert StrictMetricsEvaluator(strict_schema,
                                  Expressions.or_(Expressions.less_than("id", 5),
                                                  Expressions.greater_than_or_equal("id", 30))).eval(strict_file)
def test_not_eq_rewritten(strict_schema, strict_file):
    assert StrictMetricsEvaluator(strict_schema, Expressions.not_(Expressions.equal("id", 5))).eval(strict_file)
    assert StrictMetricsEvaluator(strict_schema, Expressions.not_(Expressions.equal("id", 29))).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.not_(Expressions.equal("id", 30))).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.not_(Expressions.equal("id", 75))).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.not_(Expressions.equal("id", 79))).eval(strict_file)
    assert StrictMetricsEvaluator(strict_schema, Expressions.not_(Expressions.equal("id", 80))).eval(strict_file)
    assert StrictMetricsEvaluator(strict_schema, Expressions.not_(Expressions.equal("id", 85))).eval(strict_file)
def test_integer_not_eq(strict_schema, strict_file):
    assert StrictMetricsEvaluator(strict_schema, Expressions.not_equal("id", 5)).eval(strict_file)
    assert StrictMetricsEvaluator(strict_schema, Expressions.not_equal("id", 29)).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.not_equal("id", 30)).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.not_equal("id", 75)).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.not_equal("id", 79)).eval(strict_file)
    assert StrictMetricsEvaluator(strict_schema, Expressions.not_equal("id", 80)).eval(strict_file)
    assert StrictMetricsEvaluator(strict_schema, Expressions.not_equal("id", 85)).eval(strict_file)
def test_zero_record_file(strict_schema, empty):

    exprs = [Expressions.less_than("no_stats", 5),
             Expressions.less_than_or_equal("no_stats", 30),
             Expressions.equal("no_stats", 70),
             Expressions.greater_than("no_stats", 78),
             Expressions.greater_than_or_equal("no_stats", 90),
             Expressions.not_equal("no_stats", 101),
             Expressions.is_null("no_stats"),
             Expressions.not_null("no_stats")]
    for expr in exprs:
        assert StrictMetricsEvaluator(strict_schema, expr).eval(empty)
def test_missing_stats(strict_schema, missing_stats):
    exprs = [Expressions.less_than("no_stats", 5),
             Expressions.less_than_or_equal("no_stats", 30),
             Expressions.equal("no_stats", 70),
             Expressions.greater_than("no_stats", 78),
             Expressions.greater_than_or_equal("no_stats", 90),
             Expressions.not_equal("no_stats", 101),
             Expressions.is_null("no_stats"),
             Expressions.not_null("no_stats")]

    for expr in exprs:
        assert not StrictMetricsEvaluator(strict_schema, expr).eval(missing_stats)
def test_not(strict_schema, strict_file):
    assert StrictMetricsEvaluator(strict_schema,
                                  Expressions.not_(Expressions.less_than("id", 5))).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema,
                                      Expressions.not_(Expressions.greater_than("id", 5))).eval(strict_file)
def test_missing_column(strict_schema, strict_file):
    with raises(ValidationException):
        StrictMetricsEvaluator(strict_schema, Expressions.less_than("missing", 5)).eval(strict_file)
def test_required_columns(strict_schema, strict_file):
    assert StrictMetricsEvaluator(strict_schema, Expressions.not_null("required")).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.is_null("required")).eval(strict_file)
def test_no_nulls(strict_schema, strict_file):
    assert StrictMetricsEvaluator(strict_schema, Expressions.is_null("all_nulls")).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.is_null("some_nulls")).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.is_null("no_nulls")).eval(strict_file)
def test_integer_gt_eq(strict_schema, strict_file):
    assert not StrictMetricsEvaluator(strict_schema, Expressions.greater_than_or_equal("id", 80)).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.greater_than_or_equal("id", 79)).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.greater_than_or_equal("id", 31)).eval(strict_file)
    assert StrictMetricsEvaluator(strict_schema, Expressions.greater_than_or_equal("id", 30)).eval(strict_file)
def test_integer_gt(strict_schema, strict_file):
    assert not StrictMetricsEvaluator(strict_schema, Expressions.greater_than("id", 79)).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.greater_than("id", 78)).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.greater_than("id", 30)).eval(strict_file)
    assert StrictMetricsEvaluator(strict_schema, Expressions.greater_than("id", 29)).eval(strict_file)
def test_integer_lt(strict_schema, strict_file):
    assert not StrictMetricsEvaluator(strict_schema, Expressions.less_than("id", 5)).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.less_than("id", 31)).eval(strict_file)
    assert not StrictMetricsEvaluator(strict_schema, Expressions.less_than("id", 79)).eval(strict_file)
    assert StrictMetricsEvaluator(strict_schema, Expressions.less_than("id", 80)).eval(strict_file)