[Piglit] [PATCH] framework: use os.path instead of manual path management

Dylan Baker baker.dylan.c at gmail.com
Thu Oct 31 15:46:16 CET 2013


Working with paths is hard, and we don't always do it right. Instead of
trying to be perfect, just use python's os.path module to do all of the
hard work for us

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/core.py      | 9 +++++----
 framework/exectest.py  | 2 +-
 framework/gleantest.py | 8 +++-----
 tests/es3conform.tests | 3 ++-
 tests/igt.tests        | 5 +++--
 tests/oglconform.tests | 2 +-
 6 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index 95854b1..2d5d0dc 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -205,9 +205,10 @@ def checkDir(dirname, failifexists):
             raise
 
 if 'PIGLIT_BUILD_DIR' in os.environ:
-    testBinDir = os.environ['PIGLIT_BUILD_DIR'] + '/bin/'
+    testBinDir = os.path.join(os.environ['PIGLIT_BUILD_DIR'], 'bin')
 else:
-    testBinDir = os.path.dirname(__file__) + '/../bin/'
+    testBinDir = os.path.normpath(os.path.join(os.path.dirname(__file__),
+                                               '../bin'))
 
 if 'PIGLIT_SOURCE_DIR' not in os.environ:
     p = os.path
@@ -485,7 +486,7 @@ class Test:
             if 'subtest' in result and len(result['subtest'].keys()) > 1:
                 for test in result['subtest'].keys():
                     result['result'] = result['subtest'][test]
-                    json_writer.write_dict_item(path + '/' + test, result)
+                    json_writer.write_dict_item(os.path.join(path, test), result)
             else:
                 json_writer.write_dict_item(path, result)
         else:
@@ -539,7 +540,7 @@ class TestProfile:
 
         def f(prefix, group, test_dict):
             for key in group:
-                fullkey = key if prefix == '' else prefix + '/' + key
+                fullkey = key if prefix == '' else os.path.join(prefix, key)
                 if isinstance(group[key], dict):
                     f(fullkey, group[key], test_dict)
                 else:
diff --git a/framework/exectest.py b/framework/exectest.py
index ebf8d28..bfb33da 100644
--- a/framework/exectest.py
+++ b/framework/exectest.py
@@ -250,7 +250,7 @@ class PlainExecTest(ExecTest):
     def __init__(self, command):
         ExecTest.__init__(self, command)
         # Prepend testBinDir to the path.
-        self.command[0] = testBinDir + self.command[0]
+        self.command[0] = os.path.join(testBinDir, self.command[0])
 
     def interpretResult(self, out, returncode, results, dmesg):
         outlines = out.split('\n')
diff --git a/framework/gleantest.py b/framework/gleantest.py
index 8099022..88432e0 100644
--- a/framework/gleantest.py
+++ b/framework/gleantest.py
@@ -1,5 +1,6 @@
 #
 # Permission is hereby granted, free of charge, to any person
+
 # obtaining a copy of this software and associated documentation
 # files (the "Software"), to deal in the Software without
 # restriction, including without limitation the rights to use,
@@ -26,17 +27,14 @@ import subprocess
 from core import checkDir, testBinDir, Test, TestResult
 from exectest import ExecTest
 
-
-def gleanExecutable():
-    return testBinDir + 'glean'
-
+glean_executable = os.path.join(testBinDir, "glean")
 
 # GleanTest: Execute a sub-test of Glean
 class GleanTest(ExecTest):
     globalParams = []
 
     def __init__(self, name):
-        ExecTest.__init__(self, [gleanExecutable(),
+        ExecTest.__init__(self, [glean_executable,
                                  "-o", "-v", "-v", "-v", "-t",
                                  "+"+name] + GleanTest.globalParams)
         self.name = name
diff --git a/tests/es3conform.tests b/tests/es3conform.tests
index 51b540d..b0e6ef0 100644
--- a/tests/es3conform.tests
+++ b/tests/es3conform.tests
@@ -73,7 +73,8 @@ def populateTests(runfile):
                 populateTests(newpath)
             else:
                 # Add the .test file
-                profile.test_list['es3conform/' + path.relpath(newpath, gtfroot)] = GTFTest(newpath)
+                group = path.join('es3conform', path.relpath(newpath, gtfroot))
+                profile.test_list[group] = GTFTest(newpath)
 
 
 # Populate the group with all the .test files
diff --git a/tests/igt.tests b/tests/igt.tests
index ec17de5..0f19c82 100644
--- a/tests/igt.tests
+++ b/tests/igt.tests
@@ -94,7 +94,7 @@ def listTests(listname):
 singleTests = listTests("list-single-tests")
 
 for test in singleTests:
-    profile.test_list['igt/' + test] = IGTTest(test)
+    profile.test_list[path.join('igt', test)] = IGTTest(test)
 
 def addSubTestCases(test):
     proc = subprocess.Popen(
@@ -112,7 +112,8 @@ def addSubTestCases(test):
     for subtest in subtests:
 	if subtest == "":
 	    continue
-	profile.test_list['igt/' + test + '/' + subtest] = IGTTest(test, ['--run-subtest', subtest])
+	profile.test_list[path.join('igt', test, subtest)] = \
+            IGTTest(test, ['--run-subtest', subtest])
 
 multiTests = listTests("list-multi-tests")
 
diff --git a/tests/oglconform.tests b/tests/oglconform.tests
index 8b52001..ace2f9c 100644
--- a/tests/oglconform.tests
+++ b/tests/oglconform.tests
@@ -70,6 +70,6 @@ with open(testlist_file) as f:
     for l in testlist:
         try:
             category, test = l.split()
-            profile.test_list['oglconform/' + category + '/' + test] = OGLCTest(category, test)
+            profile.test_list[path.join('oglconform', category, test)] = OGLCTest(category, test)
         except:
             continue
-- 
1.8.1.5



More information about the Piglit mailing list