예제 #1
0
 def test_gen_func_chaining(self):
     def inner_gen():
         for d in [range(10),range(10)]:
             yield d
     p = parallel(inner_gen)
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     self.assertEquals(list(p.flatten().map(double)), list(parallel((d for d in [range(10),range(10)])).flatmap(double)))
예제 #2
0
 def test_raises_exception(self):
     def inner_func():
         return 1
     class InnerClass(object):
         pass
     with self.assertRaises(TypeError):
         p = parallel(inner_func())
     with self.assertRaises(TypeError):
         p = parallel(1)
     with self.assertRaises(TypeError):
         p = parallel(InnerClass())
예제 #3
0
 def test_returns_gen(self):
     p = parallel((d for d in [range(10),range(10)]))
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     def inner_gen():
         for i in range(10):
             yield i
     p = parallel(inner_gen())
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     p = parallel(list())
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     p = parallel(tuple())
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     p = parallel(set())
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
예제 #4
0
 def test_filter_for_none_false_elements(self):
     p = parallel((d for d in [False, True, None]))
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     pred = is_none_or_false
     filtered = p.filter(pred)
     self.assertEquals(list(filtered), list([False, None]))
     self.assertFalse(filtered is p)
예제 #5
0
 def test_filter_with_none_as_func(self):
     p = parallel((d for d in [False, True]))
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     pred = None
     filtered = p.filter(pred)
     self.assertEquals(list(filtered), list([True]))
     self.assertFalse(filtered is p)
예제 #6
0
 def test_filter(self):
     p = parallel((d for d in ['a','2','3']))
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     pred = is_digit
     filtered = p.filter(pred)
     self.assertEquals(list(filtered), list(['2','3']))
     self.assertFalse(filtered is p)
예제 #7
0
 def test_gen_func_flatten(self):
     def inner_gen():
         for d in [range(10),range(10)]:
             yield d
     p = parallel(inner_gen)
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     self.assertEquals(list(p.flatten()), list(chain(*[range(10),range(10)])))
예제 #8
0
 def test_gen_func_flatmap(self):
     def inner_gen():
         for d in [range(10),range(10)]:
             yield d
     p = parallel(inner_gen)
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     self.assertEquals(list(p.flatmap(double)), map(double, chain(*[range(10),range(10)])))
     self.assertFalse(p.flatmap(double) is p)
예제 #9
0
 def test_gen_func_foreach(self):
     def inner_gen():
         for d in [range(10),range(10)]:
             yield d
     p = parallel(inner_gen)
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     p.foreach(double)
     self.assertEquals(list(p), map(double, [range(10),range(10)]))
     self.assertTrue(p.foreach(double) is None)
예제 #10
0
 def test_gen_func_reduce(self):
     def inner_gen():
         for d in ['a', 'a', 'b']:
             yield d
     p = parallel(inner_gen)
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     reduced = p.reduce(group_letters, defaultdict(list))
     self.assertEquals(dict(a=['a','a'], b=['b',]), dict(reduced))
     self.assertFalse(reduced is p)
예제 #11
0
 def test_gen_func_map(self):
     def inner_gen():
         for d in [range(10),range(10)]:
             yield d
     p = parallel(inner_gen)
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     mapped = p.map(double)
     self.assertEquals(list(mapped), map(double, [range(10),range(10)]))
     self.assertFalse(mapped is p)
예제 #12
0
 def test_gen_func_filter(self):
     def inner_gen():
         for d in ['a','2','3']:
             yield d
     p = parallel(inner_gen)
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     pred = is_digit
     filtered = p.filter(pred)
     self.assertEquals(list(filtered), list(['2','3']))
     self.assertFalse(filtered is p)
예제 #13
0
 def test_flatmap(self):
     p = parallel((d for d in [range(10),range(10)]))
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     self.assertEquals(list(p.flatmap(double)), map(double, chain(*[range(10),range(10)])))
     self.assertFalse(p.flatmap(double) is p)
예제 #14
0
 def test_map(self):
     p = parallel((d for d in [range(10),range(10)]))
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     mapped = p.map(double)
     self.assertEquals(list(mapped), map(double, [range(10),range(10)]))
     self.assertFalse(mapped is p)
예제 #15
0
 def test_foreach(self):
     p = parallel((d for d in [range(10),range(10)]))
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     p.foreach(double)
     self.assertEquals(list(p), map(double, [range(10),range(10)]))
     self.assertTrue(p.foreach(double) is None)
예제 #16
0
 def test_chaining(self):
     p = parallel((d for d in [range(10),range(10)]))
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     self.assertEquals(list(p.flatten().map(double)), list(parallel((d for d in [range(10),range(10)])).flatmap(double)))
예제 #17
0
 def test_reduce(self):
     p = parallel((d for d in ['a', 'a', 'b']))
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     reduced = p.reduce(group_letters, defaultdict(list))
     self.assertEquals(dict(a=['a','a'], b=['b',]), dict(reduced))
     self.assertFalse(reduced is p)
예제 #18
0
 def test_flatten(self):
     p = parallel((d for d in [range(10),range(10)]))
     self.assertTrue(p.__class__.__name__ == 'ParallelGen')
     self.assertEquals(list(p.flatten()), list(chain(*[range(10),range(10)])))