Exemple #1
0
    def test_passes_initial_parameter_values(self):
        task = StringConsumingTask()
        uut = TaskRunner([task])

        uut.run("-string-")

        task.assert_called_once_with("-string-")
Exemple #2
0
    def test_runs_first_task(self):
        task = VoidTask()
        uut = TaskRunner([task])

        uut.run()

        task.assert_called_once_with()
Exemple #3
0
    def test_continue_runs_next_task(self):
        first_task = VoidTask(results=Continue)
        second_task = VoidTask()
        uut = TaskRunner([first_task, second_task])

        uut.run()

        second_task.assert_called_once_with()
Exemple #4
0
    def test_task_can_return_a_single_instance(self):
        first_task = VoidTask(results="-some string-")
        second_task = StringConsumingTask()
        uut = TaskRunner([first_task, second_task])

        uut.run()

        second_task.assert_called_once_with("-some string-")
Exemple #5
0
    def test_runs_subsequent_task_with_generic_result_of_previous_task(self):
        first_task = VoidTask([[1, 2]])
        second_task = ListConsumingTask()
        uut = TaskRunner([first_task, second_task])

        uut.run()

        second_task.assert_called_once_with([1, 2])
Exemple #6
0
    def test_runs_second_task_with_result_of_first_task(self):
        first_task = VoidTask([":some string:"])
        second_task = StringConsumingTask()
        uut = TaskRunner([first_task, second_task])

        uut.run()

        second_task.assert_called_once_with(":some string:")
Exemple #7
0
    def test_runs_second_task_with_each_result_of_first_task(self):
        first_task = VoidTask([":some string:", ":other string:"])
        second_task = StringConsumingTask()
        uut = TaskRunner([first_task, second_task])

        uut.run()

        second_task.assert_has_calls([(":some string:", ),
                                      (":other string:", )])
Exemple #8
0
    def test_runs_subsequent_task_with_required_results_of_previous_tasks(
            self):
        first_task = VoidTask([":some string:"])
        second_task = VoidTask()
        uut = TaskRunner([first_task, second_task])

        uut.run()

        second_task.assert_called_once_with()
Exemple #9
0
    def test_asterisk_arg_gets_all_available_parameters(self):
        first_task = VoidTask(results="-some string-")
        second_task = VoidTask(results=42)
        asterisk_task = AsteriskTask()
        uut = TaskRunner([first_task, second_task, asterisk_task])

        uut.run()

        asterisk_task.assert_called_once_with("-some string-", 42)
Exemple #10
0
    def test_none_result_continues_execution(self):
        first_task = VoidTask(results="-some string-")
        second_task = NoneReturningTask()
        third_task = StringConsumingTask()
        uut = TaskRunner([first_task, second_task, third_task])

        uut.run()

        third_task.assert_called_once_with("-some string-")
Exemple #11
0
    def test_continues_with_next_input_if_task_fails(self):
        first_task = VoidTask(results=["-some string-", "-some other string-"])
        second_task = FailingStringConsumingTask("-error-")
        uut = TaskRunner([first_task, second_task])
        uut.logger = MagicMock()

        uut.run()

        second_task.assert_called_once_with("-some other string-")
Exemple #12
0
    def test_runs_subsequent_task_with_all_results_of_previous_tasks(self):
        first_task = VoidTask([":some string:"])
        second_task = StringConsumingTask([42])
        third_task = StringAndIntConsumingTask()
        uut = TaskRunner([first_task, second_task, third_task])

        uut.run()

        third_task.assert_called_once_with(":some string:", 42)
Exemple #13
0
    def test_runs_subsequent_task_with_results_of_previous_tasks_in_any_order(
            self):
        first_task = VoidTask([":some string:"])
        second_task = StringConsumingTask([42])
        third_task = IntAndStringConsumingTask()
        uut = TaskRunner([first_task, second_task, third_task])

        uut.run()

        third_task.assert_called_once_with(42, ":some string:")
Exemple #14
0
    def test_reports_if_a_task_requires_an_unavailable_parameter(self):
        first_task = VoidTask([42])
        second_task = StringConsumingTask()
        uut = TaskRunner([first_task, second_task])

        with assert_raises(TaskParameterUnavailableWarning) as context:
            uut.run()

        actual_message = str(context.exception)
        assert_equals("Missing parameter s for task StringConsumingTask",
                      actual_message)
Exemple #15
0
    def test_reports_if_a_task_returns_the_same_type_as_a_previous_task(self):
        first_task = VoidTask(['-some-string-'])
        second_task = StringConsumingTask(['-some-other-string-'])
        uut = TaskRunner([first_task, second_task])

        with assert_raises(TaskParameterDuplicateTypeWarning) as context:
            uut.run()

        actual_message = str(context.exception)
        assert_equals(
            "Parameter type str provided by task StringConsumingTask already exists",
            actual_message)
Exemple #16
0
    def test_reports_if_a_task_requests_the_same_type_multiple_times(self):
        first_task = VoidTask([42])
        second_task = DuplicateIntRequestingTask()
        uut = TaskRunner([first_task, second_task])

        with assert_raises(TaskRequestsDuplicateTypeWarning) as context:
            uut.run()

        actual_message = str(context.exception)
        assert_equals(
            "Task DuplicateIntRequestingTask requests multiple parameters of type int",
            actual_message)
Exemple #17
0
    def test_can_run_another_task_runner(self):
        first_outer_task = VoidTask(results="-some string-")
        first_inner_task = StringConsumingTask(results=42)
        second_inner_task = StringAndIntConsumingTask()
        second_outer_task = StringConsumingTask(results=42)
        inner_runner = TaskRunner([first_inner_task, second_inner_task])
        uut = TaskRunner([first_outer_task, inner_runner, second_outer_task])

        uut.run()

        first_inner_task.assert_called_once_with("-some string-")
        second_inner_task.assert_called_once_with("-some string-", 42)
        second_outer_task.assert_called_once_with("-some string-")
Exemple #18
0
 def test_handles_empty_tasks(self):
     uut = TaskRunner([])
     uut.run()
Exemple #19
0
_INDEX_PATH = os.path.join(__MUBENCH_ROOT_PATH, "checkouts-xp", "index.csv")


class PrintIndexTask:
    def run(self, project: Project, version: ProjectVersion, misuse: Misuse):
        print("{}\t{}\t{}\t{}\t{}\t{}\t{}".format(
            project.id, version.version_id, misuse.misuse_id,
            ':'.join(version.source_dirs), misuse.location.file,
            misuse.location.method, "\t".join(misuse.apis)),
              file=open(_INDEX_PATH, "a"))


datasets = sys.argv[1:]

white_list = []
for dataset in datasets:
    white_list.extend(get_white_list(__MUBENCH_DATASETS_FILE, dataset.lower()))
initial_parameters = [DataEntityLists(white_list, [])]

runner = TaskRunner([
    CollectProjectsTask(__MUBENCH_DATA_PATH),
    CollectVersionsTask(False),
    CollectMisusesTask(),
    PrintIndexTask()
])

if os.path.exists(_INDEX_PATH):
    os.remove(_INDEX_PATH)

runner.run(*initial_parameters)
Exemple #20
0
 def run(self) -> None:
     RequirementsCheck()
     task_configuration = get_task_configuration(self.config)
     initial_parameters = [self.data_entity_lists]
     runner = TaskRunner(task_configuration)
     runner.run(*initial_parameters)