def test_tagged_dim_matchs():
    # not in table metadata
    assert_true(not tm.tagged_dim_matches(tagged_dim(':'), Field('ip_addr')))

    assert_true(tm.tagged_dim_matches(tagged_dim(':'), Field('clientip')))
    assert_true(tm.tagged_dim_matches(tagged_dim(':ip'), Field('clientip')))
    assert_true(
        not tm.tagged_dim_matches(tagged_dim(':mac'), Field('clientip')))
def test_ds_rewrite_tagged_dim_to_or():
    c = gbceq(tagged_dim(':ip'), '1.2.3.4')
    r = ds._rewrite_tagged_dim(c)
    expected = Or([
        gbceq(Field('clientip'), '1.2.3.4'),
        gbceq(Field('serverip'), '1.2.3.4')
    ])
    assert_equal(expected, r)
def test_field_selector():
    assert_equal(field_or_tagged_dim(' @f '), Field('f'))
    assert_equal(field_or_tagged_dim(Field('f')), Field('f'))

    assert_equal(field_or_tagged_dim('tag:dim'), tagged_dim('tag:dim'))
    assert_equal(field_or_tagged_dim(['tag', 'dim']), tagged_dim('tag:dim'))

    assert_equal(field_or_tagged_dim(tagged_dim('tag:dim')),
                 tagged_dim('tag:dim'))
Beispiel #4
0
def test_parse_tagdim_field_list_fields1():
    def f(x):
        res = parse_list_fieldselectors(x)
        return res

    assert_equal(f("*"), [])
    assert_equal(f(""), [])
    assert_equal(f("@F"), [Field('F')])
    assert_equal(f("@F,@G"), [Field('F'), Field('G')])
    assert_equal(f(":dim"), [tagged_dim("dim")])
    assert_equal(f("tag:,:dim"), [tagged_dim('tag:'), tagged_dim("dim")])
def test_rewrite_set():
    #    c = GenericSetCondition(Field('a'), '==', [])
    #    res = ds._rewrite_generic_set_condition(c)
    assert_equal(
        TrueCondition(),
        ds._rewrite_generic_set_condition(
            GenericSetCondition(Field('a'), '==', [])))

    assert_equal(
        GenericBinaryCondition(Field('a'), '==', "foo"),
        ds._rewrite_generic_set_condition(
            GenericSetCondition(Field('a'), '==', ["foo"])))

    assert_equal(
        Or([
            GenericBinaryCondition(Field('a'), '==', "foo"),
            GenericBinaryCondition(Field('a'), '==', "bar")
        ]),
        ds._rewrite_generic_set_condition(
            GenericSetCondition(Field('a'), '==', ["foo", "bar"])))
Beispiel #6
0
def test_or_leaves_map():
    c = Or([Equals(Field('x'), 2)])
    actual = c.map_leaves(flip)
    expected = Or([Equals(Field('x'), 4)])
    assert_equal( actual , expected)
def test_and_rparen():
    a = Equals(Field('a'), '1')
    b = Equals(Field('b'), '1')
    c = Equals(Field('d'), '1')
    actual = ds._rewrite_outer_and(And([And([a, b]), c]))
    assert_equal(And([a, b, c]), actual)
Beispiel #8
0
def test_parse_field_eq_ip():
    assert_equal(parse_binary_condition('@asdf == 2.3.4.5'),
                 GenericBinaryCondition(Field('asdf'), '==', "2.3.4.5"))
Beispiel #9
0
def test_parse_field_eq_quote():
    assert_equal(parse_binary_condition("@asdf == 'asdf'"),
                 GenericBinaryCondition(Field('asdf'), '==', "asdf"))
def test_has_field():
    assert_true(tm.has_field(Field('clientip')))
    assert_true(not tm.has_field(Field('asdf')))
Beispiel #11
0
def test_field_strips_at():
    assert_equal(field('@f'), Field('f'))
def test_ds_remove_generic_binary_condition_unsupported_op():
    c = GenericBinaryCondition(Field('f'), '<>', '23')
    ds._rewrite_generic_binary_condition(c)
def test_ds_unnecessary_remove_generic_binary_condition():
    c = Equals(Field('f'), '23')
    r = ds._rewrite_generic_binary_condition(c)
    assert_equal(c, r)
def test_ds_remove_generic_binary_condition():
    c = GenericBinaryCondition(Field('f'), '==', '23')
    r = ds._rewrite_generic_binary_condition(c)
    assert_equal(r, Equals(Field('f'), '23'))
def test_check_fields():
    ds._check_fields(Equals(Field('a'), '1'))
Beispiel #16
0
def test_or_condition1():
    e = Equals(Field('x'), 2)
    assert_equal( e , or_condition([e]))
Beispiel #17
0
def test_or_condition_many():
    cs = [Equals(Field('x'), 2), Equals('y', 3)]
    assert_equal( cs , or_condition([cs]))
Beispiel #18
0
def test_field_repr():
    r = Field('f')
    assert_equal(r, eval(repr(r)))
def test_fields_matching():
    assert_equal(tm.fields_matching(Field('clientip')), [Field('clientip')])
    assert_equal(tm.fields_matching('@clientip'), [Field('clientip')])
    assert_equal(tm.fields_matching(tagged_dim(':ip')), [Field('clientip')])
    assert_equal(tm.fields_matching(tagged_dim(':mac')), [])
Beispiel #20
0
def test_and_repr():
    a = And([Equals(Field('x'), 2)])
    assert_equal( a , eval(repr(a)))
Beispiel #21
0
def test_and_fields():
    a = And([Equals(Field('x'), 2)])
    assert_equal( [Field('x')] , list(a.fields))
Beispiel #22
0
def test_and_map():
    x = And([Equals(Field('x'), 2)])
    actual = x.map(flip)
    expected = Or([Equals(Field('x'), 4)])
    assert_equal( actual , expected)
Beispiel #23
0
def test_parse_field_eq_float():
    assert_equal(parse_binary_condition('@asdf == 2.03'),
                 GenericBinaryCondition(Field('asdf'), '==', 2.03))
Beispiel #24
0
def test_and_map_leaves():
    a = And([Equals(Field('x'), 2)])
    assert_equal( And([Equals(Field('x'), 4)]) , a.map_leaves(flip))
Beispiel #25
0
def test_parse_field_eq_star():
    assert_equal(parse_binary_condition('@asdf == "*test*"'),
                 GenericBinaryCondition(Field('asdf'), '==', "*test*"))
Beispiel #26
0
def test_or_fields():
    c = Or([Equals(Field('x'), 2)])
    assert_equal( [Field('x')] , list(c.fields))
Beispiel #27
0
def test_parse_rhs_valueset():
    assert_equal(GenericSetCondition(Field('asdf'), '==', [91, 92, 93]),
                 parse_binary_condition('@asdf == {91,92,93}'))
def test_and1():
    a = Equals(Field('a'), '1')
    actual = ds._rewrite_outer_and(And([a]))
    assert_equal(a, actual)