def flip(x): if isinstance(x, Equals): return Equals(x.lhs, 2 * x.rhs) elif isinstance(x, Or): return And(x.parts) elif isinstance(x, And): return Or(x.parts) else: return x
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_or_repr(): c = Or([Equals(tagged_dim('src:ip'), 2)]) assert_equal( c , eval(repr(c)))
def test_or_fields(): c = Or([Equals(Field('x'), 2)]) assert_equal( [Field('x')] , list(c.fields))
def test_and_map_leaves(): a = And([Equals(Field('x'), 2)]) assert_equal( And([Equals(Field('x'), 4)]) , a.map_leaves(flip))
def test_equals_repr(): c = Equals(tagged_dim('t:d'), 2) assert_equal( c , eval(repr(c)))
def test_and_fields(): a = And([Equals(Field('x'), 2)]) assert_equal( [Field('x')] , list(a.fields))
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_ds_rewrite_tagged_dim_nogbc(): c = Equals(tagged_dim(':ip'), '1.2.3.4') r = ds._rewrite_tagged_dim(c) assert_equal(c, r)
def test_and_repr(): a = And([Equals(Field('x'), 2)]) assert_equal( a , eval(repr(a)))
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_and_map(): x = And([Equals(Field('x'), 2)]) actual = x.map(flip) expected = Or([Equals(Field('x'), 4)]) assert_equal( actual , expected)
def test_or_condition_many(): cs = [Equals(Field('x'), 2), Equals('y', 3)] assert_equal( cs , or_condition([cs]))
def test_and1(): a = Equals(Field('a'), '1') actual = ds._rewrite_outer_and(And([a])) assert_equal(a, actual)