[Piglit] [PATCH 3/4] Fix import_glsl_parser_tests' dependency on the number of dirs in basepath.

Paul Berry stereotype441 at gmail.com
Mon Aug 8 14:15:06 PDT 2011

To figure out where a test file belongs in the test hierarchy,
import_glsl_parser_tests has to determine the test file's path
relative to the "basepath" argument.

Before this patch, it worked out the relative path by dropping the
first three directories from the test file's path.  This worked
because import_glsl_parser_tests was always called with a basepath
that contained exactly three directory names, e.g. "./spec/glsl-1.00".
But it was a fragile assumption.

This patch changes import_glsl_parser_tests so that it uses
os.path.relpath() to work out the relative path.

I've also taken the liberty of fixing a typo in the docstring
explaining how basebath is used, and I've changed
"assert(type(testname) is str)" to "assert isinstance(testname,
basestring)", which works properly with Unicode.
 framework/glsl_parser_test.py |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index da8ff62..118df13 100755
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -58,7 +58,7 @@ def import_glsl_parser_tests(group, basepath, subdirectories):
 	the shader source file's path relative to ``basepath``. For example,
 		import_glsl_parser_tests(group, 'a', ['b1', 'b2'])
-	is called and the file 'a/b/c/d.frag' exists, then the test is
+	is called and the file 'a/b1/c/d.frag' exists, then the test is
 	registered into the group as ``group['b1/c/d.frag']``.
 	for d in subdirectories:
@@ -70,10 +70,11 @@ def import_glsl_parser_tests(group, basepath, subdirectories):
 				ext = f.rsplit('.')[-1]
 				if ext in ['vert', 'geom', 'frag']:
 					filepath = path.join(dirpath, f)
-					# testname := filepath with initial
-					#   three directories removed.
-					testname = '/'.join(filepath.split(os.sep)[3:])
-					assert(type(testname) is str)
+					# testname := filepath relative to
+					# basepath.
+					testname = os.path.relpath(
+						filepath, basepath)
+					assert isinstance(testname, basestring)

More information about the Piglit mailing list