示例#1
0
 async def main():
     to_ch = chan(5, xf.take(5))
     from_ch = c.to_chan(range(20))
     c.pipeline(5, to_ch, xf.identity, from_ch, mode=mode)
     await asyncio.sleep(0.1)
     self.assertEqual(await a_list(to_ch), [0, 1, 2, 3, 4])
     self.assertTrue(len(await a_list(from_ch)) > 5)
示例#2
0
        async def main():
            ch = c.to_chan([1, 2, 3])

            def rf(result, val=None):
                if val is None:
                    return result
                result.append(val)
                return result

            result_ch = c.transduce(xf.take(2), rf, [], ch)
            self.assertEqual(await result_ch.get(), [1, 2])
示例#3
0
    def test_xform_state_is_not_modified_when_canceled(self):
        xformCh = self.chan(1, xf.take(2))
        xformCh.b_put('firstTake')
        ch = self.chan()

        def thread():
            time.sleep(0.1)
            ch.b_put('altValue')

        threading.Thread(target=thread).start()
        self.assertEqual(
            c.b_alt(ch, [xformCh, 'do not modify xform state'], priority=True),
            ('altValue', ch))
        xformCh.f_put('secondTake')
        xformCh.f_put('dropMe')
        self.assertEqual(b_list(xformCh), ['firstTake', 'secondTake'])
示例#4
0
 def test_reduced(self):
     xform = xf.comp(xf.partition_by(lambda x: x % 2 == 0), xf.take(2))
     self.assertEqual(list(xf.xiter(xform, [1, 3, 2, 4, 5, 7])),
                      [(1, 3), (2, 4)])
示例#5
0
 def test_complete(self):
     xform = xf.comp(xf.partition_by(lambda x: x % 2 == 0), xf.take(2))
     self.assertEqual(list(xf.xiter(xform, [2, 4, 6, 1, 3, 5, 8])),
                      [(2, 4, 6), (1, 3, 5)])
示例#6
0
 def test_reduced(self):
     xform = xf.comp(xf.map_indexed(lambda i, x: {i: x}), xf.take(2))
     self.assertEqual(list(xf.xiter(xform, ['zero', 'one', '_', '_'])),
                      [{0: 'zero'}, {1: 'one'}])
示例#7
0
 def test_reduced(self):
     xform = xf.comp(xf.drop_last(4), xf.take(2))
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4, 5, 6, 7])), [1, 2])
示例#8
0
 def test_reduced(self):
     xform = xf.comp(xf.random_sample(1), xf.take(2))
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4])), [1, 2])
示例#9
0
 def test_itransduce_reduced(self):
     result = xf.itransduce(xf.take(2), sum_rf, 1, [2, 3, 100])
     self.assertEqual(result, 6)
示例#10
0
 def test_reduced(self):
     xform = xf.comp(xf.keep_indexed(self.even_set), xf.take(2))
     self.assertEqual(list(xf.xiter(xform, [2, 3, 4, 5, 6])), [{2}, {4}])
示例#11
0
 def test_reduced(self):
     xform = xf.comp(xf.interpose('s'), xf.take(4))
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3])), [1, 's', 2, 's'])
示例#12
0
 def test_reduced(self):
     xform = xf.comp(xf.remove_indexed(self.even_i_pos_v), xf.take(1))
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4])), [2])
示例#13
0
 def test_reduced(self):
     xform = xf.comp(xf.keep(lambda x: x if x % 2 == 0 else None),
                     xf.take(2))
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4, 5, 6])), [2, 4])
示例#14
0
 def test_reduced(self):
     xform = xf.comp(xf.remove(lambda x: x % 2 == 0), xf.take(2))
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4, 5])), [1, 3])
示例#15
0
 def test_reduced(self):
     xform = xf.comp(xf.filter_indexed(self.even_i_pos_v), xf.take(1))
     self.assertEqual(list(xf.xiter(xform, [-1, 2, 3, 4, 5])), [3])
示例#16
0
 def test_reduced(self):
     xform = xf.comp(xf.filter(lambda x: x % 2 == 0), xf.take(2))
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4, 5, 6])), [2, 4])
示例#17
0
 def test_reductions_init_only_reduced(self):
     xform = xf.comp(xf.reductions(lambda x, y: x + y, 'success'),
                     xf.take(1))
     self.assertEqual(list(xf.xiter(xform, [])), ['success'])
示例#18
0
 def test_reduced(self):
     xform = xf.comp(xf.cat, xf.take(2))
     self.assertEqual(list(xf.xiter(xform, [[1, 2], [3]])), [1, 2])
示例#19
0
 def test_reductions_reduced(self):
     xform = xf.comp(xf.reductions(lambda x, y: x + y, 1), xf.take(3))
     self.assertEqual(list(xf.xiter(xform, [2, 3, 4, 5])), [1, 3, 6])
示例#20
0
 def test_reduced(self):
     xform = xf.comp(xf.mapcat(lambda x: [x, x * 2]), xf.take(3))
     self.assertEqual(list(xf.xiter(xform, [1, 4, 16])), [1, 2, 4])
示例#21
0
 def test_reduced(self):
     xform = xf.comp(xf.replace({1: 'one'}), xf.take(2))
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4])), ['one', 2])
示例#22
0
 async def main():
     ch = self.chan(1, xf.take(2))
     c.onto_chan(ch, [1, 2, 3, 4])
     self.assertEqual(await a_list(ch), [1, 2])
示例#23
0
 def test_partition_with_smaller_step_reduced_during_complete(self):
     xform = xf.comp(xf.partition_all(3, 1), xf.take(4))
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4, 5])),
                      [(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5)])
示例#24
0
 def test_reduced(self):
     xform = xf.comp(xf.drop_while(lambda x: x < 3), xf.take(2))
     dropped = list(xf.xiter(xform, range(8)))
     self.assertEqual(list(dropped), [3, 4])
示例#25
0
 def test_reduced_without_step(self):
     xform = xf.comp(xf.partition_all(1), xf.take(2))
     self.assertEqual(list(xf.xiter(xform, range(12))), [(0,), (1,)])
示例#26
0
 def test_reduced(self):
     xform = xf.comp(xf.map(lambda x: x * 2), xf.take(2))
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4])), [2, 4])
示例#27
0
 def test_xform_with_reduced_return(self):
     ch = c.promise_chan(xf.take(1))
     self.assertIs(ch.b_put('success'), True)
     self.assertIs(ch.b_put('failure'), False)
     self.assertEqual(ch.b_get(), 'success')
     self.assertEqual(ch.b_get(), 'success')
示例#28
0
 def test_reduced(self):
     xform = xf.comp(xf.dedupe, xf.take(2))
     self.assertEqual(list(xf.xiter(xform, [1, 1, 2, 2, 3, 4])), [1, 2])
示例#29
0
 def test_reduced_with_step(self):
     xform = xf.comp(xf.partition_all(2, 1), xf.take(1))
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3])), [(1, 2)])
示例#30
0
 def test_reduced(self):
     xform = xf.comp(xf.drop(2), xf.take(2))
     dropped = list(xf.xiter(xform, range(8)))
     self.assertEqual(dropped, [2, 3])