gemini-code-assist[bot] commented on code in PR #38847:
URL: https://github.com/apache/beam/pull/38847#discussion_r3374572728


##########
sdks/python/apache_beam/runners/dataflow/internal/apiclient_test.py:
##########
@@ -1298,6 +1298,41 @@ def 
test_template_file_generation_with_upload_graph(self):
           self.assertFalse(template_obj.get('steps'))
           self.assertTrue(template_obj['stepsLocation'])
 
+  def test_dataflow_endpoint_clean(self):
+    endpoints_and_expectations = [
+        # (input_endpoint, expected_endpoint, expected_transport)
+        ('https://dataflow.googleapis.com/', 'dataflow.googleapis.com', None),
+        ('https://dataflow.googleapis.com   ', 'dataflow.googleapis.com', 
None),
+        ('dataflow.googleapis.com/', 'dataflow.googleapis.com', None),
+        ('http://localhost:8080/', 'http://localhost:8080', 'rest'),
+        ('localhost:8080/', 'localhost:8080', 'rest'),
+    ]
+
+    for input_ep, expected_ep, expected_transport in 
endpoints_and_expectations:
+      pipeline_options = PipelineOptions([
+          '--project',
+          'test-project',
+          '--temp_location',
+          'gs://test-location/temp',
+          '--dataflow_endpoint',
+          input_ep,
+          '--no_auth',
+      ])
+      with 
mock.patch('apache_beam.runners.dataflow.internal.apiclient.dataflow'
+                      '.JobsV1Beta3Client') as mock_jobs:
+        with mock.patch(
+            'apache_beam.runners.dataflow.internal.apiclient.dataflow'
+            '.MessagesV1Beta3Client'):
+          with mock.patch(
+              'apache_beam.runners.dataflow.internal.apiclient.dataflow'
+              '.MetricsV1Beta3Client'):
+            apiclient.DataflowApplicationClient(pipeline_options)
+            called_kwargs = mock_jobs.call_args[1]

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   If the call to `DataflowApplicationClient` fails or does not invoke 
`JobsV1Beta3Client`, `mock_jobs.call_args` will be `None`, resulting in a 
cryptic `TypeError` when attempting to subscript it. Adding 
`mock_jobs.assert_called_once()` provides a much clearer assertion failure 
message. Additionally, using `mock_jobs.call_args.kwargs` is more readable and 
idiomatic than indexing `call_args[1]`.
   
   ```suggestion
               apiclient.DataflowApplicationClient(pipeline_options)
               mock_jobs.assert_called_once()
               called_kwargs = mock_jobs.call_args.kwargs
   ```



-- 
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]

Reply via email to