示例#1
0
def test_not() -> None:
    assert_round_trip(not_term,
                      (P.with_id("foo") | P.of_kind("bla")).not_term())
    assert_round_trip(not_term, P.of_kind("bla").not_term())
    assert_round_trip(
        not_term,
        term_parser.parse(
            "not(is(a) or not is(b) and not a>1 or not b<2 or not(a>1))"))
示例#2
0
def test_filter_term() -> None:
    assert_round_trip(term_parser, P("mem") < 23)
    assert_round_trip(term_parser, P.with_id("foo"))
    assert_round_trip(term_parser, P.of_kind("foo"))
    assert_round_trip(term_parser, P.of_kind("foo") | P.of_kind("bla"))
    assert_round_trip(
        term_parser,
        ((P.of_kind("foo") | P.of_kind("bla")) & (P("a") > 23)) &
        (P("b").is_in([1, 2, 3])) & (P("c") == {
            "a": 123
        }),
    )
示例#3
0
def test_not() -> None:
    assert_round_trip(not_term,
                      (P.with_id("foo") | P.of_kind("bla")).not_term())
    assert_round_trip(not_term, P.of_kind("bla").not_term())
    assert_round_trip(
        not_term,
        term_parser.parse(
            "not(is(a) or not is(b) and not a>1 or not b<2 or not(a>1))"))
    # make sure not only negates the simple term, not the combined term
    assert term_parser.parse("not a==b and b==c") == CombinedTerm(
        NotTerm(P("a") == "b"), "and",
        P("b") == "c")
示例#4
0
def test_part() -> None:
    assert_round_trip(part_parser, Part(P.of_kind("test")))
    assert_round_trip(
        part_parser,
        Part(P.of_kind("test"),
             navigation=Navigation(1, 10, [EdgeType.delete])))
    assert_round_trip(
        part_parser,
        Part(P.of_kind("test"),
             "red",
             navigation=Navigation(1, 10, [EdgeType.delete])))
    with_clause = WithClause(WithClauseFilter("==", 0),
                             Navigation(maybe_edge_types=[EdgeType.delete]))
    assert_round_trip(
        part_parser,
        Part(P.of_kind("test"),
             "green",
             with_clause,
             navigation=Navigation(1, 10, [EdgeType.delete])))
示例#5
0
def simple_reference() -> None:
    # only kind
    Query.by("ec2")

    # equality
    Query.by(P.of_kind("ec2") & (P("simple") == "hallo"))
    Query.by(P.of_kind("ec2") & (P("simple") != "hallo"))

    # regex
    Query.by(P.of_kind("ec2") & P("simple").matches("^some.regex[a-d]+$"))
    Query.by(P.of_kind("ec2") & P("simple").not_matches("^some.regex[a-d]+$"))

    # comparator
    Query.by(P.of_kind("ec2") & (P("num") > 23))
    Query.by(P.of_kind("ec2") & (P("num") >= 23))
    Query.by(P.of_kind("ec2") & (P("num") == 23))
    Query.by(P.of_kind("ec2") & (P("num") <= 23))
    Query.by(P.of_kind("ec2") & (P("num") < 23))

    # in set
    Query.by(P.of_kind("ec2") & P("num").is_in([1, 2, 5]))
    Query.by(P.of_kind("ec2") & P("num").is_not_in([1, 2, 5]))

    # array: all above operators are available
    Query.by(P.of_kind("ec2") & (P.array("some.array").for_all() > 12.23))
    Query.by(
        P.of_kind("ec2") & (P.array("some.array").for_any().is_in([1, 2, 3])))
    Query.by(P.of_kind("ec2") & (P.array("some.array").for_none() == 5))

    # call a function
    Query.by(P.function("in_subnet").on("ip", "1.2.3.4/16"))

    # refine with multiple predicates (all predicates have to match)
    Query.by(
        P.of_kind("ec2") & P("a").ge(1),
        P("b") == 2,
        P("c").matches("aaa"))
示例#6
0
def test_combined() -> None:
    assert_round_trip(combined_term, P.of_kind("foo") | P.of_kind("bla"))
示例#7
0
def test_kind() -> None:
    assert_round_trip(is_term, P.of_kind("foo"))