Beispiel #1
0
    def test_multi(self):
        start = time()
        Iter(range(10)).into(SlowQPipe()).execute()
        finish = time() - start
        if is_backend(Backend.MULTIPROCESSING): assert 0.9 < finish < 1.1
        if is_backend(Backend.THREADING): assert 0.9 < finish < 1.1
        if is_backend(Backend.DUMMY): assert 0.9 < finish < 1.1

        start = time()
        Iter(range(10)).into(SlowQPipe(processes=2)).execute()
        finish = time() - start
        if is_backend(Backend.MULTIPROCESSING): assert 0.4 < finish < 1.0
        if is_backend(Backend.THREADING): assert 0.4 < finish < .7
        if is_backend(Backend.DUMMY): assert 0.9 < finish < 1.1

        start = time()
        Iter(range(10)).into(SlowQPipe(processes=4)).execute()
        finish = time() - start
        if is_backend(Backend.MULTIPROCESSING): assert 0.2 < finish < 0.6
        if is_backend(Backend.THREADING): assert 0.2 < finish < 0.5
        if is_backend(Backend.DUMMY): assert 0.9 < finish < 1.1

        start = time()
        Iter(range(10)).into(SlowQPipe(processes=10)).execute()
        finish = time() - start
        if is_backend(Backend.MULTIPROCESSING): assert finish < 0.4
        if is_backend(Backend.THREADING): assert finish < 0.4
        if is_backend(Backend.DUMMY): assert 0.9 < finish < 1.1
Beispiel #2
0
 def test_open(self):
     fname = "/tmp/test-open-" + str(time())
     with open(fname, 'w') as f:
         f.write("Line1\n")
         f.write("Line2\n")
         f.write("Line3\n")
     assert Open(fname).results() == ["Line1\n", "Line2\n", "Line3\n"]
     assert Iter([fname]).into(Open()).results() == ["Line1\n", "Line2\n", "Line3\n"]
Beispiel #3
0
 def test_three_sequential(self):
     pipe = Iter(range(10)).into(Fn(sq)).into(Fn(multiply_ten)).into(Fn(multiply_ten))
     assert pipe.results() == [0, 100, 400, 900, 1600, 2500, 3600, 4900, 6400, 8100]
Beispiel #4
0
 def test_reversed(self):
     assert Iter(range(4)).into(Reverse()).results() == [3, 2, 1, 0]
Beispiel #5
0
 def test_grep(self):
     assert Iter(["dogs", "dog", "heydog", "other"]).into(Grep("dog$")).results() == ["dog", "heydog"]
Beispiel #6
0
 def test_print(self):
     assert Iter(range(10)).into(Print()).results() == []
Beispiel #7
0
 def test_fn_basic(self):
     assert Iter(range(10)).into(Fn(lambda x: x*x)).results() == [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]