You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by al...@apache.org on 2017/06/13 16:34:40 UTC
[1/2] beam git commit: Make unique test names for value-provider
arguments
Repository: beam
Updated Branches:
refs/heads/master bd83612f2 -> e906fe9c3
Make unique test names for value-provider arguments
Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/b547b5a1
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/b547b5a1
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/b547b5a1
Branch: refs/heads/master
Commit: b547b5a1eee61e293ff2f8ccfac57f308867328c
Parents: bd83612
Author: Maria Garcia Herrero <ma...@google.com>
Authored: Fri Jun 9 23:34:59 2017 -0700
Committer: Ahmet Altay <al...@google.com>
Committed: Tue Jun 13 09:34:06 2017 -0700
----------------------------------------------------------------------
.../options/pipeline_options_test.py | 39 ++++----
.../apache_beam/options/value_provider_test.py | 93 +++++++++++---------
2 files changed, 71 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/beam/blob/b547b5a1/sdks/python/apache_beam/options/pipeline_options_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/options/pipeline_options_test.py b/sdks/python/apache_beam/options/pipeline_options_test.py
index 1a644b4..f4dd4d9 100644
--- a/sdks/python/apache_beam/options/pipeline_options_test.py
+++ b/sdks/python/apache_beam/options/pipeline_options_test.py
@@ -192,47 +192,52 @@ class PipelineOptionsTest(unittest.TestCase):
options = PipelineOptions(['--redefined_flag'])
self.assertTrue(options.get_all_options()['redefined_flag'])
+ # TODO(BEAM-1319): Require unique names only within a test.
+ # For now, <file name acronym>_vp_arg<number> will be the convention
+ # to name value-provider arguments in tests, as opposed to
+ # <file name acronym>_non_vp_arg<number> for non-value-provider arguments.
+ # The number will grow per file as tests are added.
def test_value_provider_options(self):
class UserOptions(PipelineOptions):
@classmethod
def _add_argparse_args(cls, parser):
parser.add_value_provider_argument(
- '--vp_arg',
+ '--pot_vp_arg1',
help='This flag is a value provider')
parser.add_value_provider_argument(
- '--vp_arg2',
+ '--pot_vp_arg2',
default=1,
type=int)
parser.add_argument(
- '--non_vp_arg',
+ '--pot_non_vp_arg1',
default=1,
type=int
)
# Provide values: if not provided, the option becomes of the type runtime vp
- options = UserOptions(['--vp_arg', 'hello'])
- self.assertIsInstance(options.vp_arg, StaticValueProvider)
- self.assertIsInstance(options.vp_arg2, RuntimeValueProvider)
- self.assertIsInstance(options.non_vp_arg, int)
+ options = UserOptions(['--pot_vp_arg1', 'hello'])
+ self.assertIsInstance(options.pot_vp_arg1, StaticValueProvider)
+ self.assertIsInstance(options.pot_vp_arg2, RuntimeValueProvider)
+ self.assertIsInstance(options.pot_non_vp_arg1, int)
# Values can be overwritten
- options = UserOptions(vp_arg=5,
- vp_arg2=StaticValueProvider(value_type=str,
- value='bye'),
- non_vp_arg=RuntimeValueProvider(
+ options = UserOptions(pot_vp_arg1=5,
+ pot_vp_arg2=StaticValueProvider(value_type=str,
+ value='bye'),
+ pot_non_vp_arg1=RuntimeValueProvider(
option_name='foo',
value_type=int,
default_value=10))
- self.assertEqual(options.vp_arg, 5)
- self.assertTrue(options.vp_arg2.is_accessible(),
- '%s is not accessible' % options.vp_arg2)
- self.assertEqual(options.vp_arg2.get(), 'bye')
- self.assertFalse(options.non_vp_arg.is_accessible())
+ self.assertEqual(options.pot_vp_arg1, 5)
+ self.assertTrue(options.pot_vp_arg2.is_accessible(),
+ '%s is not accessible' % options.pot_vp_arg2)
+ self.assertEqual(options.pot_vp_arg2.get(), 'bye')
+ self.assertFalse(options.pot_non_vp_arg1.is_accessible())
with self.assertRaises(RuntimeError):
- options.non_vp_arg.get()
+ options.pot_non_vp_arg1.get()
if __name__ == '__main__':
http://git-wip-us.apache.org/repos/asf/beam/blob/b547b5a1/sdks/python/apache_beam/options/value_provider_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/options/value_provider_test.py b/sdks/python/apache_beam/options/value_provider_test.py
index 3a45e8b..17e9590 100644
--- a/sdks/python/apache_beam/options/value_provider_test.py
+++ b/sdks/python/apache_beam/options/value_provider_test.py
@@ -24,72 +24,77 @@ from apache_beam.options.value_provider import RuntimeValueProvider
from apache_beam.options.value_provider import StaticValueProvider
+# TODO(BEAM-1319): Require unique names only within a test.
+# For now, <file name acronym>_vp_arg<number> will be the convention
+# to name value-provider arguments in tests, as opposed to
+# <file name acronym>_non_vp_arg<number> for non-value-provider arguments.
+# The number will grow per file as tests are added.
class ValueProviderTests(unittest.TestCase):
def test_static_value_provider_keyword_argument(self):
class UserDefinedOptions(PipelineOptions):
@classmethod
def _add_argparse_args(cls, parser):
parser.add_value_provider_argument(
- '--vp_arg',
+ '--vpt_vp_arg1',
help='This keyword argument is a value provider',
default='some value')
- options = UserDefinedOptions(['--vp_arg', 'abc'])
- self.assertTrue(isinstance(options.vp_arg, StaticValueProvider))
- self.assertTrue(options.vp_arg.is_accessible())
- self.assertEqual(options.vp_arg.get(), 'abc')
+ options = UserDefinedOptions(['--vpt_vp_arg1', 'abc'])
+ self.assertTrue(isinstance(options.vpt_vp_arg1, StaticValueProvider))
+ self.assertTrue(options.vpt_vp_arg1.is_accessible())
+ self.assertEqual(options.vpt_vp_arg1.get(), 'abc')
def test_runtime_value_provider_keyword_argument(self):
class UserDefinedOptions(PipelineOptions):
@classmethod
def _add_argparse_args(cls, parser):
parser.add_value_provider_argument(
- '--vp_arg',
+ '--vpt_vp_arg2',
help='This keyword argument is a value provider')
options = UserDefinedOptions()
- self.assertTrue(isinstance(options.vp_arg, RuntimeValueProvider))
- self.assertFalse(options.vp_arg.is_accessible())
+ self.assertTrue(isinstance(options.vpt_vp_arg2, RuntimeValueProvider))
+ self.assertFalse(options.vpt_vp_arg2.is_accessible())
with self.assertRaises(RuntimeError):
- options.vp_arg.get()
+ options.vpt_vp_arg2.get()
def test_static_value_provider_positional_argument(self):
class UserDefinedOptions(PipelineOptions):
@classmethod
def _add_argparse_args(cls, parser):
parser.add_value_provider_argument(
- 'vp_pos_arg',
+ 'vpt_vp_arg3',
help='This positional argument is a value provider',
default='some value')
options = UserDefinedOptions(['abc'])
- self.assertTrue(isinstance(options.vp_pos_arg, StaticValueProvider))
- self.assertTrue(options.vp_pos_arg.is_accessible())
- self.assertEqual(options.vp_pos_arg.get(), 'abc')
+ self.assertTrue(isinstance(options.vpt_vp_arg3, StaticValueProvider))
+ self.assertTrue(options.vpt_vp_arg3.is_accessible())
+ self.assertEqual(options.vpt_vp_arg3.get(), 'abc')
def test_runtime_value_provider_positional_argument(self):
class UserDefinedOptions(PipelineOptions):
@classmethod
def _add_argparse_args(cls, parser):
parser.add_value_provider_argument(
- 'vp_pos_arg',
+ 'vpt_vp_arg4',
help='This positional argument is a value provider')
options = UserDefinedOptions([])
- self.assertTrue(isinstance(options.vp_pos_arg, RuntimeValueProvider))
- self.assertFalse(options.vp_pos_arg.is_accessible())
+ self.assertTrue(isinstance(options.vpt_vp_arg4, RuntimeValueProvider))
+ self.assertFalse(options.vpt_vp_arg4.is_accessible())
with self.assertRaises(RuntimeError):
- options.vp_pos_arg.get()
+ options.vpt_vp_arg4.get()
def test_static_value_provider_type_cast(self):
class UserDefinedOptions(PipelineOptions):
@classmethod
def _add_argparse_args(cls, parser):
parser.add_value_provider_argument(
- '--vp_arg',
+ '--vpt_vp_arg5',
type=int,
help='This flag is a value provider')
- options = UserDefinedOptions(['--vp_arg', '123'])
- self.assertTrue(isinstance(options.vp_arg, StaticValueProvider))
- self.assertTrue(options.vp_arg.is_accessible())
- self.assertEqual(options.vp_arg.get(), 123)
+ options = UserDefinedOptions(['--vpt_vp_arg5', '123'])
+ self.assertTrue(isinstance(options.vpt_vp_arg5, StaticValueProvider))
+ self.assertTrue(options.vpt_vp_arg5.is_accessible())
+ self.assertEqual(options.vpt_vp_arg5.get(), 123)
def test_set_runtime_option(self):
# define ValueProvider ptions, with and without default values
@@ -97,25 +102,25 @@ class ValueProviderTests(unittest.TestCase):
@classmethod
def _add_argparse_args(cls, parser):
parser.add_value_provider_argument(
- '--vp_arg',
+ '--vpt_vp_arg6',
help='This keyword argument is a value provider') # set at runtime
parser.add_value_provider_argument( # not set, had default int
- '-v', '--vp_arg2', # with short form
+ '-v', '--vpt_vp_arg7', # with short form
default=123,
type=int)
parser.add_value_provider_argument( # not set, had default str
- '--vp-arg3', # with dash in name
+ '--vpt_vp-arg8', # with dash in name
default='123',
type=str)
parser.add_value_provider_argument( # not set and no default
- '--vp_arg4',
+ '--vpt_vp_arg9',
type=float)
parser.add_value_provider_argument( # positional argument set
- 'vp_pos_arg', # default & runtime ignored
+ 'vpt_vp_arg10', # default & runtime ignored
help='This positional argument is a value provider',
type=float,
default=5.4)
@@ -123,23 +128,23 @@ class ValueProviderTests(unittest.TestCase):
# provide values at graph-construction time
# (options not provided here become of the type RuntimeValueProvider)
options = UserDefinedOptions1(['1.2'])
- self.assertFalse(options.vp_arg.is_accessible())
- self.assertFalse(options.vp_arg2.is_accessible())
- self.assertFalse(options.vp_arg3.is_accessible())
- self.assertFalse(options.vp_arg4.is_accessible())
- self.assertTrue(options.vp_pos_arg.is_accessible())
+ self.assertFalse(options.vpt_vp_arg6.is_accessible())
+ self.assertFalse(options.vpt_vp_arg7.is_accessible())
+ self.assertFalse(options.vpt_vp_arg8.is_accessible())
+ self.assertFalse(options.vpt_vp_arg9.is_accessible())
+ self.assertTrue(options.vpt_vp_arg10.is_accessible())
# provide values at job-execution time
# (options not provided here will use their default, if they have one)
- RuntimeValueProvider.set_runtime_options({'vp_arg': 'abc',
- 'vp_pos_arg':'3.2'})
- self.assertTrue(options.vp_arg.is_accessible())
- self.assertEqual(options.vp_arg.get(), 'abc')
- self.assertTrue(options.vp_arg2.is_accessible())
- self.assertEqual(options.vp_arg2.get(), 123)
- self.assertTrue(options.vp_arg3.is_accessible())
- self.assertEqual(options.vp_arg3.get(), '123')
- self.assertTrue(options.vp_arg4.is_accessible())
- self.assertIsNone(options.vp_arg4.get())
- self.assertTrue(options.vp_pos_arg.is_accessible())
- self.assertEqual(options.vp_pos_arg.get(), 1.2)
+ RuntimeValueProvider.set_runtime_options({'vpt_vp_arg6': 'abc',
+ 'vpt_vp_arg10':'3.2'})
+ self.assertTrue(options.vpt_vp_arg6.is_accessible())
+ self.assertEqual(options.vpt_vp_arg6.get(), 'abc')
+ self.assertTrue(options.vpt_vp_arg7.is_accessible())
+ self.assertEqual(options.vpt_vp_arg7.get(), 123)
+ self.assertTrue(options.vpt_vp_arg8.is_accessible())
+ self.assertEqual(options.vpt_vp_arg8.get(), '123')
+ self.assertTrue(options.vpt_vp_arg9.is_accessible())
+ self.assertIsNone(options.vpt_vp_arg9.get())
+ self.assertTrue(options.vpt_vp_arg10.is_accessible())
+ self.assertEqual(options.vpt_vp_arg10.get(), 1.2)
[2/2] beam git commit: This closes #3341
Posted by al...@apache.org.
This closes #3341
Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/e906fe9c
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/e906fe9c
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/e906fe9c
Branch: refs/heads/master
Commit: e906fe9c3a1e12f01d84e05fbb872d47b28d2fe9
Parents: bd83612 b547b5a
Author: Ahmet Altay <al...@google.com>
Authored: Tue Jun 13 09:34:16 2017 -0700
Committer: Ahmet Altay <al...@google.com>
Committed: Tue Jun 13 09:34:16 2017 -0700
----------------------------------------------------------------------
.../options/pipeline_options_test.py | 39 ++++----
.../apache_beam/options/value_provider_test.py | 93 +++++++++++---------
2 files changed, 71 insertions(+), 61 deletions(-)
----------------------------------------------------------------------