[Piglit] [patch v3 14/15] glsl_parser_test.py: Don't allow duplicate keys

Dylan Baker baker.dylan.c at gmail.com
Mon Jul 28 17:34:24 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             | 12 +++++++++++-
 framework/tests/glsl_parser_test_tests.py | 29 +++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index 5ffc101..9d768fe 100644
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -170,7 +170,17 @@ 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 {0} in file {1}'.format(
+                            match.group('key'), filepath))
+                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 8e29cc0..22a1f2c 100644
--- a/framework/tests/glsl_parser_test_tests.py
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -226,3 +226,32 @@ 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:
+        with utils.with_tempfile(content) as tfile:
+            glsl.GLSLParserTest(tfile)
+
+            nt.eq_(
+                e.exception.message,
+                'Duplicate entry for key {0} in file {1}'.format(dup, tfile))
+
+
+ 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.2



More information about the Piglit mailing list