[Piglit] [patch v3 12/15] glsl_parser_test.py: Strict key checking for config section
Dylan Baker
baker.dylan.c at gmail.com
Mon Jul 28 17:34:22 PDT 2014
This enforces a set of valid keys, any key that isn't valid will raise
an exception with a message explaining the problem.
Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
framework/glsl_parser_test.py | 13 ++++++++++++-
framework/tests/glsl_parser_test_tests.py | 31 +++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index 1f1c1e7..5ffc101 100644
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -78,9 +78,15 @@ class GLSLParserTest(PiglitTest):
.tesc, .tese, .geom or .frag
"""
+ _CONFIG_KEYS = frozenset(['expect_result', 'glsl_version',
+ 'require_extensions', 'check_link'])
+
def __init__(self, filepath):
os.stat(filepath)
+ # a set that stores a list of keys that have been found already
+ self.__found_keys = set()
+
# Parse the config file and get the config section, then write this
# section to a StringIO and pass that to ConfigParser
with open(filepath, 'r') as testfile:
@@ -159,11 +165,16 @@ class GLSLParserTest(PiglitTest):
match = is_metadata.match(line)
if match:
+ if match.group('key') not in GLSLParserTest._CONFIG_KEYS:
+ raise GLSLParserException(
+ "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')
else:
raise GLSLParserException(
"The config section is malformed."
- "Check file {0}".format(filepath))
+ "Check file {0} for line {1}".format(filepath, line))
else:
raise GLSLParserException("No [end config] section found!")
diff --git a/framework/tests/glsl_parser_test_tests.py b/framework/tests/glsl_parser_test_tests.py
index b4e9c24..8e29cc0 100644
--- a/framework/tests/glsl_parser_test_tests.py
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -195,3 +195,34 @@ def test_config_to_command():
check_config_to_command.description = \
'Command correctly generated for {}'.format(desc)
yield check_config_to_command, config, result
+
+
+def test_bad_section_name():
+ """ A section name not in the _CONFIG_KEYS name raises an error """
+ content = ('// [config]\n'
+ '// expect_result: pass\n'
+ '// glsl_version: 1.00\n'
+ '// new_awesome_key: foo\n'
+ '// [end config]\n')
+
+ with nt.assert_raises(glsl.GLSLParserException) as e:
+ _, name = _check_config(content)
+
+ nt.eq_(e.exception.message,
+ 'Key new_awesome_key in file {0 is not a valid key for a '
+ 'glslparser test config block'.format(name))
+
+
+def test_good_section_names():
+ """ A section name in the _CONFIG_KEYS does not raise an error """
+ content = ('// [config]\n'
+ '// expect_result: pass\n'
+ '// glsl_version: 1.00\n'
+ '// require_extensions: EXT_foo\n'
+ '// check_link: True\n'
+ '// [end config]\n')
+
+ try:
+ _check_config(content)
+ except glsl.GLSLParserException as e:
+ raise AssertionError(e)
--
2.0.2
More information about the Piglit
mailing list