riteshghorse commented on code in PR #28158:
URL: https://github.com/apache/beam/pull/28158#discussion_r1305836477
##########
sdks/python/apache_beam/options/pipeline_options_validator_test.py:
##########
@@ -95,258 +96,152 @@ def test_missing_required_options(self):
errors, ['project', 'staging_location', 'temp_location',
'region']),
[])
- def test_gcs_path(self):
- def get_validator(temp_location, staging_location):
+ @parameterized.expand([
+ (None, 'gs://foo/bar',
+ []), (None, None, ['staging_location', 'temp_location']),
+ ('gs://foo/bar', None, []), ('gs://foo/bar', 'gs://ABC/bar',
+ []), ('gcs:/foo/bar', 'gs://foo/bar', []),
+ ('gs:/foo/bar', 'gs://foo/bar', []), ('gs://ABC/bar', 'gs://foo/bar',
[]),
+ ('gs://ABC/bar', 'gs://BCD/bar', ['temp_location', 'staging_location'
+ ]), ('gs://foo', 'gs://foo/bar', []),
+ ('gs://foo/', 'gs://foo/bar', []), ('gs://foo/bar', 'gs://foo/bar', [])
+ ])
+ def test_gcs_path(self, temp_location, staging_location,
expected_error_args):
+ def get_validator(_temp_location, _staging_location):
options = ['--project=example:example', '--job_name=job']
- if temp_location is not None:
- options.append('--temp_location=' + temp_location)
+ if _temp_location is not None:
+ options.append('--temp_location=' + _temp_location)
- if staging_location is not None:
- options.append('--staging_location=' + staging_location)
+ if _staging_location is not None:
+ options.append('--staging_location=' + _staging_location)
pipeline_options = PipelineOptions(options)
runner = MockRunners.DataflowRunner()
validator = PipelineOptionsValidator(pipeline_options, runner)
return validator
- test_cases = [{
- 'temp_location': None, 'staging_location': 'gs://foo/bar', 'errors': []
- },
- {
- 'temp_location': None,
- 'staging_location': None,
- 'errors': ['staging_location', 'temp_location']
- },
- {
- 'temp_location': 'gs://foo/bar',
- 'staging_location': None,
- 'errors': []
- },
- {
- 'temp_location': 'gs://foo/bar',
- 'staging_location': 'gs://ABC/bar',
- 'errors': []
- },
- {
- 'temp_location': 'gcs:/foo/bar',
- 'staging_location': 'gs://foo/bar',
- 'errors': []
- },
- {
- 'temp_location': 'gs:/foo/bar',
- 'staging_location': 'gs://foo/bar',
- 'errors': []
- },
- {
- 'temp_location': 'gs://ABC/bar',
- 'staging_location': 'gs://foo/bar',
- 'errors': []
- },
- {
- 'temp_location': 'gs://ABC/bar',
- 'staging_location': 'gs://BCD/bar',
- 'errors': ['temp_location', 'staging_location']
- },
- {
- 'temp_location': 'gs://foo',
- 'staging_location': 'gs://foo/bar',
- 'errors': []
- },
- {
- 'temp_location': 'gs://foo/',
- 'staging_location': 'gs://foo/bar',
- 'errors': []
- },
- {
- 'temp_location': 'gs://foo/bar',
- 'staging_location': 'gs://foo/bar',
- 'errors': []
- }]
-
- for case in test_cases:
- errors = get_validator(case['temp_location'],
- case['staging_location']).validate()
- self.assertEqual(
- self.check_errors_for_arguments(errors, case['errors']), [], case)
-
- def test_project(self):
- def get_validator(project):
+ errors = get_validator(temp_location, staging_location).validate()
+ self.assertEqual(
+ self.check_errors_for_arguments(errors, expected_error_args), [])
+
+ @parameterized.expand([(None, ['project']), ('12345', ['project']),
+ ('FOO', ['project']), ('foo:BAR', ['project']),
+ ('fo', ['project']), ('foo', []), ('foo:bar', [])])
+ def test_project(self, project, expected_error_args):
+ def get_validator(_project):
options = [
'--job_name=job',
'--staging_location=gs://foo/bar',
'--temp_location=gs://foo/bar'
]
- if project is not None:
- options.append('--project=' + project)
+ if _project is not None:
+ options.append('--project=' + _project)
pipeline_options = PipelineOptions(options)
runner = MockRunners.DataflowRunner()
validator = PipelineOptionsValidator(pipeline_options, runner)
return validator
- test_cases = [
- {
- 'project': None, 'errors': ['project']
- },
- {
- 'project': '12345', 'errors': ['project']
- },
- {
- 'project': 'FOO', 'errors': ['project']
- },
- {
- 'project': 'foo:BAR', 'errors': ['project']
- },
- {
- 'project': 'fo', 'errors': ['project']
- },
- {
- 'project': 'foo', 'errors': []
- },
- {
- 'project': 'foo:bar', 'errors': []
- },
- ]
-
- for case in test_cases:
- errors = get_validator(case['project']).validate()
- self.assertEqual(
- self.check_errors_for_arguments(errors, case['errors']), [])
+ errors = get_validator(project).validate()
+ self.assertEqual(
+ self.check_errors_for_arguments(errors, expected_error_args), [])
- def test_job_name(self):
- def get_validator(job_name):
+ @parameterized.expand([(None, []), ('12345', ['job_name']),
+ ('FOO', ['job_name']), ('foo:bar', ['job_name']),
+ ('fo', []), ('foo', [])])
+ def test_job_name(self, job_name, expected_error_args):
+ def get_validator(_job_name):
options = [
'--project=example:example',
'--staging_location=gs://foo/bar',
'--temp_location=gs://foo/bar'
]
- if job_name is not None:
- options.append('--job_name=' + job_name)
+ if _job_name is not None:
+ options.append('--job_name=' + _job_name)
pipeline_options = PipelineOptions(options)
runner = MockRunners.DataflowRunner()
validator = PipelineOptionsValidator(pipeline_options, runner)
return validator
- test_cases = [
- {
- 'job_name': None, 'errors': []
- },
- {
- 'job_name': '12345', 'errors': ['job_name']
- },
- {
- 'job_name': 'FOO', 'errors': ['job_name']
- },
- {
- 'job_name': 'foo:bar', 'errors': ['job_name']
- },
- {
- 'job_name': 'fo', 'errors': []
- },
- {
- 'job_name': 'foo', 'errors': []
- },
- ]
-
- for case in test_cases:
- errors = get_validator(case['job_name']).validate()
- self.assertEqual(
- self.check_errors_for_arguments(errors, case['errors']), [])
+ errors = get_validator(job_name).validate()
+ self.assertEqual(
+ self.check_errors_for_arguments(errors, expected_error_args), [])
- def test_num_workers(self):
- def get_validator(num_workers):
+ @parameterized.expand([(None, []), ('1', []), ('0', ['num_workers']),
+ ('-1', ['num_workers'])])
+ def test_num_workers(self, num_workers, expected_error_args):
+ def get_validator(_num_workers):
options = [
'--project=example:example',
'--job_name=job',
'--staging_location=gs://foo/bar',
'--temp_location=gs://foo/bar'
]
- if num_workers is not None:
- options.append('--num_workers=' + num_workers)
+ if _num_workers is not None:
+ options.append('--num_workers=' + _num_workers)
pipeline_options = PipelineOptions(options)
runner = MockRunners.DataflowRunner()
validator = PipelineOptionsValidator(pipeline_options, runner)
return validator
- test_cases = [
- {
- 'num_workers': None, 'errors': []
- },
- {
- 'num_workers': '1', 'errors': []
- },
- {
- 'num_workers': '0', 'errors': ['num_workers']
- },
- {
- 'num_workers': '-1', 'errors': ['num_workers']
- },
- ]
-
- for case in test_cases:
- errors = get_validator(case['num_workers']).validate()
- self.assertEqual(
- self.check_errors_for_arguments(errors, case['errors']), [])
-
- def test_is_service_runner(self):
- test_cases = [
- {
- 'runner': MockRunners.OtherRunner(),
- 'options': [],
- 'expected': False,
- },
- {
- 'runner': MockRunners.OtherRunner(),
- 'options': ['--dataflow_endpoint=https://dataflow.googleapis.com'],
- 'expected': False,
- },
- {
- 'runner': MockRunners.OtherRunner(),
- 'options':
['--dataflow_endpoint=https://dataflow.googleapis.com/'],
- 'expected': False,
- },
- {
- 'runner': MockRunners.DataflowRunner(),
- 'options': [],
- 'expected': True,
- },
- {
- 'runner': MockRunners.DataflowRunner(),
- 'options': ['--dataflow_endpoint=https://another.service.com'],
- 'expected': True,
- },
- {
- 'runner': MockRunners.DataflowRunner(),
- 'options': ['--dataflow_endpoint=https://dataflow.googleapis.com'],
- 'expected': True,
- },
- {
- 'runner': MockRunners.DataflowRunner(),
- 'options': ['--dataflow_endpoint=http://localhost:1000'],
- 'expected': False,
- },
- {
- 'runner': MockRunners.DataflowRunner(),
- 'options': ['--dataflow_endpoint=foo: //dataflow. googleapis.
com'],
- 'expected': True,
- },
- {
- 'runner': MockRunners.DataflowRunner(),
- 'options': [],
- 'expected': True,
- },
- ]
-
- for case in test_cases:
- validator = PipelineOptionsValidator(
- PipelineOptions(case['options']), case['runner'])
- self.assertEqual(validator.is_service_runner(), case['expected'], case)
+ errors = get_validator(num_workers).validate()
+ self.assertEqual(
+ self.check_errors_for_arguments(errors, expected_error_args), [])
+
+ @parameterized.expand([
Review Comment:
Nothing blocking but I like this way of writing test cases (each test case
and its param on different line).. could we do this for other test cases as well
```
[
(
[],
{},
),(
[],
{},
),
]
```
--
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]