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_map(): c = Or([Equals(Field('x'), 2)]) actual = c.map(flip) expected = And([Equals(Field('x'), 4)]) assert_equal( actual , expected)
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_and_map_leaves(): a = And([Equals(Field('x'), 2)]) assert_equal( And([Equals(Field('x'), 4)]) , a.map_leaves(flip))
def test_and_fields(): a = And([Equals(Field('x'), 2)]) assert_equal( [Field('x')] , list(a.fields))
def test_and_repr(): a = And([Equals(Field('x'), 2)]) assert_equal( a , eval(repr(a)))
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_and1(): a = Equals(Field('a'), '1') actual = ds._rewrite_outer_and(And([a])) assert_equal(a, actual)
def test_and0(): actual = ds._rewrite_outer_and(And([])) assert_equal(TrueCondition(), actual)