def test_is_not_multiprocessing(self): results = schedule_workers(return_args, list(zip(range(200))), max_processes=100) self.assertEqual(sorted(results, key=lambda x: x[0]), list(zip(range(200)))) # If it's not multiprocessing, we should get results in order no matter what self.assertEqual(results, list(zip(range(200))))
def test_kwargs(self): args = list(zip(range(10))) kwargs = [{'thekwarg': i} for i in args] results = schedule_workers(return_all, list(zip(args, kwargs)), with_kwargs=True) self.assertEqual(len(results), 10) for r in results: self.assertEqual(r[0], r[1]['thekwarg'])
def test_is_really_multiprocessing(self): results = schedule_workers(return_args, list(zip(range(200))), max_processes=100) self.assertEqual(sorted(results, key=lambda x: x[0]), list(zip(range(200)))) # If it's really multiprocessing, with random waits we _must_ get a result which is out of order. with self.assertRaises(AssertionError): self.assertEqual(results, list(zip(range(200))))
def test_multiple_args(self): args = list(zip(range(100), range(100))) results = schedule_workers(return_args, args) self.assertEqual(sorted(results, key=lambda x: x[0]), args)
def test_one_arg(self): results = schedule_workers(return_args, list(zip(range(100)))) self.assertEqual(sorted(results, key=lambda x: x[0]), list(zip(range(100))))
def test_all_jobs_are_scheduled(self): results = schedule_workers(return_args, list(zip(range(10)))) self.assertEqual(len(results), 10)
def test_process_limit_is_respected(self): # Limiting to 1 process must ensure results are ordered results = schedule_workers(return_args, list(zip(range(100))), max_processes=1) self.assertEqual(results, list(zip(range(100))))
def test_exceptions_are_masked(self): schedule_workers(crash, zip(range(10)), forward_exceptions=False)
def test_exceptions_are_forwarded(self): with self.assertRaises(CrashException): results = schedule_workers(crash, list(zip(range(10))))