Пример #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)
Пример #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)
Пример #3
0
 def test_it_returns_empty_list_on_empty_input(self):
     l = iter([])
     assert list(runtime.iteration(l, 1)) == []
Пример #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
Пример #5
0
 def test_it_returns_mappings_unaltered(self):
     mapping = {}
     assert runtime.iteration(mapping, 1) is mapping
Пример #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)]
Пример #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)]
Пример #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
Пример #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)]
Пример #10
0
 def test_it_returns_mappings_unaltered(self):
     mapping = {}
     assert runtime.iteration(mapping, 1) is mapping
Пример #11
0
 def test_it_returns_empty_list_on_empty_input(self):
     l = iter([])
     assert list(runtime.iteration(l, 1)) == []
Пример #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
Пример #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)]
Пример #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)]
Пример #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)]
Пример #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