def UNPACK_SEQUENCE(self, instr):
        nargs = instr.oparg

        nodes = []
        ast_tuple = _ast.Tuple(elts=nodes, ctx=_ast.Store(), lineno=instr.lineno, col_offset=0)
        for i in range(nargs):
            nex_instr = self.ilst.pop(0)
            self.ast_stack.append(None)
            self.visit(nex_instr)

            node = self.ast_stack.pop()
            nodes.append(node.targets[0])

        expr = self.ast_stack.pop()
        if isinstance(expr, _ast.Assign):
            assgn = expr 
            assgn.targets.append(ast_tuple)
            
            value_dup = self.ast_stack.pop()
            
            assert cmp_ast(assgn.value, value_dup)
            
        else:
            assgn = _ast.Assign(targets=[ast_tuple], value=expr, lineno=instr.lineno, col_offset=0)
        self.ast_stack.append(assgn)
    def UNPACK_SEQUENCE(self, instr):
        nargs = instr.oparg

        nodes = []
        ast_tuple = _ast.Tuple(elts=nodes,
                               ctx=_ast.Store(),
                               lineno=instr.lineno,
                               col_offset=0)
        for i in range(nargs):
            nex_instr = self.ilst.pop(0)
            self.ast_stack.append(None)
            self.visit(nex_instr)

            node = self.ast_stack.pop()
            nodes.append(node.targets[0])

        expr = self.ast_stack.pop()
        if isinstance(expr, _ast.Assign):
            assgn = expr
            assgn.targets.append(ast_tuple)

            value_dup = self.ast_stack.pop()

            assert cmp_ast(assgn.value, value_dup)

        else:
            assgn = _ast.Assign(targets=[ast_tuple],
                                value=expr,
                                lineno=instr.lineno,
                                col_offset=0)
        self.ast_stack.append(assgn)
Exemple #3
0
def assert_ast_eq(testcase, orig_ast, expected_ast):
    
    if not cmp_ast(orig_ast, expected_ast):
        str1 = str_ast(orig_ast, indent=' ', newline='\n')
        str2 = str_ast(expected_ast, indent=' ', newline='\n')
        msg = 'AST Trees are not equal\n## left ########### \n%s\n## right ########### \n%s' % (str1, str2)
        testcase.fail(msg)
Exemple #4
0
def assert_ast_eq(testcase, orig_ast, expected_ast):

    if not cmp_ast(orig_ast, expected_ast):
        str1 = str_ast(orig_ast, indent=' ', newline='\n')
        str2 = str_ast(expected_ast, indent=' ', newline='\n')
        msg = 'AST Trees are not equal\n## left ########### \n%s\n## right ########### \n%s' % (
            str1, str2)
        testcase.fail(msg)
Exemple #5
0
    def assertAstEqual(self, left, right):

        if not isinstance(left, _ast.AST):
            raise self.failureException("%s is not an _ast.AST instance" % (left))
        if not isinstance(right, _ast.AST):
            raise self.failureException("%s is not an _ast.AST instance" % (right))
        result = cmp_ast(left, right)

        if not result:
            
            lstream = StringIO()
            print_ast(left, indent='', file=lstream, newline='')

            rstream = StringIO()
            print_ast(right, indent='', file=rstream, newline='')

            lstream.seek(0)
            rstream.seek(0)
            msg = 'Ast Not Equal:\nGenerated: %r\nExpected:  %r' % (lstream.read(), rstream.read())
            raise self.failureException(msg)
    def STORE_SLICE_3(self, instr):
        'obj[lower:upper] = expr'

        upper = self.ast_stack.pop()
        lower = self.ast_stack.pop()
        value = self.ast_stack.pop()
        expr = self.ast_stack.pop()
        
        kw = dict(lineno=instr.lineno, col_offset=0)
        slice = _ast.Slice(lower=lower, step=None, upper=upper, **kw)
        subscr = _ast.Subscript(value=value, slice=slice, ctx=_ast.Store(), **kw)
        
        if isinstance(expr, _ast.AugAssign):
            assign = expr
            result = cmp_ast(expr.target, subscr)
            
            assert result
        else:
            assign = _ast.Assign(targets=[subscr], value=expr, **kw)
            
        self.ast_stack.append(assign)
    def STORE_SLICE_3(self, instr):
        'obj[lower:upper] = expr'

        upper = self.ast_stack.pop()
        lower = self.ast_stack.pop()
        value = self.ast_stack.pop()
        expr = self.ast_stack.pop()

        kw = dict(lineno=instr.lineno, col_offset=0)
        slice = _ast.Slice(lower=lower, step=None, upper=upper, **kw)
        subscr = _ast.Subscript(value=value,
                                slice=slice,
                                ctx=_ast.Store(),
                                **kw)

        if isinstance(expr, _ast.AugAssign):
            assign = expr
            result = cmp_ast(expr.target, subscr)

            assert result
        else:
            assign = _ast.Assign(targets=[subscr], value=expr, **kw)

        self.ast_stack.append(assign)