示例#1
0
 def testFormatters(self):
     """Creating a query with raw AST should generate the source."""
     q = query.Query(
         ast.Complement(
             ast.Equivalence(ast.Map(ast.Var("Process"), ast.Var("pid")),
                             ast.Literal(10))))
     self.assertEqual(q.source, "Process.pid != 10")
示例#2
0
    def testOperatorPrecedence(self):
        # Prefix operator, like the unary minus sign, should respect operator
        # precedence order.
        self.assertQueryMatches(
            "-x + y",
            ast.Sum(ast.Product(ast.Literal(-1), ast.Var("x")), ast.Var("y")))

        self.assertQueryMatches(
            "not x and y",
            ast.Intersection(ast.Complement(ast.Var("x")), ast.Var("y")))

        self.assertQueryMatches(
            "x / -f(y) or not z(a, b)",
            ast.Union(
                ast.Quotient(
                    ast.Var("x"),
                    ast.Product(ast.Literal(-1),
                                ast.Apply(ast.Var("f"), ast.Var("y")))),
                ast.Complement(
                    ast.Apply(ast.Var("z"), ast.Var("a"), ast.Var("b")))))
示例#3
0
 def testMultiWordOperators(self):
     self.assertQueryMatches(
         "x not in y",
         ast.Complement(ast.Membership(ast.Var("x"), ast.Var("y"))))
示例#4
0
def ReverseComplementMembership(x, y, **kwargs):
    """Change (x doesn't contain y) to not(y in x)."""
    return ast.Complement(
        ast.Membership(y, x, **kwargs), **kwargs)
示例#5
0
def ComplementMembership(*args, **kwargs):
    """Change (x not in y) to not(x in y)."""
    return ast.Complement(
        ast.Membership(*args, **kwargs), **kwargs)
示例#6
0
def ComplementEquivalence(*args, **kwargs):
    """Change x != y to not(x == y)."""
    return ast.Complement(
        ast.Equivalence(*args, **kwargs), **kwargs)