Repository: beam
Updated Branches:
  refs/heads/master ebd4ae6eb -> eb59a1d23


Parameterized tests for standard coders in Python SDK


Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/997002df
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/997002df
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/997002df

Branch: refs/heads/master
Commit: 997002df57c48fd3bdacf988c35a8f9d9982f6bd
Parents: ebd4ae6
Author: Vikas Kedigehalli <[email protected]>
Authored: Thu Feb 16 16:55:20 2017 -0800
Committer: Ahmet Altay <[email protected]>
Committed: Tue Feb 21 11:29:23 2017 -0800

----------------------------------------------------------------------
 pom.xml                                         |  1 +
 .../apache_beam/coders/standard_coders_test.py  | 49 ++++++++------------
 sdks/python/setup.py                            |  1 +
 3 files changed, 22 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/997002df/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 9cbaf67..0b668f7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1132,6 +1132,7 @@
               <exclude>**/test/**/.placeholder</exclude>
               <exclude>.repository/**/*</exclude>
               <exclude>**/nose-*.egg/**/*</exclude>
+              <exclude>**/.eggs/**/*</exclude>
               <exclude>**/.tox/**/*</exclude>
 
               <!-- Default eclipse excludes neglect subprojects -->

http://git-wip-us.apache.org/repos/asf/beam/blob/997002df/sdks/python/apache_beam/coders/standard_coders_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/coders/standard_coders_test.py 
b/sdks/python/apache_beam/coders/standard_coders_test.py
index d4179eb..1fbf1a1 100644
--- a/sdks/python/apache_beam/coders/standard_coders_test.py
+++ b/sdks/python/apache_beam/coders/standard_coders_test.py
@@ -30,6 +30,24 @@ from apache_beam.coders import coder_impl
 from apache_beam.utils.timestamp import Timestamp
 from apache_beam.transforms.window import IntervalWindow
 
+from nose_parameterized import parameterized
+
+STANDARD_CODERS_YAML = os.path.join(
+    os.path.dirname(__file__), '..', 'tests', 'data', 'standard_coders.yaml')
+
+
+def _load_test_cases(test_yaml):
+  """Load test data from yaml file and return an iterable of test cases.
+
+  See ``standard_coders.yaml`` for more details.
+  """
+  if not os.path.exists(test_yaml):
+    raise ValueError('Could not find the test spec: %s' % test_yaml)
+  for ix, spec in enumerate(yaml.load_all(open(test_yaml))):
+    spec['index'] = ix
+    name = spec.get('name', spec['coder']['urn'].split(':')[-2])
+    yield [name, spec]
+
 
 class StandardCodersTest(unittest.TestCase):
 
@@ -54,30 +72,8 @@ class StandardCodersTest(unittest.TestCase):
       'urn:beam:coders:stream:0.1': lambda x, parser: map(parser, x)
   }
 
-  # We must prepend an underscore to this name so that the open-source unittest
-  # runner does not execute this method directly as a test.
-  @classmethod
-  def _create_test(cls, spec):
-    counter = 0
-    name = spec.get('name', spec['coder']['urn'].split(':')[-2])
-    unique_name = 'test_' + name
-    while hasattr(cls, unique_name):
-      counter += 1
-      unique_name = 'test_%s_%d' % (name, counter)
-    setattr(cls, unique_name, lambda self: self._run_coder_test(spec))
-
-  # We must prepend an underscore to this name so that the open-source unittest
-  # runner does not execute this method directly as a test.
-  @classmethod
-  def _create_tests(cls, coder_test_specs):
-    if not os.path.exists(STANDARD_CODERS_YAML):
-      raise ValueError(
-          "Could not find the test spec: %s" % STANDARD_CODERS_YAML)
-    for ix, spec in enumerate(yaml.load_all(open(coder_test_specs))):
-      spec['index'] = ix
-      cls._create_test(spec)
-
-  def _run_coder_test(self, spec):
+  @parameterized.expand(_load_test_cases(STANDARD_CODERS_YAML))
+  def test_standard_coder(self, name, spec):
     coder = self.parse_coder(spec['coder'])
     parse_value = self.json_value_parser(spec['coder'])
     nested_list = [spec['nested']] if 'nested' in spec else [True, False]
@@ -124,11 +120,6 @@ class StandardCodersTest(unittest.TestCase):
       open(STANDARD_CODERS_YAML, 'w').write(doc_sep.join(docs))
 
 
-STANDARD_CODERS_YAML = os.path.join(
-    os.path.dirname(__file__), '..', 'tests', 'data', 'standard_coders.yaml')
-StandardCodersTest._create_tests(STANDARD_CODERS_YAML)
-
-
 def encode_nested(coder, value, nested=True):
   out = coder_impl.create_OutputStream()
   coder.get_impl().encode_to_stream(value, out, nested)

http://git-wip-us.apache.org/repos/asf/beam/blob/997002df/sdks/python/setup.py
----------------------------------------------------------------------
diff --git a/sdks/python/setup.py b/sdks/python/setup.py
index 59c0994..935cb90 100644
--- a/sdks/python/setup.py
+++ b/sdks/python/setup.py
@@ -100,6 +100,7 @@ REQUIRED_PACKAGES = [
 
 
 REQUIRED_TEST_PACKAGES = [
+    'nose-parameterized>=0.5.0,<0.6.0',
     'pyhamcrest>=1.9,<2.0',
     ]
 

Reply via email to