[Piglit] [Patch v2 8/9] glsl_parser_test.py: Don't allow duplicate keys
Dylan Baker
baker.dylan.c at gmail.com
Fri Jul 11 08:14:21 PDT 2014
If a single key is provided more than once raise an exception.
Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
framework/glsl_parser_test.py | 11 ++++++++++-
framework/tests/glsl_parser_test_tests.py | 27 +++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index cb9dd91..5c0461e 100644
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -170,7 +170,16 @@ class GLSLParserTest(PiglitTest):
"Key {0} in file {1} is not a valid key for a "
"glslparser test config block".format(
match.group('key'), filepath))
- keys[match.group('key')] = match.group('value')
+ elif match.group('key') in self.__found_keys:
+ # If this key has already been encountered throw an error,
+ # there are no duplicate keys allows
+ raise GLSLParserException(
+ 'Duplicate entry for key {}'.format(match.group('key')))
+ else:
+ # Otherwise add the key to the set of found keys, and add
+ # it to the dictionary that will be returned
+ self.__found_keys.add(match.group('key'))
+ keys[match.group('key')] = match.group('value')
else:
raise GLSLParserException(
"The config section is malformed."
diff --git a/framework/tests/glsl_parser_test_tests.py b/framework/tests/glsl_parser_test_tests.py
index b2b5cdd..987ed9e 100644
--- a/framework/tests/glsl_parser_test_tests.py
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -210,3 +210,30 @@ def test_good_section_names():
_check_config(content)
except glsl.GLSLParserException as e:
raise AssertionError(e)
+
+
+def check_no_duplicates(content, dup):
+ """ Ensure that duplicate entries raise an error """
+ with nt.assert_raises(glsl.GLSLParserException) as e:
+ _check_config(content)
+
+ nt.eq_(e.exception.message,
+ 'Duplicate entry for key {}'.format(dup))
+
+
+ at utils.nose_generator
+def test_duplicate_entries():
+ """ Generate tests for duplicate keys in the config block """
+ content = [
+ ('expect_result', '// expect_result: pass\n'),
+ ('glsl_version', '// glsl_version: 1.00\n'),
+ ('require_extensions', '// require_extensions: ARB_ham_sandwhich\n')
+ ]
+
+ for name, value in content:
+ check_no_duplicates.description = \
+ "duplicate values of {0} raise an exception".format(name)
+ test = '// [config]\n{0}{1}// [end config]'.format(
+ ''.join(x[1] for x in content), value)
+
+ yield check_no_duplicates, test, name
--
2.0.0
More information about the Piglit
mailing list