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'))
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"])))
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)
def test_parse_field_eq_ip(): assert_equal(parse_binary_condition('@asdf == 2.3.4.5'), GenericBinaryCondition(Field('asdf'), '==', "2.3.4.5"))
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')))
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'))
def test_or_condition1(): e = Equals(Field('x'), 2) assert_equal( e , or_condition([e]))
def test_or_condition_many(): cs = [Equals(Field('x'), 2), Equals('y', 3)] assert_equal( cs , or_condition([cs]))
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')), [])
def test_and_repr(): a = And([Equals(Field('x'), 2)]) assert_equal( a , eval(repr(a)))
def test_and_fields(): a = And([Equals(Field('x'), 2)]) assert_equal( [Field('x')] , list(a.fields))
def test_and_map(): x = And([Equals(Field('x'), 2)]) actual = x.map(flip) expected = Or([Equals(Field('x'), 4)]) assert_equal( actual , expected)
def test_parse_field_eq_float(): assert_equal(parse_binary_condition('@asdf == 2.03'), GenericBinaryCondition(Field('asdf'), '==', 2.03))
def test_and_map_leaves(): a = And([Equals(Field('x'), 2)]) assert_equal( And([Equals(Field('x'), 4)]) , a.map_leaves(flip))
def test_parse_field_eq_star(): assert_equal(parse_binary_condition('@asdf == "*test*"'), GenericBinaryCondition(Field('asdf'), '==', "*test*"))
def test_or_fields(): c = Or([Equals(Field('x'), 2)]) assert_equal( [Field('x')] , list(c.fields))
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)