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"))
def test_parse_predicate_array() -> None: assert_round_trip(predicate_term, P.array("mem").for_any() < 23) assert_round_trip(predicate_term, P.array("mem").for_all() >= 23) assert_round_trip(predicate_term, P.array("mem").for_none().matches("foo.*")) assert_round_trip(predicate_term, P.array("num").for_any().is_in([1, 2, 5])) assert_round_trip(predicate_term, P.array("num").for_all().is_in([1, 2, 5])) assert_round_trip(predicate_term, P.array("num").for_none().is_in([1, 2, 5]))