[Piglit] [PATCH 21/35] profile: allow forcing python or xml loading

Dylan Baker dylan at pnwbakers.com
Wed Apr 4 22:27:09 UTC 2018


This will be used during build time to allow profiles that modify other
profiles to load XML instead of rebuilding.
---
 framework/profile.py | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/framework/profile.py b/framework/profile.py
index 7b1b41b..2395b22 100644
--- a/framework/profile.py
+++ b/framework/profile.py
@@ -429,7 +429,7 @@ class TestProfile(object):
                 yield k, v
 
 
-def load_test_profile(filename):
+def load_test_profile(filename, python=None):
     """Load a python module and return it's profile attribute.
 
     All of the python test files provide a profile attribute which is a
@@ -449,15 +449,24 @@ def load_test_profile(filename):
 
     Arguments:
     filename -- the name of a python module to get a 'profile' from
+
+    Keyword Arguments:
+    python -- If this is None (the default) XML is tried, and then a python
+              module. If True, then only python is tried, if False then only
+              XML is tried.
     """
     name = os.path.splitext(os.path.basename(filename))[0]
-    xml = os.path.join(ROOT_DIR, 'tests', name + '.xml')
-    if os.path.exists(xml):
-        return XMLProfile(xml)
+    xml = os.path.join('tests', name + '.xml')
+    if not python:
+        xml = os.path.join(ROOT_DIR, 'tests', name + '.xml')
+        if os.path.exists(xml):
+            return XMLProfile(xml)
+
+    if python is False:
+        raise exceptions.PiglitFatalError('Cannot open "tests/{}.xml"'.format(name))
 
     try:
-        mod = importlib.import_module('tests.{0}'.format(
-            os.path.splitext(os.path.basename(filename))[0]))
+        mod = importlib.import_module('tests.{0}'.format(name))
     except ImportError:
         raise exceptions.PiglitFatalError(
             'Failed to import "{}", there is either something wrong with the '
-- 
git-series 0.9.1


More information about the Piglit mailing list