def test_tmap__None_func_and_multiple_sequences(self): return #TODO """ Using a None as func and multiple seqences """ res = tmap(None, [1,2,3,4]) res2 = tmap(None, [1,2,3,4], [22, 33, 44, 55]) res3 = tmap(None, [1,2,3,4], [22, 33, 44, 55, 66]) res4 = tmap(None, [1,2,3,4,5], [22, 33, 44, 55]) self.assertEqual([1, 2, 3, 4], res) self.assertEqual([(1, 22), (2, 33), (3, 44), (4, 55)], res2) self.assertEqual([(1, 22), (2, 33), (3, 44), (4, 55), (None, 66)], res3) self.assertEqual([(1, 22), (2, 33), (3, 44), (4, 55), (5,None)], res4)
def test_tmap__None_func_and_multiple_sequences(self): return #TODO """ Using a None as func and multiple seqences """ res = tmap(None, [1, 2, 3, 4]) res2 = tmap(None, [1, 2, 3, 4], [22, 33, 44, 55]) res3 = tmap(None, [1, 2, 3, 4], [22, 33, 44, 55, 66]) res4 = tmap(None, [1, 2, 3, 4, 5], [22, 33, 44, 55]) self.assertEqual([1, 2, 3, 4], res) self.assertEqual([(1, 22), (2, 33), (3, 44), (4, 55)], res2) self.assertEqual([(1, 22), (2, 33), (3, 44), (4, 55), (None, 66)], res3) self.assertEqual([(1, 22), (2, 33), (3, 44), (4, 55), (5, None)], res4)
def test_tmap__no_workers(self): '''Ensure that map is called if the number of workers is set to 0''' r = range(1000) # Calculate the expected result of the computation expected = list(map(lambda x: x + 1, r)) # Ask tmap to do the computation with 0 workers r1 = tmap(lambda x: x + 1, r, num_workers=0) self.assertEqual(list(r1), expected) # Send tmap an empty worker queue and verify that it uses map in this case too wq = WorkerQueue(0) r2 = tmap(lambda x: x + 1, r, worker_queue=wq) self.assertEqual(list(r2), expected)
def test_tmap(self): # __doc__ (as of 2008-06-28) for pygame.threads.tmap: # like map, but uses a thread pool to execute. # num_workers - the number of worker threads that will be used. If pool # is passed in, then the num_workers arg is ignored. # worker_queue - you can optionally pass in an existing WorkerQueue. # wait - True means that the results are returned when everything is finished. # False means that we return the [worker_queue, results] right away instead. # results, is returned as a list of FuncResult instances. # stop_on_error - func, data = lambda x: x + 1, xrange_(100) tmapped = list(tmap(func, data)) mapped = list(map(func, data)) self.assertEqual(tmapped, mapped)
def test_tmap(self): # __doc__ (as of 2008-06-28) for pygame.threads.tmap: # like map, but uses a thread pool to execute. # num_workers - the number of worker threads that will be used. If pool # is passed in, then the num_workers arg is ignored. # worker_queue - you can optionally pass in an existing WorkerQueue. # wait - True means that the results are returned when everything is finished. # False means that we return the [worker_queue, results] right away instead. # results, is returned as a list of FuncResult instances. # stop_on_error - func, data = lambda x:x+1, xrange_(100) tmapped = list(tmap(func, data)) mapped = list(map(func, data)) self.assertEqual(tmapped, mapped)
def test_tmap__wait(self): r = range(1000) wq, results = tmap(lambda x: x, r, num_workers=5, wait=False) wq.wait() r2 = map(lambda x: x.result, results) self.assertEqual(list(r), list(r2))
def test_tmap__wait(self): r = range(1000) wq, results = tmap(lambda x:x, r, num_workers = 5, wait=False) wq.wait() r2 = map(lambda x:x.result, results) self.assertEqual(list(r), list(r2))
def test_tmap__wait(self): r = list(range(1000)) wq, results = tmap(lambda x: x, r, num_workers=5, wait=False) wq.wait() r2 = [x.result for x in results] self.assertEqual(list(r), list(r2))