def __init__(self, base_node):
        BaseMutator.__init__(self, base_node)
        self.original_bin_op = base_node.op

        if type(base_node.op) in [ast.Add, ast.Sub, ast.Mult, ast.Div, ast.Mod, ast.Pow]:
            if type(base_node.op) is ast.Add:
                # Don't perform the mutation for string concatenation (e.g. 'string' + 'concat')
                if (type(base_node.left) is not ast.Str) and (type(base_node.right) is not ast.Str):
                    self.mutations.append({"op": ast.Sub()})

            if type(base_node.op) is ast.Sub:
                self.mutations.append({"op": ast.Add()})

            if type(base_node.op) is ast.Mult:
                # Don't perform the mutation for string repetition (e.g. 'string' * 50)
                if (type(base_node.left) is not ast.Str) and (type(base_node.right) is not ast.Str):
                    self.mutations.append({"op": ast.Div()})

            if type(base_node.op) is ast.Div:
                self.mutations.append({"op": ast.Mult()})

            if type(base_node.op) is ast.Mod:
                # Don't perform the mutation for string format (e.g. 'strings are %s' % 'cool')
                if (type(base_node.left) is not ast.Str) and (type(base_node.right) is not ast.Str):
                    self.mutations.append({"op": ast.Pow()})

            if type(base_node.op) is ast.Pow:
                self.mutations.append({"op": ast.Mod()})
