Ejemplo n.º 1
0
    def test_cancel(self):
        # Again, cancelling jobs is beyond our responsibility. In this test
        # we only check if we delegate on the proper method of the underlaying
        # future object.

        # pylint: disable=redefined-outer-name
        with intercepted_executor_for_localjob() as (LocalJob, executor):
            job = LocalJob(lambda: None, fake_qobj())
            job.cancel()

        self.assertCalledOnce(executor.submit)
        mocked_future = executor.submit.return_value
        self.assertCalledOnce(mocked_future.cancel)
Ejemplo n.º 2
0
    def test_done(self):
        # Once more, testing that reading the `done` property delegates into
        # the proper future API.

        # pylint: disable=redefined-outer-name
        with intercepted_executor_for_localjob() as (LocalJob, executor):
            job = LocalJob(lambda: None, fake_qobj())
            _ = job.done

        self.assertCalledOnce(executor.submit)
        mocked_future = executor.submit.return_value
        self.assertCalledOnce(mocked_future.done)
Ejemplo n.º 3
0
    def test_multiple_execution(self):
        # Notice that it is Python responsibility to test the executors
        # can run several tasks at the same time. It is our responsibility to
        # use the executor correctly. That is what this test checks.

        taskcount = 10
        target_tasks = [lambda: None for _ in range(taskcount)]

        # pylint: disable=redefined-outer-name
        with intercepted_executor_for_localjob() as (LocalJob, executor):
            for index in range(taskcount):
                LocalJob(target_tasks[index], fake_qobj())

        self.assertEqual(executor.submit.call_count, taskcount)
        for index in range(taskcount):
            _, callargs, _ = executor.submit.mock_calls[index]
            submitted_task = callargs[0]
            target_task = target_tasks[index]
            self.assertEqual(submitted_task, target_task)