def test_not_between_condition(self): c = PredicatedExpression( Column("x"), BetweenCondition(Literal(3), Literal(6), True)) bindings = dict([('x', 2)]) assert (c.evaluate(bindings) == True) bindings = dict([('x', 4)]) assert (c.evaluate(bindings) == False) bindings = dict([('x', 7)]) assert (c.evaluate(bindings) == True) bindings = dict([('x', None)]) assert (c.evaluate(bindings) == None) c = PredicatedExpression( Column("x"), BetweenCondition(Literal('d'), Literal('h'), True)) bindings = dict([('x', 'a')]) assert (c.evaluate(bindings) == True) bindings = dict([('x', 'e')]) assert (c.evaluate(bindings) == False) bindings = dict([('x', 'v')]) assert (c.evaluate(bindings) == True) bindings = dict([('x', None)]) assert (c.evaluate(bindings) == None) c = PredicatedExpression( Column("x"), BetweenCondition(Literal('2017/01/01'), Literal('2019/01/01'), True)) bindings = dict([('x', '2016/01/01')]) assert (c.evaluate(bindings) == True) bindings = dict([('x', '2018/01/01')]) assert (c.evaluate(bindings) == False) bindings = dict([('x', '2020/01/01')]) assert (c.evaluate(bindings) == True) bindings = dict([('x', None)]) assert (c.evaluate(bindings) == None)
def test_is_condition(self): c = PredicatedExpression(Column("x"), IsCondition(Literal("NULL"), False)) bindings = dict([('x', 2)]) assert (c.evaluate(bindings) == False) bindings = dict([('x', None)]) assert (c.evaluate(bindings) == True) c = PredicatedExpression(Column("x"), IsCondition(Literal(None), False)) bindings = dict([('x', 2)]) assert (c.evaluate(bindings) == False) bindings = dict([('x', None)]) assert (c.evaluate(bindings) == True) c = PredicatedExpression(Column("x"), IsCondition(Literal("TRUE"), False)) bindings = dict([('x', "True")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "true")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "t")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "y")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "yes")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "on")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "1")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', None)]) assert (c.evaluate(bindings) == False) c = PredicatedExpression(Column("x"), IsCondition(Literal("False"), False)) bindings = dict([('x', "False")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "false")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "f")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "n")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "no")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "off")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "0")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', None)]) assert (c.evaluate(bindings) == False)
def test_and(self): for tv, tn in zip(vals_t, names_t): for tvb, tnb in zip(vals_t, names_t): # All True if not (isinstance(tv, str) and isinstance(tvb, str)): assert BooleanCompare(Literal(tv), 'and', Literal(tvb)).evaluate(None) assert BooleanCompare(Column(tn), 'and', Literal(tvb)).evaluate(bindings) assert BooleanCompare(Literal(tv), 'and', Column(tnb)).evaluate(bindings) for fv, fn in zip(vals_f, names_f): # All False if not (isinstance(tv, str) and isinstance(fv, str)): assert not BooleanCompare(Literal(tv), 'and', Literal(fv)).evaluate(None) assert not BooleanCompare(Column(tn), 'and', Literal(fv)).evaluate(bindings) assert not BooleanCompare(Literal(tv), 'and', Column(fn)).evaluate(bindings)
def test_not_in_condition(self): c = PredicatedExpression( Column("x"), InCondition(Seq([Literal(1), Literal(2), Literal(3)]), True)) bindings = dict([('x', 2)]) assert (c.evaluate(bindings) == False) bindings = dict([('x', 2.)]) assert (c.evaluate(bindings) == False) bindings = dict([('x', 7)]) assert (c.evaluate(bindings) == True) bindings = dict([('x', None)]) assert (c.evaluate(bindings) == None) c = PredicatedExpression( Column("x"), InCondition(Seq([Literal("1"), Literal("2"), Literal("3")]), True)) bindings = dict([('x', "2")]) assert (c.evaluate(bindings) == False) bindings = dict([('x', "2.")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', "7")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', None)]) assert (c.evaluate(bindings) == None) c = PredicatedExpression( Column("x"), InCondition(Seq([Literal("2017/01/01"), Literal("2019/01/01")]), True)) bindings = dict([('x', "2017/01/01")]) assert (c.evaluate(bindings) == False) bindings = dict([('x', "2020/01/01")]) assert (c.evaluate(bindings) == True) bindings = dict([('x', None)]) assert (c.evaluate(bindings) == None)
def test_eq(Self): # test numeric values for v5, n5 in zip(vals_5, names_5): # All True for v5b, n5b in zip(vals_5, names_5): if not (isinstance(v5, str) and isinstance(v5b, str)): assert (BooleanCompare(Literal(v5), '=', Literal(v5b)).evaluate(None)) assert (BooleanCompare(Column(n5), '=', Literal(v5b)).evaluate(bindings)) assert (BooleanCompare(Literal(v5), '=', Column(n5b)).evaluate(bindings)) # All False for v7, n7 in zip(vals_7, names_7): if not (isinstance(v5, str) and isinstance(v7, str)): assert (not BooleanCompare(Literal(v5), '=', Literal(v7)).evaluate(None)) assert (not BooleanCompare(Column(n5), '=', Literal(v7)).evaluate(bindings)) assert (not BooleanCompare(Literal(v5), '=', Column(n7)).evaluate(bindings)) # test dates for d1, n1 in zip(vals_d1, names_d1): for d1b, n1b in zip(vals_d1, names_d1): # all True comp = BooleanCompare(Literal(d1b), '=', Literal(d1)) assert (comp.evaluate(None)) comp = BooleanCompare(Column(n1b), '=', Literal(d1)) assert (comp.evaluate(bindings)) comp = BooleanCompare(Literal(d1b), '=', Column(n1)) assert (comp.evaluate(bindings)) for d2, n2 in zip(vals_d2, names_d2): # all False comp = BooleanCompare(Literal(d1), '=', Literal(d2)) assert (not comp.evaluate(None)) comp = BooleanCompare(Column(n1), '=', Literal(d2)) assert (not comp.evaluate(bindings)) comp = BooleanCompare(Literal(d1), '=', Column(n2)) assert (not comp.evaluate(bindings)) # test strings # All True assert (BooleanCompare(Literal(vals_str[0]), '=', Literal(vals_str[0])).evaluate(None)) assert (BooleanCompare(Column(names_str[0]), '=', Literal(vals_str[0])).evaluate(bindings)) assert (BooleanCompare(Literal(vals_str[0]), '=', Column(names_str[0])).evaluate(bindings)) # All False assert (not BooleanCompare(Literal(vals_str[1]), '=', Literal(vals_str[0])).evaluate(None)) assert (not BooleanCompare(Column(names_str[1]), '=', Literal(vals_str[0])).evaluate(bindings)) assert (not BooleanCompare(Literal(vals_str[1]), '=', Column(names_str[0])).evaluate(bindings))
def test_lt(self): # test numeric values for v5, n5 in zip(vals_5, names_5): for v7, n7 in zip(vals_7, names_7): # all False comp = BooleanCompare(Literal(v7), '<', Literal(v5)) assert (not comp.evaluate(None)) comp = BooleanCompare(Column(n7), '<', Literal(v5)) assert (not comp.evaluate(bindings)) comp = BooleanCompare(Literal(v7), '<', Column(n5)) assert (not comp.evaluate(bindings)) # all True comp = BooleanCompare(Literal(v5), '<', Literal(v7)) assert (comp.evaluate(None)) comp = BooleanCompare(Column(n5), '<', Literal(v7)) assert (comp.evaluate(bindings)) comp = BooleanCompare(Literal(v5), '<', Column(n7)) assert (comp.evaluate(bindings)) # test dates for d1, n1 in zip(vals_d1, names_d1): for d2, n2 in zip(vals_d2, names_d2): # all False comp = BooleanCompare(Literal(d2), '<', Literal(d1)) assert (not comp.evaluate(None)) comp = BooleanCompare(Column(n2), '<', Literal(d1)) assert (not comp.evaluate(bindings)) comp = BooleanCompare(Literal(d2), '<', Column(n1)) assert (not comp.evaluate(bindings)) # all True comp = BooleanCompare(Literal(d1), '<', Literal(d2)) assert (comp.evaluate(None)) comp = BooleanCompare(Column(n1), '<', Literal(d2)) assert (comp.evaluate(bindings)) comp = BooleanCompare(Literal(d1), '<', Column(n2)) assert (comp.evaluate(bindings)) # test strings # All False assert (not BooleanCompare(Literal(vals_str[0]), '<', Literal(vals_str[1])).evaluate(None)) assert (not BooleanCompare(Column(names_str[0]), '<', Literal(vals_str[1])).evaluate(bindings)) assert (not BooleanCompare(Literal(vals_str[0]), '<', Column(names_str[1])).evaluate(bindings)) # All True assert (BooleanCompare(Literal(vals_str[1]), '<', Literal(vals_str[0])).evaluate(None)) assert (BooleanCompare(Column(names_str[1]), '<', Literal(vals_str[0])).evaluate(bindings)) assert (BooleanCompare(Literal(vals_str[1]), '<', Column(names_str[0])).evaluate(bindings))