Ejemplo n.º 1
0
 def test_reset_source_none(self):
     '''reset source using send(None) - fails'''
     with self.assertRaises(TypeError):
         with (repack.integer().iterator()) as iterator:
             iterator.send(None)
             r = []
             for v in iterator:
                 r.append(v)
Ejemplo n.º 2
0
    def test_iterate_list(self):
        '''source generator - pass'''
        with (repack.integer().iterator(iter(['1', '2', '3']))) as iterator:
            r = []
            for v in iterator:
                r.append(v)

        self.assertSequenceEqual([1, 2, 3], r)
Ejemplo n.º 3
0
    def test_reset_source_forin(self):
        '''reset source using send in for...in - pass'''
        with (repack.integer().iterator(iter(['1', '2', '3']))) as iterator:
            r = []
            for v in iterator.send(iter(['11', '22', '33'])):
                r.append(v)

        self.assertSequenceEqual([11, 22, 33], r)
Ejemplo n.º 4
0
    def test_iterate_list_more_filters(self):
        '''source, more filters - pass'''
        with (repack.integer().string().reverse().integer().iterator(
                iter(['1', '2', '3']))) as iterator:
            r = []
            for v in iterator:
                r.append(v)

        self.assertSequenceEqual([1, 2, 3], r)
Ejemplo n.º 5
0
    def test_iterate_chained(self):
        '''source generator, chained - pass'''

        left = tests.gen(iter(['1', '2', '3']))
        iterator = (repack.integer().iterator(left))
        right = tests.gen(iterator)

        r = []
        for v in right:
            r.append(v)

        self.assertSequenceEqual([1, 2, 3], r)
Ejemplo n.º 6
0
    def test_convert_int(self):
        '''convert int to str - pass'''
        with (repack.integer().converter()) as c:
            r = c.send('101010')

        self.assertEqual(101010, r)
Ejemplo n.º 7
0
 def test_iterate_none(self):
     '''source None - fail'''
     with self.assertRaises(TypeError):
         with (repack.integer().iterator(None)) as iterator:
             for v in iterator:
                 pass