

def test_order_rewrite_numeric(self):
    'Tests rewrite of numeric values'
    l = ast.Literal('foo')
    v = ast.Number(25)
    v1 = ast.Number(50)
    v2 = ast.Number(75)
    v3 = ast.Number(100)
    cmp1 = ast.CompareOperator('<', l, v)
    cmp2 = ast.CompareOperator('>=', l, v1)
    cmp3 = ast.CompareOperator('>', l, v2)
    cmp4 = ast.CompareOperator('<=', l, v3)
    or1 = ast.LogicalOperator('or', cmp1, cmp2)
    or2 = ast.LogicalOperator('or', cmp3, cmp4)
    or3 = ast.LogicalOperator('or', or1, or2)
    name = merge.node_name(cmp1, True)
    r = compare.order_rewrite(ast.dup(or3), name, cmp1, True)
    assert isinstance(r.left.left, ast.Constant)
    assert (r.left.left.value == True)
    assert isinstance(r.left.right, ast.Constant)
    assert (r.left.right.value == False)
    assert isinstance(r.right.left, ast.Constant)
    assert (r.right.left.value == False)
    assert isinstance(r.right.right, ast.Constant)
    assert (r.right.right.value == True)
    name = merge.node_name(cmp1, True)
    r = compare.order_rewrite(ast.dup(or3), name, cmp1, False)
    assert isinstance(r.left.left, ast.Constant)
    assert (r.left.left.value == False)
    assert ASTPattern(cmp2).matches(r.left.right)
    assert ASTPattern(cmp3).matches(r.right.left)
    assert ASTPattern(cmp4).matches(r.right.right)
    name = merge.node_name(cmp2, True)
    r = compare.order_rewrite(ast.dup(or3), name, cmp2, True)
    assert isinstance(r.left.left, ast.Constant)
    assert (r.left.left.value == False)
    assert isinstance(r.left.right, ast.Constant)
    assert (r.left.right.value == True)
    assert ASTPattern(cmp3).matches(r.right.left)
    assert ASTPattern(cmp4).matches(r.right.right)
    name = merge.node_name(cmp2, True)
    r = compare.order_rewrite(ast.dup(or3), name, cmp2, False)
    assert ASTPattern(cmp1).matches(r.left.left)
    assert isinstance(r.left.right, ast.Constant)
    assert (r.left.right.value == False)
    assert isinstance(r.right.left, ast.Constant)
    assert (r.right.left.value == False)
    assert isinstance(r.right.right, ast.Constant)
    assert (r.right.right.value == True)
    name = merge.node_name(cmp3, True)
    r = compare.order_rewrite(ast.dup(or3), name, cmp3, True)
    assert isinstance(r.left.left, ast.Constant)
    assert (r.left.left.value == False)
    assert isinstance(r.left.right, ast.Constant)
    assert (r.left.right.value == True)
    assert isinstance(r.right.left, ast.Constant)
    assert (r.right.left.value == True)
    assert ASTPattern(cmp4).matches(r.right.right)
    name = merge.node_name(cmp3, True)
    r = compare.order_rewrite(ast.dup(or3), name, cmp3, False)
    assert ASTPattern(cmp1).matches(r.left.left)
    assert ASTPattern(cmp2).matches(r.left.right)
    assert isinstance(r.right.left, ast.Constant)
    assert (r.right.left.value == False)
    assert isinstance(r.right.right, ast.Constant)
    assert (r.right.right.value == True)
    name = merge.node_name(cmp4, True)
    r = compare.order_rewrite(ast.dup(or3), name, cmp4, True)
    assert ASTPattern(cmp1).matches(r.left.left)
    assert ASTPattern(cmp2).matches(r.left.right)
    assert ASTPattern(cmp3).matches(r.right.left)
    assert isinstance(r.right.right, ast.Constant)
    assert (r.right.right.value == True)
    name = merge.node_name(cmp4, True)
    r = compare.order_rewrite(ast.dup(or3), name, r, False)
    assert isinstance(r.left.left, ast.Constant)
    assert (r.left.left.value == False)
    assert isinstance(r.left.right, ast.Constant)
    assert (r.left.right.value == True)
    assert isinstance(r.right.left, ast.Constant)
    assert (r.right.left.value == True)
    assert isinstance(r.right.right, ast.Constant)
    assert (r.right.right.value == False)

dataset/ETHPy150Open armon/pypred/tests/unit/test_compare.py TestCompare.test_order_rewrite_numeric/VarMisuse@1003/1125 `cmp4`->`r`