Exemplo n.º 1
0
    def test_get_lower_class(self):
        cls = utils.get_by_python_version(classes=[self.A, self.B],
                                          python_version=(3, 3))

        self.assertEqual(cls, self.B)
Exemplo n.º 2
0
        self.newline(node)
        self.write('try:')
        self.body(node.body)
        for handler in node.handlers:
            self.visit(handler)
        if node.finalbody:
            self.newline(node)
            self.write('finally:')
            self.body(node.finalbody)


    def visit_With(self, node):
        self.newline(node)
        self.write('with ')
        for with_item in node.items:
            self.visit(with_item.context_expr)
            if with_item.optional_vars is not None:
                self.write(' as ')
                self.visit(with_item.optional_vars)
            if with_item != node.items[-1]:
                self.write(', ')
        self.write(':')
        self.body(node.body)


SourceGenerator = utils.get_by_python_version([
    SourceGeneratorPython32,
    SourceGeneratorPython33
])

Exemplo n.º 3
0
 def test_empty_classes(self):
     with self.assertRaises(NotImplementedError):
         utils.get_by_python_version(classes=[])
Exemplo n.º 4
0
 def test_no_proper_class(self):
     with self.assertRaises(NotImplementedError):
         utils.get_by_python_version(classes=[self.A, self.B],
                                     python_version=(3, 0))
Exemplo n.º 5
0
        def write_comma():
            if want_comma:
                self.write(', ')
            else:
                want_comma.append(True)

        padding = [None] * (len(node.args) - len(node.defaults))
        for arg, default in zip(node.args, padding + node.defaults):
            write_comma()
            self.visit(arg)
            if default is not None:
                self.write('=')
                self.visit(default)
        if node.vararg is not None:
            write_comma()
            self.write('*' + node.vararg.arg)
        if node.kwarg is not None:
            write_comma()
            self.write('**' + node.kwarg.arg)


class SourceGeneratorPython35(SourceGeneratorPython34):

    __python_version__ = (3, 5)


SourceGenerator = utils.get_by_python_version([
    SourceGeneratorPython33, SourceGeneratorPython34, SourceGeneratorPython35
])
Exemplo n.º 6
0
    __python_version__ = (3, 3)

    def visit_Try(self, node):
        self.newline(node)
        self.write('try:')
        self.body(node.body)
        for handler in node.handlers:
            self.visit(handler)
        if node.finalbody:
            self.newline(node)
            self.write('finally:')
            self.body(node.finalbody)

    def visit_With(self, node):
        self.newline(node)
        self.write('with ')
        for with_item in node.items:
            self.visit(with_item.context_expr)
            if with_item.optional_vars is not None:
                self.write(' as ')
                self.visit(with_item.optional_vars)
            if with_item != node.items[-1]:
                self.write(', ')
        self.write(':')
        self.body(node.body)


SourceGenerator = utils.get_by_python_version(
    [SourceGeneratorPython32, SourceGeneratorPython33])
Exemplo n.º 7
0
            ast.Nonlocal,
            ast.Pass,
            ast.Raise,
            ast.Return,
            ast.ClassDef,
            ast.FunctionDef,
            ast.Try,
            ast.ExceptHandler,
            ast.If,
            ast.For,
            ast.While,
        }


CoverageNodeTransformer = utils.get_by_python_version([
    CoverageNodeTransformerPython32,
    CoverageNodeTransformerPython33,
])


class CoverageInjector:

    def __init__(self):
        self.covered_nodes = set()

    def inject(self, node, module_name='coverage'):
        self.covered_nodes.clear()
        self.marker_transformer = MarkerNodeTransformer()
        marker_node = self.marker_transformer.visit(node)
        coverage_node = CoverageNodeTransformer().visit(copy.deepcopy(marker_node))
        self.covered_nodes.add(coverage_node.marker)
        with utils.StdoutManager():
Exemplo n.º 8
0
            ast.Nonlocal,
            ast.Pass,
            ast.Raise,
            ast.Return,
            ast.ClassDef,
            ast.FunctionDef,
            ast.Try,
            ast.ExceptHandler,
            ast.If,
            ast.For,
            ast.While,
        }


CoverageNodeTransformer = utils.get_by_python_version([
    CoverageNodeTransformerPython32,
    CoverageNodeTransformerPython33,
])


class CoverageInjector:

    def __init__(self):
        self.covered_nodes = set()

    def inject(self, node, module_name='coverage'):
        self.covered_nodes.clear()
        self.marker_transformer = MarkerNodeTransformer()
        marker_node = self.marker_transformer.visit(node)
        coverage_node = CoverageNodeTransformer().visit(copy.deepcopy(marker_node))
        self.covered_nodes.add(coverage_node.marker)
        with utils.StdoutManager():
Exemplo n.º 9
0

class SuperCallingInsertPython35(SuperCallingInsertPython27):
    __python_version__ = (3, 5)

    @staticmethod
    def add_kwarg_to_super_call(super_call, kwarg):
        super_call.value.keywords.append(ast.keyword(arg=None, value=ast.Name(id=kwarg.arg, ctx=ast.Load())))

    @staticmethod
    def add_vararg_to_super_call(super_call, vararg):
        super_call.value.args.append(ast.Starred(ctx=ast.Load(), value=ast.Name(id=vararg.arg, ctx=ast.Load())))


SuperCallingInsert = utils.get_by_python_version([
    SuperCallingInsertPython27,
    SuperCallingInsertPython35,
])


class AbstractMethodDecoratorInsertionMutationOperator(MutationOperator):
    @copy_node
    def mutate_FunctionDef(self, node):
        if not isinstance(node.parent, ast.ClassDef):
            raise MutationResign()
        for decorator in node.decorator_list:
            if isinstance(decorator, ast.Call):
                decorator_name = decorator.func.id
            elif isinstance(decorator, ast.Attribute):
                decorator_name = decorator.value.id
            else:
                decorator_name = decorator.id