summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2015-07-22 17:51:54 -0700
committerDylan Baker <baker.dylan.c@gmail.com>2015-07-23 11:43:34 -0700
commit450067218d2fb3ebf64afe18dc20b9c8ff336b86 (patch)
treedaad0feba5df576592a092f374691d73da127b81
parent5bb1f960754d4dbe964eb383884eabfa4e279592 (diff)
framework: fix handling of files with a '.' in the name of the file
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@intel.com> Tested-by: Michel Dänzer <michel.daenzer@amd.com>
-rw-r--r--framework/backends/__init__.py4
-rw-r--r--framework/tests/backends_tests.py15
2 files changed, 18 insertions, 1 deletions
diff --git a/framework/backends/__init__.py b/framework/backends/__init__.py
index 2950b3383..5ce4d6f30 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 8084cdf00..f2fad1108 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', {})
+
+
+@nt.with_setup(_notimplemented_setup, _registry_teardown)
+@nt.raises(backends.BackendNotImplementedError)
+@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')
+