Ejemplo n.º 1
0
def test_adding_result_completes_work_item(work_db):
    items = [
        WorkItem.single(
            f"job_id_{idx}",
            ResolvedMutationSpec("path_{}".format(idx),
                                 "operator_{}".format(idx), idx, (idx, idx),
                                 (idx, idx + 1)),
        ) for idx in range(10)
    ]

    for item in items:
        work_db.add_work_item(item)

    for idx, item in enumerate(items):
        assert [r[0] for r in work_db.completed_work_items] == items[:idx]
        result = (
            "job_id_{}".format(idx),
            WorkResult(
                output="data_{}".format(idx),
                test_outcome=TOutcome.KILLED,
                worker_outcome=WorkerOutcome.NORMAL,
                diff="diff_{}".format(idx),
            ),
        )
        work_db.set_result(*result)
Ejemplo n.º 2
0
def test_set_multiple_results_works(work_db):
    work_db.add_work_item(
        WorkItem.single(
            "job_id",
            ResolvedMutationSpec("path", "operator", 0, (0, 0), (0, 1))))

    work_db.set_result(
        "job_id",
        WorkResult(output="first result",
                   test_outcome=TOutcome.KILLED,
                   worker_outcome=WorkerOutcome.NORMAL,
                   diff="diff"),
    )

    work_db.set_result(
        "job_id",
        WorkResult(output="second result",
                   test_outcome=TOutcome.KILLED,
                   worker_outcome=WorkerOutcome.NORMAL,
                   diff="diff"),
    )

    results = [r for job_id, r in work_db.results if job_id == "job_id"]
    assert len(results) == 1
    assert results[0].output == "second result"
Ejemplo n.º 3
0
def test_results(work_db):
    for idx in range(10):
        work_db.add_work_item(
            WorkItem.single(
                f"job_id_{idx}",
                ResolvedMutationSpec("path_{}".format(idx),
                                     "operator_{}".format(idx), idx,
                                     (idx, idx), (idx, idx + 1)),
            ))

    original = [(
        "job_id_{}".format(idx),
        WorkResult(
            output="data_{}".format(idx),
            test_outcome=TOutcome.KILLED,
            worker_outcome=WorkerOutcome.NORMAL,
            diff="diff_{}".format(idx),
        ),
    ) for idx in range(10)]

    for result in original:
        work_db.set_result(*result)

    actual = list(work_db.results)

    assert actual == original
Ejemplo n.º 4
0
def test_adding_result_clears_pending(work_db):
    items = [
        WorkItem.single(
            f"job_id_{idx}",
            ResolvedMutationSpec("path_{}".format(idx),
                                 "operator_{}".format(idx), idx, (idx, idx),
                                 (idx, idx + 1)),
        ) for idx in range(10)
    ]

    for item in items:
        work_db.add_work_item(item)

    for idx, item in enumerate(items):
        assert sorted(list(work_db.pending_work_items),
                      key=repr) == sorted(items[idx:], key=repr)
        result = (
            "job_id_{}".format(idx),
            WorkResult(
                output="data_{}".format(idx),
                test_outcome=TOutcome.KILLED,
                worker_outcome=WorkerOutcome.NORMAL,
                diff="diff_{}".format(idx),
            ),
        )
        work_db.set_result(*result)
Ejemplo n.º 5
0
def test_clear_removes_work_items(work_db):
    for idx in range(10):
        work_db.add_work_item(
            WorkItem.single(
                f"job_id_{idx}",
                ResolvedMutationSpec("path", "operator", 0, (0, 0), (0, 1))))
    work_db.clear()
    assert work_db.num_work_items == 0
Ejemplo n.º 6
0
def test_num_work_items(work_db):
    count = 10
    for idx in range(count):
        work_db.add_work_item(
            WorkItem.single(
                f"job_id_{idx}",
                ResolvedMutationSpec("path", "operator", 0, (0, 0), (0, 1))))
    assert work_db.num_work_items == count
Ejemplo n.º 7
0
def test_clear_work_items_removes_results(work_db):
    for idx in range(10):
        work_db.add_work_item(
            WorkItem.single(
                f"job_id_{idx}",
                ResolvedMutationSpec("path", "operator", 0, (0, 0), (0, 1))))
        work_db.set_result(f"job_id_{idx}", WorkResult(WorkerOutcome.NORMAL))

    work_db.clear()
    assert work_db.num_results == 0
 def new_work_item(self, operator_name, job_id):
     self.count += 1
     return WorkItem.single(
         job_id,
         ResolvedMutationSpec(
             module_path="{}.py".format(self.count),
             operator_name=operator_name,
             occurrence=self.count,
             start_pos=(self.count, self.count),
             end_pos=(self.count + 1, self.count + 1),
         ),
     )
Ejemplo n.º 9
0
def test_jobs_with_results_are_not_pending(work_db):
    work_db.add_work_item(
        WorkItem.single(
            "job_id",
            ResolvedMutationSpec("path", "operator", 0, (0, 0), (0, 1))))
    work_db.set_result(
        "job_id",
        WorkResult(output="data",
                   test_outcome=TOutcome.KILLED,
                   worker_outcome=WorkerOutcome.NORMAL,
                   diff="diff"),
    )
    assert not list(work_db.pending_work_items)
Ejemplo n.º 10
0
def test_new_work_items_are_pending(work_db):
    items = [
        WorkItem.single(
            f"job_id_{idx}",
            ResolvedMutationSpec("path_{}".format(idx),
                                 "operator_{}".format(idx), idx, (idx, idx),
                                 (idx, idx + 1)),
        ) for idx in range(10)
    ]

    for idx, item in enumerate(items):
        assert sorted(list(work_db.pending_work_items),
                      key=repr) == sorted(items[:idx], key=repr)
        work_db.add_work_item(item)
Ejemplo n.º 11
0
def test_work_items(work_db):
    original = [
        WorkItem.single(
            f"job_id_{idx}",
            ResolvedMutationSpec("path_{}".format(idx),
                                 "operator_{}".format(idx), idx, (idx, idx),
                                 (idx, idx + 1)),
        ) for idx in range(10)
    ]
    for item in original:
        work_db.add_work_item(item)

    actual = list(work_db.work_items)

    assert actual == original
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
def test_find_pending_job(work_db):
    item = WorkItem.single(
        "job_id", ResolvedMutationSpec("path", "operator", 0, (0, 0), (0, 1)))
    work_db.add_work_item(item)
    pending = list(work_db.pending_work_items)
    assert pending == [item]