Exemplo n.º 1
0
 def test_empty_side_outputs(self):
     pipeline = Pipeline('DirectPipelineRunner')
     nums = pipeline | Create('Some Numbers', [1, 3, 5])
     results = nums | FlatMap(
         'ClassifyNumbers', lambda x:
         [x, SideOutputValue('even'
                             if x % 2 == 0 else 'odd', x)]).with_outputs()
     assert_that(results[None], equal_to([1, 3, 5]))
     assert_that(results.odd, equal_to([1, 3, 5]), label='assert:odd')
     assert_that(results.even, equal_to([]), label='assert:even')
     pipeline.run()
Exemplo n.º 2
0
 def test_undeclared_side_outputs(self):
     pipeline = Pipeline('DirectPipelineRunner')
     nums = pipeline | Create('Some Numbers', [1, 2, 3, 4])
     results = nums | FlatMap(
         'ClassifyNumbers', lambda x:
         [x, SideOutputValue('even'
                             if x % 2 == 0 else 'odd', x)]).with_outputs()
     # TODO(silviuc): Revisit this test to check for undeclared side outputs.
     # This should work with .with_outputs() without any tags declared and
     # the results[None] should work also.
     assert_that(results[None], equal_to([1, 2, 3, 4]))
     assert_that(results.odd, equal_to([1, 3]), label='assert:odd')
     assert_that(results.even, equal_to([2, 4]), label='assert:even')
     pipeline.run()
Exemplo n.º 3
0
 def create_dupes(o, _):
     yield o
     yield SideOutputValue('side', o)
Exemplo n.º 4
0
 def some_fn(v):
     if v % 2 == 0:
         return [v, SideOutputValue('even', v)]
     else:
         return [v, SideOutputValue('odd', v)]
Exemplo n.º 5
0
 def process(self, context):
     yield context.element
     if context.element % 2 == 0:
         yield SideOutputValue('even', context.element)
     else:
         yield SideOutputValue('odd', context.element)