コード例 #1
0
ファイル: init.py プロジェクト: sobolevn/cosmic-ray
def init(modules,
         work_db,
         config,
         timeout):
    """Clear and initialize a work-db with work items.

    Any existing data in the work-db will be cleared and replaced with entirely
    new work orders. In particular, this means that any results in the db are
    removed.

    Args:
      modules: iterable of module objects to be mutated.
      work_db: A `WorkDB` instance into which the work orders will be saved.
      config: The configuration for the new session.
      timeout: The timeout to apply to the work in the session.
    """
    operators = cosmic_ray.plugins.operator_names()
    work_db.set_config(
        config=config,
        timeout=timeout)

    work_db.clear_work_items()

    for module in modules:
        for op_name in operators:
            core = WorkDBInitCore(module, op_name, work_db)
            operator = get_operator(op_name)(core)
            module_ast = get_ast(module)
            operator.visit(module_ast)

    apply_interceptors(work_db)
コード例 #2
0
ファイル: init.py プロジェクト: woshibwt/cosmic-ray
def init(module_paths, work_db, config):
    """Clear and initialize a work-db with work items.

    Any existing data in the work-db will be cleared and replaced with entirely
    new work orders. In particular, this means that any results in the db are
    removed.

    Args:
      module_paths: iterable of pathlib.Paths of modules to mutate.
      work_db: A `WorkDB` instance into which the work orders will be saved.
      config: The configuration for the new session.
    """

    operator_names = list(cosmic_ray.plugins.operator_names())

    work_db.set_config(config=config)

    work_db.clear()
    work_db.disable_synchronisation()

    for module_path in module_paths:
        module_ast = get_ast(
            module_path, python_version=config.python_version)

        for op_name in operator_names:
            operator = get_operator(op_name)(config.python_version)
            visitor = WorkDBInitVisitor(module_path, op_name, work_db,
                                        operator)
            visitor.walk(module_ast)

    enabled_interceptors = config.sub('interceptors').get('enabled', ())
    apply_interceptors(work_db, enabled_interceptors, config)
    work_db.enable_synchronisation()
コード例 #3
0
def all_work_items(module_paths, operator_names, python_version):
    "Iterable of all WorkItems for the given inputs."
    for module_path in module_paths:
        module_ast = get_ast(module_path, python_version=python_version)

        for op_name in operator_names:
            operator = get_operator(op_name)(python_version)
            occurrence = 0
            for node in ast_nodes(module_ast):
                for start_pos, end_pos in operator.mutation_positions(node):
                    yield WorkItem(job_id=uuid.uuid4().hex,
                                   module_path=str(module_path),
                                   operator_name=op_name,
                                   occurrence=occurrence,
                                   start_pos=start_pos,
                                   end_pos=end_pos)

                    occurrence += 1
コード例 #4
0
def _all_work_items(module_paths, operator_names) -> Iterable[WorkItem]:
    "Iterable of all WorkItems for the given inputs."
    for module_path in module_paths:
        module_ast = get_ast(module_path)

        for op_name in operator_names:
            operator = get_operator(op_name)()

            positions = (
                (start_pos, end_pos) for node in ast_nodes(module_ast)
                for start_pos, end_pos in operator.mutation_positions(node))

            for occurrence, (start_pos, end_pos) in enumerate(positions):
                mutation = ResolvedMutationSpec(
                    module_path=str(module_path),
                    operator_name=op_name,
                    occurrence=occurrence,
                    start_pos=start_pos,
                    end_pos=end_pos,
                )

                yield WorkItem.single(job_id=uuid.uuid4().hex,
                                      mutation=mutation)