tvalentyn commented on a change in pull request #16154:
URL: https://github.com/apache/beam/pull/16154#discussion_r787265688
##########
File path: sdks/python/test-suites/direct/common.gradle
##########
@@ -86,7 +86,7 @@ task examples {
def argMap = ["runner": "TestDirectRunner",
"test_opts": testOpts,
"suite":
"postCommitExamples-direct-py${pythonVersionSuffix}",
- "collect": "examples_postcommit"
+ "collect": "examples_postcommit and not no_sickbay_examples"
Review comment:
Double negation is not intuitive here. I would call the label
`sickbay_examples`; Using different labels may be better if sickbays are
specific per runner :
```
sickbay_direct
sickbay_portable
sickbay_spark
...
```
##########
File path: sdks/python/apache_beam/examples/complete/autocomplete_test.py
##########
@@ -71,6 +79,33 @@ def test_autocomplete_it(self):
assert_that(checksum, equal_to([self.KINGLEAR_HASH_SUM]))
+ @pytest.mark.examples_postcommit
+ def test_basics(self):
+ EXPECTED_PREFIXES = "t: [(3, 'to'), (2, 'this'), (1, 'that')]\n" \
+ "th: [(2, 'this'), (1, 'that')]\n" \
+ "thi: [(2, 'this')]\n" \
+ "this: [(2, 'this')]\n" \
+ "tha: [(1, 'that')]\n" \
+ "that: [(1, 'that')]\n" \
+ "to: [(3, 'to')]"
+
+ # Setup the files with expected content.
+ temp_folder = tempfile.mkdtemp()
+ self.create_file(
+ os.path.join(temp_folder, 'input.txt'), ' '.join(self.WORDS))
+ autocomplete.run([
+ '--input=%s/input.txt' % temp_folder,
+ '--output',
+ os.path.join(temp_folder, 'result')
+ ],
+ save_main_session=False)
+
+ # Load result file and compare.
+ with open_shards(os.path.join(temp_folder, 'result-*-of-*')) as
result_file:
+ result = result_file.read().strip()
+
+ self.assertEqual(result, EXPECTED_PREFIXES)
Review comment:
Are both results expected to be sorted?
##########
File path: sdks/python/apache_beam/examples/complete/autocomplete.py
##########
@@ -40,7 +40,7 @@ def run(argv=None):
# We use the save_main_session option because one or more DoFn's in this
# workflow rely on global context (e.g., a module imported at module level).
pipeline_options = PipelineOptions(pipeline_args)
- pipeline_options.view_as(SetupOptions).save_main_session = True
+ pipeline_options.view_as(SetupOptions).save_main_session = save_main_session
Review comment:
Could you please help me understand why save_main_session is an issue
here?
Which runner has an issue if we don't set this to `False`?
Adding this flag adds some confusion to the example, as seeing this pattern
users might try to copy it into their pipelines. I'd like to understand if we
can avoid defining the flag as an additional parameter to the example. For
example, the comment above is going out of sync with this line now.
##########
File path:
sdks/python/apache_beam/examples/cookbook/bigquery_side_input_it_test.py
##########
@@ -0,0 +1,69 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Integration test for the BigQuery side input example."""
+
+# pytype: skip-file
+
+import logging
+import unittest
+import uuid
+
+import pytest
+from hamcrest.core.core.allof import all_of
+
+from apache_beam.examples.cookbook import bigquery_side_input
+from apache_beam.runners.runner import PipelineState
+from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.test_utils import delete_files
+
+
+class BigQuerySideInputIT(unittest.TestCase):
+ DEFAULT_OUTPUT_FILE = \
+ 'gs://temp-storage-for-end-to-end-tests/py-it-cloud/output'
+
+ def setUp(self):
+ self.test_pipeline = TestPipeline(is_integration_test=True)
+ self.uuid = str(uuid.uuid4())
+
+ self.output = '/'.join([self.DEFAULT_OUTPUT_FILE, self.uuid, 'results'])
+
+ @pytest.mark.examples_postcommit
+ def test_basics(self):
+ state_verifier = PipelineStateMatcher(PipelineState.DONE)
+ NUM_GROUPS = 3
+
+ extra_opts = {
+ 'output': self.output + '/side-input',
+ 'num_groups': str(NUM_GROUPS),
+ 'on_success_matcher': all_of(state_verifier)
Review comment:
Let's try to add some verifier for output contents that makes sense.
##########
File path: sdks/python/apache_beam/examples/complete/game/user_score_it_test.py
##########
@@ -84,6 +85,32 @@ def test_user_score_it(self):
self.test_pipeline.get_full_options_as_args(**extra_opts),
save_main_session=False)
+ @pytest.mark.examples_postcommit
+ def test_basics(self):
Review comment:
Let's try to pick more mnemonic naming for the unit tests in this PR.
Ideally, a name should summarize the behavior being tested and its expected
outcome so that it's easy to answer how the scenarios such as test_basics vs
test_user_score_it differ. possible suggestion:
`test_userscore_output_checksum_on_small_input`.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]