Пример #1
0
 def test_add_error(self):
     result_manager = ListResultManager()
     result_manager.add_error(JobError(1, 1))
     self.assertEqual(len(result_manager.errors), 1)
     self.assertEqual(type(result_manager.errors[0]).__name__, JobError.__name__)
     self.assertEqual(result_manager.errors[0].job_id, 1)
     self.assertEqual(result_manager.errors[0].result, 1)
Пример #2
0
 def test_add_success(self):
     result_manager = ListResultManager()
     result_manager.add_success(JobSuccess(1, 1))
     self.assertEqual(len(result_manager.results), 1)
     self.assertEqual(type(result_manager.results[0]).__name__, JobSuccess.__name__)
     self.assertEqual(result_manager.results[0].job_id, 1)
     self.assertEqual(result_manager.results[0].result, 1)
Пример #3
0
 def test_show_errors(self):
     result_manager = ListResultManager()
     result_manager.add_error(JobError(1, 1))
     result = result_manager.show_errors()
     self.assertEqual(len(result), 1)
     self.assertEqual(type(result[0]).__name__, JobError.__name__)
     self.assertEqual(result[0].job_id, 1)
     self.assertEqual(result[0].result, 1)
     result_manager = ListResultManager()
     result = result_manager.show_results()
     self.assertEqual(len(result), 0)
Пример #4
0
 def test_init(self):
     Data = ListDataProxy([i for i in range(100)])
     executor = PipedJobExecutor(worker=test_worker,
                                 data_partitioner=SimpleListPartitioner(data_proxy=Data, processors=4),
                                 result_manager=ListResultManager())
     self.assertEqual(executor.processors, 4)
     aa = executor.response_holder()
     self.assertTrue(type(aa).__name__, tuple.__name__)
     self.assertTrue(type(aa[0]).__name__, Pipe.__name__)
     self.assertTrue(type(aa[1]).__name__, Pipe.__name__)
Пример #5
0
 def test_execute(self):
     Data = ListDataProxy([i for i in range(100)])
     result = PipedJobExecutor(worker=test_worker,
                               data_partitioner=SimpleListPartitioner(data_proxy=Data, processors=4),
                               result_manager=ListResultManager()).execute()
     result.show_results()
     self.assertEqual(len(result.show_results()), 4)
     self.assertEqual(len(result.show_results()[0].result), 25)
     self.assertEqual(len(result.show_results()[1].result), 25)
     self.assertEqual(len(result.show_results()[2].result), 25)
     self.assertEqual(len(result.show_results()[3].result), 25)
Пример #6
0
    def __init__(self,
                 worker=None,
                 data_partitioner=None,
                 result_manager=None):
        """

        :param worker: The worker function to run in parallel. Must be a callable.
        :param data_partitioner: Instance of DataPartitioner to partition the source data.
        :param result_manager: Instance of @result.ResultManager to return the results of all the jobs.
        """
        assert isinstance(data_partitioner, DataPartitioner),\
            "data_partitioner must be an instance of {0}".format(DataPartitioner.__name__)
        if result_manager is not None:
            assert isinstance(result_manager, ResultManager), \
                "result_manager must be an instance of {0}".format(ResultManager.__name__)
            self.result_manager = result_manager
        else:
            self.result_manager = ListResultManager()

        self.data_partitioner = data_partitioner
        self.processors = self.data_partitioner.processors
        self.worker = worker
        self.processes = []
Пример #7
0
 def test_add_results_success(self, add_success, add_error):
     result_manager = ListResultManager()
     result_manager.add_results(JobSuccess(1, 1))
     self.assertTrue(add_success.called)
     self.assertFalse(add_error.called)
Пример #8
0
 def test_add_error_invalid_type(self):
     result_manager = ListResultManager()
     with self.assertRaises(AssertionError) as e:
         result_manager.add_error(1)
Пример #9
0
 def test_add_error_success_type(self):
     result_manager = ListResultManager()
     with self.assertRaises(AssertionError) as e:
         result_manager.add_error(JobSuccess(1, 1))
Пример #10
0
 def test_add_results_invalid_result_type(self, add_success, add_error):
     result_manager = ListResultManager()
     with self.assertRaises(TypeError) as e:
         result_manager.add_results(1)
Пример #11
0
 def test_init_invalid_partitioner(self):
     Data = ListDataProxy([i for i in range(100)])
     with self.assertRaises(AssertionError) as e:
         PipedJobExecutor(worker=test_worker,
                          data_partitioner=Data,
                          result_manager=ListResultManager())