예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
    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))
예제 #6
0
    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]
예제 #7
0
    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))
예제 #8
0
    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