[Piglit] [PATCH] framework: when searching a directory ignore files ending in .old

Dylan Baker baker.dylan.c at gmail.com
Thu Jul 30 08:30:55 PDT 2015


Currently if piglit updates a result to a new version, then tries to
load from the same directory the first result will be
'results.json.old', and piglit will interpret the '.old' as a
compression extension, and die in a fire.

With this patch when searching a folder (but not when pointing directly
at a file) piglit will ignore any files ending in '.old', which will
correct the problem.

A unit test is also included.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/backends/__init__.py    |  2 +-
 framework/tests/backends_tests.py | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/framework/backends/__init__.py b/framework/backends/__init__.py
index 5ce4d6f..b0f784f 100644
--- a/framework/backends/__init__.py
+++ b/framework/backends/__init__.py
@@ -145,7 +145,7 @@ def load(file_path):
             return _extension(file_path)
         else:
             for file_ in os.listdir(file_path):
-                if file_.startswith('result'):
+                if file_.startswith('result') and not file_.endswith('.old'):
                     return _extension(file_)
 
         tests = os.path.join(file_path, 'tests')
diff --git a/framework/tests/backends_tests.py b/framework/tests/backends_tests.py
index f2fad11..39e3e2d 100644
--- a/framework/tests/backends_tests.py
+++ b/framework/tests/backends_tests.py
@@ -212,3 +212,20 @@ def test_load_trailing_dot():
     """
     backends.load('foo.test_backend..gz')
 
+
+ at nt.with_setup(_notimplemented_setup, _registry_teardown)
+ at utils.test_in_tempdir
+ at nt.raises(backends.BackendError)
+def test_load_old():
+    """backends.load(): Ignores files ending in '.old'
+
+    If this raises a BackendError it means it didn't find a backend to use,
+    thus it skipped the file ending in '.old'.
+    
+    """
+    os.mkdir('test')
+    file_path = os.path.join('test', 'results.test_backend.old')
+    with open(file_path, 'w') as f:
+        f.write('foo')
+
+    backends.load('test')
-- 
2.4.6



More information about the Piglit mailing list