[
https://issues.apache.org/jira/browse/BEAM-8434?focusedWorklogId=335270&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-335270
]
ASF GitHub Bot logged work on BEAM-8434:
----------------------------------------
Author: ASF GitHub Bot
Created on: 28/Oct/19 23:20
Start Date: 28/Oct/19 23:20
Worklog Time Spent: 10m
Work Description: robertwb commented on pull request #9832: [BEAM-8434]
Translate trigger transcripts into validates runner tests.
URL: https://github.com/apache/beam/pull/9832#discussion_r339835318
##########
File path: sdks/python/apache_beam/transforms/trigger_test.py
##########
@@ -659,11 +675,132 @@ def fire_timers():
self.assertEqual([], output, msg='Unexpected output: %s' % output)
+class TestStreamTranscriptTest(TranscriptTest):
+ """A suite of TestStream-based tests based on trigger transcript entries.
+ """
+
+ def _execute(
+ self, window_fn, trigger_fn, accumulation_mode, timestamp_combiner,
+ transcript, spec):
+
+ runner_name = TestPipeline().runner.__class__.__name__
+ if runner_name in spec.get('broken_on', ()):
+ self.skipTest('Known to be broken on %s' % runner_name)
+
+ test_stream = TestStream()
+ for action, params in transcript:
+ if action == 'expect':
+ test_stream.add_elements([('expect', params)])
+ else:
+ test_stream.add_elements([('expect', [])])
+ if action == 'input':
+ test_stream.add_elements([('input', e) for e in params])
+ elif action == 'watermark':
+ test_stream.advance_watermark_to(params)
+ elif action == 'clock':
+ test_stream.advance_processing_time(params)
+ elif action == 'state':
+ pass # Requires inspection of implementation details.
+ else:
+ raise ValueError('Unexpected action: %s' % action)
+ test_stream.add_elements([('expect', [])])
+
+ class Check(beam.DoFn):
+ """A StatefulDoFn that verifies outputs are produced as expected.
+
+ This DoFn takes in two kinds of inputs, actual outputs and
+ expected outputs. When an actual output is received, it is buffered
+ into state, and when an expected output is received, this buffered
+ state is retrieved and compared against the expected value(s) to ensure
+ they match.
+
+ The key is ignored, but all items must be on the same key to share state.
+ """
+ def process(
+ self, element, seen=beam.DoFn.StateParam(
+ beam.transforms.userstate.BagStateSpec(
+ 'seen',
+ beam.coders.FastPrimitivesCoder()))):
+ _, (action, data) = element
+ if action == 'actual':
+ seen.add(data)
+
+ elif action == 'expect':
+ actual = list(seen.read())
+ seen.clear()
+
+ if len(actual) > len(data):
+ raise AssertionError(
+ 'Unexpected output: expected %s but got %s' % (data, actual))
+ elif len(data) > len(actual):
+ raise AssertionError(
+ 'Unmatched output: expected %s but got %s' % (data, actual))
+ else:
+
+ def diff(actual, expected):
+ for key in sorted(expected.keys(), reverse=True):
+ if key in actual:
+ if actual[key] != expected[key]:
+ return key
+
+ for output in actual:
+ diffs = [diff(output, expected) for expected in data]
+ if all(diffs):
Review comment:
`diff(output, expected)` is the key that differed. `all(diffs)` is saying
that there was a difference for all of the expected values (i.e. if each diff
is non-empty, then it didn't match any of them).
----------------------------------------------------------------
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 335270)
Time Spent: 2.5h (was: 2h 20m)
> Allow trigger transcript tests to be run as ValidatesRunner tests.
> -------------------------------------------------------------------
>
> Key: BEAM-8434
> URL: https://issues.apache.org/jira/browse/BEAM-8434
> Project: Beam
> Issue Type: Improvement
> Components: testing
> Reporter: Robert Bradshaw
> Assignee: Robert Bradshaw
> Priority: Major
> Time Spent: 2.5h
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)