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)))
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())
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')
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)
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)
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)
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)])))
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)
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)
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)
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)
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)
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)
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)
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)
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)))
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)
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)])))