def test_pipeline_process_single_thread_with_other_pipeline(self): def identity(x): return x def one(): return 1 def sum1(x): return x + 1 p = Pipeline([identity]) p.lock() q = Pipeline([one, p, sum1]) q.lock() result = sum(q.process(range(10))) assert result == 20 p = Pipeline([identity, sum1]) p.lock() q = Pipeline([one, p]) q.lock() result = sum(q.process(range(10))) assert result == 20
def test_pipeline_process_multi_thread_with_other_single_thread_pipeline( self): def identity(x): return x def one(): return 1 def sum1(x): return x + 1 p = Pipeline([identity]) p.lock() q = Pipeline([one, p, sum1], parallel=True, workers=6) q.lock() result = sum(q.process(range(10))) assert result == 20 p = Pipeline([identity]) p.lock() q = Pipeline([one, p, sum1], parallel=True, workers=6) q.lock() result = sum(q.process(range(10))) assert result == 20
def test_pipeline_process_single_thread(self): def sum1(x): return x + 1 p = Pipeline([sum1]) p.lock() result = p.process([0]) assert sum(result) == 1 p = Pipeline([sum1, sum1, sum1]) p.lock() result = p.process([0]) assert sum(result) == 3
def test_pipeline_process_multi_thread_with_no_args_but_return(self): def one(): return 1 p = Pipeline([one], parallel=True, workers=6) p.lock() result = sum(p.process(range(1000))) assert result == 1000
def test_pipeline_process_single_thread_with_args_and_return(self): def identity(x): return x p = Pipeline([identity]) p.lock() result = p.process(range(10)) assert result == list(range(10))
def test_pipeline_process_single_thread_with_args_no_return(self): def void(*a, **k): pass p = Pipeline([void]) p.lock() result = p.process(range(2)) assert result == [None, None]
def test_pipeline_process_multi_thread_with_args_and_return(self): def identity(x): return x p = Pipeline([identity], parallel=True, workers=6) p.lock() result = p.process(range(1000)) result.sort() assert result == list(range(1000))
def test_pipeline_process_multi_thread_with_other_multi_thread_pipeline( self): def sum_set(x): return sum(x) def minus1(x): return x - 1 def identity(x): return x def get_hundred_of(x): return [x] * 100 # will spawn (2 ** 3) + 2 threads p = Pipeline([minus1], parallel=True, workers=3) p.lock() q = Pipeline([get_hundred_of, p, sum_set], parallel=True, workers=2) q.lock() result = sum(q.process([1] * 100)) assert result == 0