예제 #1
0
    def test_branch_true_dead(self):
        "Test branch with the false branch being dead"
        t = ast.Constant(True)
        f = ast.Constant(False)
        l = ast.Literal('foo')
        v = ast.Number(42)
        cmp = ast.CompareOperator('=', l, v)
        n = ast.Branch(f, t, cmp)

        # Should reduce to to the compare
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert r is cmp
예제 #2
0
파일: test_ast.py 프로젝트: dungba88/pypred
    def test_branch(self):
        l = ast.Literal('a')
        r = ast.Literal('b')
        check = ast.CompareOperator('>', l, r)
        true = ast.Constant(True)
        false = ast.Constant(False)
        b = ast.Branch(check, true, false)

        assert b.evaluate(MockPred(), {'a': 2, 'b':1})

        res, ctx = b.analyze(MockPred(), {'a': 1, 'b':2})
        assert not res
        assert ctx.literals["a"] == 1
        assert ctx.literals["b"] == 2
        assert ctx.failed[-1].startswith("Right hand side")