Ejemplo n.º 1
0
 def visitEach(self, each):
     obj = iteration(self._do_eval(each.obj), len(each.keys))
     for item in obj:
         local_context = dict()
         if len(each.keys) > 1:
             for (key, value) in zip(each.keys, item):
                 local_context[key] = value
         else:
             local_context[each.keys[0]] = item
         with local_context_manager(self, local_context):
             self.visit(each.block)
Ejemplo n.º 2
0
 def visitEach(self, each):
     obj = iteration(self._do_eval(each.obj), len(each.keys))
     for item in obj:
         local_context = dict()
         if len(each.keys) > 1:
             for (key, value) in zip(each.keys, item):
                 local_context[key] = value
         else:
             local_context[each.keys[0]] = item
         with local_context_manager(self, local_context):
             self.visit(each.block)
Ejemplo n.º 3
0
 def test_it_returns_empty_list_on_empty_input(self):
     l = iter([])
     assert list(runtime.iteration(l, 1)) == []
Ejemplo n.º 4
0
 def test_it_doesnt_swallow_first_item_of_iterators(self):
     l = [1, 2]
     iterator = iter(l)
     assert list(runtime.iteration(iterator, 1)) == l
Ejemplo n.º 5
0
 def test_it_returns_mappings_unaltered(self):
     mapping = {}
     assert runtime.iteration(mapping, 1) is mapping
Ejemplo n.º 6
0
 def test_it_adds_index_if_items_are_strings(self):
     l = ['a', 'b']
     assert list(runtime.iteration(l, 2)) == [('a', 0), ('b', 1)]
Ejemplo n.º 7
0
 def test_it_adds_index_if_items_are_non_iterable(self):
     l = [1, 2]
     assert list(runtime.iteration(l, 2)) == [(1, 0), (2, 1)]
Ejemplo n.º 8
0
 def test_it_iterates_as_is_if_numkeys_is_same_as_cardinality(self):
     l = [(1, 2), (3, 4)]
     assert list(runtime.iteration(l, 2)) == l
Ejemplo n.º 9
0
 def test_it_extends_with_index_if_items_are_iterable(self):
     l = [('a',), ('b',)]
     assert list(runtime.iteration(l, 2)) == [('a', 0), ('b', 1)]
Ejemplo n.º 10
0
 def test_it_returns_mappings_unaltered(self):
     mapping = {}
     assert runtime.iteration(mapping, 1) is mapping
Ejemplo n.º 11
0
 def test_it_returns_empty_list_on_empty_input(self):
     l = iter([])
     assert list(runtime.iteration(l, 1)) == []
Ejemplo n.º 12
0
 def test_it_doesnt_swallow_first_item_of_iterators(self):
     l = [1, 2]
     iterator = iter(l)
     assert list(runtime.iteration(iterator, 1)) == l
Ejemplo n.º 13
0
 def test_it_adds_index_if_items_are_non_iterable(self):
     l = [1, 2]
     assert list(runtime.iteration(l, 2)) == [(1, 0), (2, 1)]
Ejemplo n.º 14
0
 def test_it_adds_index_if_items_are_strings(self):
     l = ['a', 'b']
     assert list(runtime.iteration(l, 2)) == [('a', 0), ('b', 1)]
Ejemplo n.º 15
0
 def test_it_extends_with_index_if_items_are_iterable(self):
     l = [('a', ), ('b', )]
     assert list(runtime.iteration(l, 2)) == [('a', 0), ('b', 1)]
Ejemplo n.º 16
0
 def test_it_iterates_as_is_if_numkeys_is_same_as_cardinality(self):
     l = [(1, 2), (3, 4)]
     assert list(runtime.iteration(l, 2)) == l