Esempio n. 2
0
    def __init__(self, base_node):
        BaseMutator.__init__(self, base_node)
        self.original_ops = base_node.ops

        index_count = 0
        for op in base_node.ops:

            if type(op) in [ast.Gt, ast.GtE, ast.Lt, ast.LtE]:
                if type(op) is ast.Gt:
                    ops_mutant_Gt = copy.deepcopy(base_node.ops)
                    ops_mutant_Gt[index_count] = ast.GtE()
                    self.mutations.append({"ops": ops_mutant_Gt})

                if type(op) is ast.GtE:
                    ops_mutant_GtE = copy.deepcopy(base_node.ops)
                    ops_mutant_GtE[index_count] = ast.Gt()
                    self.mutations.append({"ops": ops_mutant_GtE})

                if type(op) is ast.Lt:
                    ops_mutant_Lt = copy.deepcopy(base_node.ops)
                    ops_mutant_Lt[index_count] = ast.LtE()
                    self.mutations.append({"ops": ops_mutant_Lt})

                if type(op) is ast.LtE:
                    ops_mutant_LtE = copy.deepcopy(base_node.ops)
                    ops_mutant_LtE[index_count] = ast.Lt()
                    self.mutations.append({"ops": ops_mutant_LtE})

            index_count += 1
    def __init__(self, base_node):
        BaseMutator.__init__(self, base_node)
        self.original_bin_op = base_node.op

        if type(base_node.op) in [
                ast.LShift, ast.RShift, ast.BitOr, ast.BitXor, ast.BitAnd,
                ast.FloorDiv
        ]:
            if type(base_node.op) is ast.LShift:
                self.mutations.append({"op": ast.RShift()})

            if type(base_node.op) is ast.RShift:
                self.mutations.append({"op": ast.LShift()})

            if type(base_node.op) is ast.BitOr:
                self.mutations.append({"op": ast.BitAnd()})

            if type(base_node.op) is ast.BitXor:
                self.mutations.append({"op": ast.FloorDiv()})

            if type(base_node.op) is ast.BitAnd:
                self.mutations.append({"op": ast.BitOr()})

            if type(base_node.op) is ast.FloorDiv:
                self.mutations.append({"op": ast.BitXor()})
    def __init__(self, base_node):
        BaseMutator.__init__(self, base_node)
        self.original_bin_op = base_node.op

        if type(base_node.op) in [
                ast.Add, ast.Sub, ast.Mult, ast.Div, ast.Mod, ast.Pow
        ]:
            if type(base_node.op) is ast.Add:
                # Don't perform the mutation for string concatenation (e.g. 'string' + 'concat')
                if (type(base_node.left) is not ast.Str) and (type(
                        base_node.right) is not ast.Str):
                    self.mutations.append({"op": ast.Sub()})

            if type(base_node.op) is ast.Sub:
                self.mutations.append({"op": ast.Add()})

            if type(base_node.op) is ast.Mult:
                # Don't perform the mutation for string repetition (e.g. 'string' * 50)
                if (type(base_node.left) is not ast.Str) and (type(
                        base_node.right) is not ast.Str):
                    self.mutations.append({"op": ast.Div()})

            if type(base_node.op) is ast.Div:
                self.mutations.append({"op": ast.Mult()})

            if type(base_node.op) is ast.Mod:
                # Don't perform the mutation for string format (e.g. 'strings are %s' % 'cool')
                if (type(base_node.left) is not ast.Str) and (type(
                        base_node.right) is not ast.Str):
                    self.mutations.append({"op": ast.Pow()})

            if type(base_node.op) is ast.Pow:
                self.mutations.append({"op": ast.Mod()})
    def __init__(self, base_node):
        BaseMutator.__init__(self, base_node)
        self.original_ops = base_node.ops

        index_count = 0
        for op in base_node.ops:

            if type(op) in [ast.Gt, ast.GtE, ast.Lt, ast.LtE, ast.Eq, ast.NotEq, ast.Is, ast.IsNot, ast.In, ast.NotIn]:
                if type(op) is ast.Eq:
                    ops_mutant_Eq = copy.deepcopy(base_node.ops)
                    ops_mutant_Eq[index_count] = ast.NotEq()
                    self.mutations.append({"ops": ops_mutant_Eq})

                if type(op) is ast.NotEq:
                    ops_mutant_NotEq = copy.deepcopy(base_node.ops)
                    ops_mutant_NotEq[index_count] = ast.Eq()
                    self.mutations.append({"ops": ops_mutant_NotEq})

                if type(op) is ast.LtE:
                    ops_mutant_LtE = copy.deepcopy(base_node.ops)
                    ops_mutant_LtE[index_count] = ast.Gt()
                    self.mutations.append({"ops": ops_mutant_LtE})

                if type(op) is ast.GtE:
                    ops_mutant_GtE = copy.deepcopy(base_node.ops)
                    ops_mutant_GtE[index_count] = ast.Lt()
                    self.mutations.append({"ops": ops_mutant_GtE})

                if type(op) is ast.Lt:
                    ops_mutant_Lt = copy.deepcopy(base_node.ops)
                    ops_mutant_Lt[index_count] = ast.GtE()
                    self.mutations.append({"ops": ops_mutant_Lt})

                if type(op) is ast.Gt:
                    ops_mutant_Gt = copy.deepcopy(base_node.ops)
                    ops_mutant_Gt[index_count] = ast.LtE()
                    self.mutations.append({"ops": ops_mutant_Gt})

                if type(op) is ast.Is:
                    ops_mutant_Is = copy.deepcopy(base_node.ops)
                    ops_mutant_Is[index_count] = ast.IsNot()
                    self.mutations.append({"ops": ops_mutant_Is})

                if type(op) is ast.IsNot:
                    ops_mutant_IsNot = copy.deepcopy(base_node.ops)
                    ops_mutant_IsNot[index_count] = ast.Is()
                    self.mutations.append({"ops": ops_mutant_IsNot})

                if type(op) is ast.In:
                    ops_mutant_In = copy.deepcopy(base_node.ops)
                    ops_mutant_In[index_count] = ast.NotIn()
                    self.mutations.append({"ops": ops_mutant_In})

                if type(op) is ast.NotIn:
                    ops_mutant_NotIn = copy.deepcopy(base_node.ops)
                    ops_mutant_NotIn[index_count] = ast.In()
                    self.mutations.append({"ops": ops_mutant_NotIn})

            index_count += 1
Esempio n. 6
0
    def __init__(self, base_node):
        BaseMutator.__init__(self, base_node)
        self.original_bool_op = base_node.op

        if type(base_node.op) is ast.Or:
            self.mutations.append(ast.And())

        if type(base_node.op) is ast.And:
            self.mutations.append(ast.Or())
