Example #1
0
 def get_random_comparator(self, node):
     if self.randomize():
         comp = random.randint(1, 4)
         if comp == 1:
             op = _ast.Lt()
         elif comp == 2:
             op = _ast.LtE()
         elif comp == 3:
             op = _ast.Gt()
         else:
             op = _ast.GtE()
         return ast.copy_location(op, node)
     else:
         return node
Example #2
0
def newOp(c):
    if type(c) == type(_ast.Lt()):
        return _ast.GtE()
    elif type(c) == type(_ast.Gt()):
        return _ast.LtE()
    elif type(c) == type(_ast.GtE()):
        return _ast.Lt()
    elif type(c) == type(_ast.LtE()):
        return _ast.Gt()
    elif type(c) == type(_ast.Eq()):
        return _ast.NotEq()
    elif type(c) == type(_ast.NotEq()):
        return _ast.Eq()
    elif type(c) == type(_ast.Is()):
        return _ast.IsNot()
    elif type(c) == type(_ast.IsNot()):
        return _ast.Is()
    elif type(c) == type(_ast.In()):
        return _ast.NotIn()
    elif type(c) == type(_ast.NotIn()):
        return _ast.In()
    else:
        return c
Example #3
0
 def test_simple_sums(self):
     ast = self.ast
     mod = self.get_ast("x = 4 + 5")
     expr = mod.body[0].value
     assert isinstance(expr, ast.BinOp)
     assert isinstance(expr.op, ast.Add)
     expr.op = ast.Sub()
     assert isinstance(expr.op, ast.Sub)
     co = compile(mod, "<example>", "exec")
     ns = {}
     exec co in ns
     assert ns["x"] == -1
     mod = self.get_ast("4 < 5 < 6", "eval")
     assert isinstance(mod.body, ast.Compare)
     assert len(mod.body.ops) == 2
     for op in mod.body.ops:
         assert isinstance(op, ast.Lt)
     mod.body.ops[0] = ast.Gt()
     co = compile(mod, "<string>", "eval")
     assert not eval(co)
Example #4
0
def Gt():
    return _ast.Gt()