[Piglit] [RFC 12/30] shader_test.py: use os.walk in add_shader_test_Dir
Dylan Baker
baker.dylan.c at gmail.com
Tue Jan 27 14:58:46 PST 2015
Python's os module provides a wonderful generator function for walking
directory trees, os.walk. By using os.walk with grouptools.join we don't
need to use a recursive function to add shader tests.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
framework/test/shader_test.py | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/framework/test/shader_test.py b/framework/test/shader_test.py
index 16d813f..5fd2de7 100644
--- a/framework/test/shader_test.py
+++ b/framework/test/shader_test.py
@@ -25,10 +25,10 @@
from __future__ import print_function, absolute_import
import os
-import os.path as path
import re
from .piglit_test import PiglitBaseTest
+from framework import grouptools
__all__ = [
'ShaderTest',
@@ -100,14 +100,15 @@ class ShaderTestParserException(Exception):
pass
-def add_shader_test_dir(group, dirpath):
+def add_shader_test_dir(group, startdir):
"""Add all shader tests in a directory to the given group."""
- for filename in os.listdir(dirpath):
- filepath = path.join(dirpath, filename)
- if path.isdir(filepath):
- add_shader_test_dir(group[filename], filepath)
- else:
+ for dirpath, _, filenames in os.walk(startdir):
+ for filename in filenames:
testname, ext = os.path.splitext(filename)
if ext != '.shader_test':
continue
- group[testname] = ShaderTest(filepath)
+
+ lgroup = grouptools.join(
+ grouptools.from_path(os.path.relpath(dirpath, startdir)),
+ testname)
+ group[lgroup] = ShaderTest(os.path.join(dirpath, filename))
--
2.2.2
More information about the Piglit
mailing list