Skip to content

Commit eb59a1d

Browse files
committed
This closes #2028
2 parents ebd4ae6 + 997002d commit eb59a1d

File tree

3 files changed

+22
-29
lines changed

3 files changed

+22
-29
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@
11321132
<exclude>**/test/**/.placeholder</exclude>
11331133
<exclude>.repository/**/*</exclude>
11341134
<exclude>**/nose-*.egg/**/*</exclude>
1135+
<exclude>**/.eggs/**/*</exclude>
11351136
<exclude>**/.tox/**/*</exclude>
11361137

11371138
<!-- Default eclipse excludes neglect subprojects -->

sdks/python/apache_beam/coders/standard_coders_test.py

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@
3030
from apache_beam.utils.timestamp import Timestamp
3131
from apache_beam.transforms.window import IntervalWindow
3232

33+
from nose_parameterized import parameterized
34+
35+
STANDARD_CODERS_YAML = os.path.join(
36+
os.path.dirname(__file__), '..', 'tests', 'data', 'standard_coders.yaml')
37+
38+
39+
def _load_test_cases(test_yaml):
40+
"""Load test data from yaml file and return an iterable of test cases.
41+
42+
See ``standard_coders.yaml`` for more details.
43+
"""
44+
if not os.path.exists(test_yaml):
45+
raise ValueError('Could not find the test spec: %s' % test_yaml)
46+
for ix, spec in enumerate(yaml.load_all(open(test_yaml))):
47+
spec['index'] = ix
48+
name = spec.get('name', spec['coder']['urn'].split(':')[-2])
49+
yield [name, spec]
50+
3351

3452
class StandardCodersTest(unittest.TestCase):
3553

@@ -54,30 +72,8 @@ class StandardCodersTest(unittest.TestCase):
5472
'urn:beam:coders:stream:0.1': lambda x, parser: map(parser, x)
5573
}
5674

57-
# We must prepend an underscore to this name so that the open-source unittest
58-
# runner does not execute this method directly as a test.
59-
@classmethod
60-
def _create_test(cls, spec):
61-
counter = 0
62-
name = spec.get('name', spec['coder']['urn'].split(':')[-2])
63-
unique_name = 'test_' + name
64-
while hasattr(cls, unique_name):
65-
counter += 1
66-
unique_name = 'test_%s_%d' % (name, counter)
67-
setattr(cls, unique_name, lambda self: self._run_coder_test(spec))
68-
69-
# We must prepend an underscore to this name so that the open-source unittest
70-
# runner does not execute this method directly as a test.
71-
@classmethod
72-
def _create_tests(cls, coder_test_specs):
73-
if not os.path.exists(STANDARD_CODERS_YAML):
74-
raise ValueError(
75-
"Could not find the test spec: %s" % STANDARD_CODERS_YAML)
76-
for ix, spec in enumerate(yaml.load_all(open(coder_test_specs))):
77-
spec['index'] = ix
78-
cls._create_test(spec)
79-
80-
def _run_coder_test(self, spec):
75+
@parameterized.expand(_load_test_cases(STANDARD_CODERS_YAML))
76+
def test_standard_coder(self, name, spec):
8177
coder = self.parse_coder(spec['coder'])
8278
parse_value = self.json_value_parser(spec['coder'])
8379
nested_list = [spec['nested']] if 'nested' in spec else [True, False]
@@ -124,11 +120,6 @@ def quote(s):
124120
open(STANDARD_CODERS_YAML, 'w').write(doc_sep.join(docs))
125121

126122

127-
STANDARD_CODERS_YAML = os.path.join(
128-
os.path.dirname(__file__), '..', 'tests', 'data', 'standard_coders.yaml')
129-
StandardCodersTest._create_tests(STANDARD_CODERS_YAML)
130-
131-
132123
def encode_nested(coder, value, nested=True):
133124
out = coder_impl.create_OutputStream()
134125
coder.get_impl().encode_to_stream(value, out, nested)

sdks/python/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def get_version():
100100

101101

102102
REQUIRED_TEST_PACKAGES = [
103+
'nose-parameterized>=0.5.0,<0.6.0',
103104
'pyhamcrest>=1.9,<2.0',
104105
]
105106

0 commit comments

Comments
 (0)