[ https://issues.apache.org/jira/browse/BEAM-7765?focusedWorklogId=326163&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-326163 ]
ASF GitHub Bot logged work on BEAM-7765: ---------------------------------------- Author: ASF GitHub Bot Created on: 10/Oct/19 08:00 Start Date: 10/Oct/19 08:00 Worklog Time Spent: 10m Work Description: angulartist commented on pull request #9685: [BEAM-7765] - Add test for snippet accessing_valueprovider_info_after_run URL: https://github.com/apache/beam/pull/9685#discussion_r333378566 ########## File path: sdks/python/apache_beam/examples/snippets/snippets_test.py ########## @@ -1266,6 +1266,59 @@ def expand(self, pcoll): lengths = p | beam.Create(["a", "ab", "abc"]) | ComputeWordLengths() assert_that(lengths, equal_to([1, 2, 3])) +class AccessingValueProviderInfoAfterRunTest(unittest.TestCase): + """Tests for accessing value provider info after run.""" + + def test_accessing_valueprovider_info_after_run(self): + # [START AccessingValueProviderInfoAfterRunSnip1] + + class MyOptions(PipelineOptions): + @classmethod + def _add_argparse_args(cls, parser): + # Use add_value_provider_argument for arguments to be templatable + # Use add_argument as usual for non-templatable arguments + parser.add_value_provider_argument('--string_value', type=str, + default='the quick brown fox jumps over the lazy dog') + + class LogValueProvidersFn(beam.DoFn): + def __init__(self, string_vp): + self.string_vp = string_vp + + # Define the DoFn that logs the ValueProvider value. + # The DoFn is called when creating the pipeline branch. + # This example logs the ValueProvider value, but + # you could store it by pushing it to an external database. + def process(self, an_int, **kwargs): + logging.info('The string_value is %s' % self.string_vp.get()) + + yield self.string_vp.get() + + pipeline_options = PipelineOptions() + + my_options = pipeline_options.view_as(MyOptions) + + # Create pipeline. + with beam.Pipeline(options=my_options) as p: + # Add a branch for logging the ValueProvider value. + vp_output = (p + | beam.Create([None]) + | 'LogValueProvider' >> beam.ParDo( + LogValueProvidersFn(my_options.string_value))) + + # Test value provider argument : is equal to given string 'the quick brown fox jumps over the lazy dog' + assert_that(vp_output, equal_to(['the quick brown fox jumps over the lazy dog']), Review comment: Thanks ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 326163) Time Spent: 1h 50m (was: 1h 40m) > Add test for snippet accessing_valueprovider_info_after_run > ----------------------------------------------------------- > > Key: BEAM-7765 > URL: https://issues.apache.org/jira/browse/BEAM-7765 > Project: Beam > Issue Type: Bug > Components: sdk-py-core > Reporter: Udi Meiri > Assignee: John Patoch > Priority: Major > Labels: easy > Time Spent: 1h 50m > Remaining Estimate: 0h > > This snippet needs a unit test. > It has bugs. For example: > - apache_beam.utils.value_provider doesn't exist > - beam.combiners.Sum doesn't exist > - unused import of: WriteToText > cc: [~pabloem] -- This message was sent by Atlassian Jira (v8.3.4#803005)