Пример #1
0
def test_nested_parenthesis_boolean():
    actual = WhereClauseParser.parse(
        to_tokens("(col = 1 and col2=4) or (col = 2 and (col =6 or col=9))"))
    expected = WhereClause(
        BooleanCondition(
            "or",
            Parenthesis(
                BooleanCondition(
                    "and",
                    Condition(Column("col"), "=", Integer(1)),
                    Condition(Column("col2"), "=", Integer(4)),
                )),
            Parenthesis(
                BooleanCondition(
                    "and",
                    Condition(Column("col"), "=", Integer(2)),
                    Parenthesis(
                        BooleanCondition(
                            "or",
                            Condition(Column("col"), "=", Integer(6)),
                            Condition(Column("col"), "=", Integer(9)),
                        )),
                )),
        ))
    assert actual == expected
Пример #2
0
def test_where_clause_keeps_generator_intact_is_null_condition():
    tokens = to_tokens("col is null group by col")
    actual, next_token = WhereClauseParser.parse(tokens)
    expected = WhereClause(Condition(Column("col"), "is", Null()))
    assert actual == expected
    assert next_token == "group"
    assert list(tokens) == ["by", "col"]
Пример #3
0
def test_where_clause_keeps_generator_intact():
    tokens = to_tokens("col = 3 group by col")
    actual, next_token = WhereClauseParser.parse(tokens)
    expected = WhereClause(Condition(Column("col"), "=", Integer(3)))
    assert actual == expected
    assert next_token == "group"
    assert list(tokens) == ["by", "col"]
Пример #4
0
def test_boolean_where_clause():
    actual = WhereClauseParser.parse(to_tokens("col = 3 and field = 5"))
    expected = WhereClause(
        BooleanCondition(
            "and",
            Condition(Column("col"), "=", Integer(3)),
            Condition(Column("field"), "=", Integer(5)),
        ))
    assert actual == expected
Пример #5
0
def test_between_where_clause():
    actual = WhereClauseParser.parse(to_tokens("col between 3 and 5"))
    expected = WhereClause(
        Condition(
            Column("col"),
            "between",
            BooleanCondition(
                "and",
                Integer(3),
                Integer(5),
            ),
        ))
    assert actual == expected
Пример #6
0
def test_multiple_args_boolean_condition():
    actual = WhereClauseParser.parse(
        to_tokens("(col = 1 and col2=4 and col3=4)"))
    expected = WhereClause(
        Parenthesis(
            BooleanCondition(
                "and",
                Condition(Column("col"), "=", Integer(1)),
                BooleanCondition(
                    "and",
                    Condition(Column("col2"), "=", Integer(4)),
                    Condition(Column("col3"), "=", Integer(4)),
                ),
            ), ))
    assert actual == expected
Пример #7
0
def test_parenthesis_boolean_where_clause():
    actual = WhereClauseParser.parse(
        to_tokens("(col = 3 and field = 5) or (f2 or f3)"))
    expected = WhereClause(
        BooleanCondition(
            "or",
            Parenthesis(
                BooleanCondition(
                    "and",
                    Condition(Column("col"), "=", Integer(3)),
                    Condition(Column("field"), "=", Integer(5)),
                )),
            Parenthesis(BooleanCondition("or", Column("f2"), Column("f3"))),
        ))
    assert actual == expected
Пример #8
0
def test_parenthesis_expression_where_clause():
    actual = WhereClauseParser.parse(to_tokens("(col + 1) = col2"))
    expected = WhereClause(
        Condition(Parenthesis(Addition(Column("col"), Integer(1))), "=",
                  Column("col2")))
    assert actual == expected
Пример #9
0
def test_where_different_predicate():
    actual = WhereClauseParser.parse(to_tokens("col <> 3"))
    expected = WhereClause(Condition(Column("col"), "<>", Integer(3)), )
    assert actual == expected
Пример #10
0
def test_where_clause():
    actual = WhereClauseParser.parse(to_tokens("col = 3"))
    expected = WhereClause(Condition(Column("col"), "=", Integer(3)))
    assert actual == expected