[Piglit] [PATCH 3/4] framework: fix handling of files with a '.' in the name of the file

Dylan Baker baker.dylan.c at gmail.com
Wed Jul 22 18:11:22 PDT 2015


This adds a test and fixes it, so that when specifying a filename like
'foo.json..gz' it will work.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---

I'm kinda iffy as to whether this is a good idea. Maybe it would be
better to just add an assert that the filename doesn't end in '.'? How
often do people intentionally name things with two dots in them?

This is unnecessary after the next patch, which corrects the addition of
the extra dot.

 framework/backends/__init__.py    |  4 +++-
 framework/tests/backends_tests.py | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/framework/backends/__init__.py b/framework/backends/__init__.py
index 2950b33..5ce4d6f 100644
--- a/framework/backends/__init__.py
+++ b/framework/backends/__init__.py
@@ -135,7 +135,9 @@ def load(file_path):
             # i.e: Use .json.gz rather that .gz
             if extension in COMPRESSION_SUFFIXES:
                 compression = extension[1:]  # Drop the leading '.'
-                extension = os.path.splitext(name)[1]
+                # Remove any trailing '.', this fixes a bug where the filename
+                # is 'foo.json..xz, or similar
+                extension = os.path.splitext(name.rstrip('.'))[1]
 
             return extension, compression
 
diff --git a/framework/tests/backends_tests.py b/framework/tests/backends_tests.py
index 8084cdf..f2fad11 100644
--- a/framework/tests/backends_tests.py
+++ b/framework/tests/backends_tests.py
@@ -197,3 +197,18 @@ def test_set_meta_notimplemented():
     """backends.load(): An error is raised if a set_meta isn't properly implmented.
     """
     backends.set_meta('test_backend', {})
+
+
+ at nt.with_setup(_notimplemented_setup, _registry_teardown)
+ at nt.raises(backends.BackendNotImplementedError)
+ at utils.not_raises(backends.BackendError)
+def test_load_trailing_dot():
+    """framework.backends.load: handles the result name ending in '.'
+
+    Basically if this reaches a BackendNotImplementedError, then the '.' was
+    handled correctly, otherwise if it's '.' then we should reach the
+    BackendError, which is incorrect.
+    
+    """
+    backends.load('foo.test_backend..gz')
+
-- 
2.4.6



More information about the Piglit mailing list