Esempio n. 7
0
    def __init__(self, base_node):
        BaseMutator.__init__(self, base_node)
        self.original_unary_op = base_node.op

        if type(base_node.op) in [ast.UAdd, ast.USub]:
            if type(base_node.op) is ast.UAdd:
                self.mutations.append({"op": ast.USub()})

            if type(base_node.op) is ast.USub:
                self.mutations.append({"op": ast.UAdd()})
    def __init__(self, base_node):
        BaseMutator.__init__(self, base_node)
        self.original_node = base_node

        # TODO - This doesn't work - AST node needs replaced
        if base_node.__class__ is ast.Break:
            self.mutations.append(
                ast.Continue(lineno=base_node.lineno,
                             col_offset=base_node.col_offset))
        # TODO - This doesn't work - AST node needs replaced
        if base_node.__class__ is ast.Continue:
            self.mutations.append(
                ast.Break(lineno=base_node.lineno,
                          col_offset=base_node.col_offset))
    def __init__(self, base_node):
        BaseMutator.__init__(self, base_node)
        self.original_test = base_node.test

        if (base_node.__class__ == ast.If) and (base_node.test.__class__ == ast.BoolOp):

            # Mutate the original statement so that the protected statements *always* execute
            self.mutations.append({"test": ast.Name(id='True',
                                                    ctx=ast.Load(),
                                                    lineno=base_node.test.lineno,
                                                    col_offset=base_node.test.col_offset,
                                                    )
                                   })

            # Mutate the original statement so that the protected statements *never* execute
            # (and any 'else' statements *always* execute)
            self.mutations.append({"test": ast.Name(id='False',
                                                    ctx=ast.Load(),
                                                    lineno=base_node.test.lineno,
                                                    col_offset=base_node.test.col_offset,
                                                    )
                                   })
    def __init__(self, base_node):
        BaseMutator.__init__(self, base_node)
        self.original_ops = base_node.ops

        index_count = 0
        for op in base_node.ops:

            if type(op) in [
                    ast.Gt, ast.GtE, ast.Lt, ast.LtE, ast.Eq, ast.NotEq,
                    ast.Is, ast.IsNot, ast.In, ast.NotIn
            ]:
                if type(op) is ast.Eq:
                    ops_mutant_Eq = copy.deepcopy(base_node.ops)
                    ops_mutant_Eq[index_count] = ast.NotEq()
                    self.mutations.append({"ops": ops_mutant_Eq})

                if type(op) is ast.NotEq:
                    ops_mutant_NotEq = copy.deepcopy(base_node.ops)
                    ops_mutant_NotEq[index_count] = ast.Eq()
                    self.mutations.append({"ops": ops_mutant_NotEq})

                if type(op) is ast.LtE:
                    ops_mutant_LtE = copy.deepcopy(base_node.ops)
                    ops_mutant_LtE[index_count] = ast.Gt()
                    self.mutations.append({"ops": ops_mutant_LtE})

                if type(op) is ast.GtE:
                    ops_mutant_GtE = copy.deepcopy(base_node.ops)
                    ops_mutant_GtE[index_count] = ast.Lt()
                    self.mutations.append({"ops": ops_mutant_GtE})

                if type(op) is ast.Lt:
                    ops_mutant_Lt = copy.deepcopy(base_node.ops)
                    ops_mutant_Lt[index_count] = ast.GtE()
                    self.mutations.append({"ops": ops_mutant_Lt})

                if type(op) is ast.Gt:
                    ops_mutant_Gt = copy.deepcopy(base_node.ops)
                    ops_mutant_Gt[index_count] = ast.LtE()
                    self.mutations.append({"ops": ops_mutant_Gt})

                if type(op) is ast.Is:
                    ops_mutant_Is = copy.deepcopy(base_node.ops)
                    ops_mutant_Is[index_count] = ast.IsNot()
                    self.mutations.append({"ops": ops_mutant_Is})

                if type(op) is ast.IsNot:
                    ops_mutant_IsNot = copy.deepcopy(base_node.ops)
                    ops_mutant_IsNot[index_count] = ast.Is()
                    self.mutations.append({"ops": ops_mutant_IsNot})

                if type(op) is ast.In:
                    ops_mutant_In = copy.deepcopy(base_node.ops)
                    ops_mutant_In[index_count] = ast.NotIn()
                    self.mutations.append({"ops": ops_mutant_In})

                if type(op) is ast.NotIn:
                    ops_mutant_NotIn = copy.deepcopy(base_node.ops)
                    ops_mutant_NotIn[index_count] = ast.In()
                    self.mutations.append({"ops": ops_mutant_NotIn})

            index_count += 1