This adds a test for overwriting an xz file in the non-backports.lzma
path, and a fix for overwriting an existing xz file.

Signed-off-by: Dylan Baker <dylanx.c.ba...@intel.com>
---
 framework/backends/compression.py           |  2 +-
 framework/tests/compressed_backend_tests.py | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/framework/backends/compression.py 
b/framework/backends/compression.py
index 6f867be..55cabe6 100644
--- a/framework/backends/compression.py
+++ b/framework/backends/compression.py
@@ -127,7 +127,7 @@ except ImportError:
                 try:
                     with open(os.devnull, 'w') as null:
                         subprocess.check_call(
-                            ['xz', '--compress', '-9', filename],
+                            ['xz', '--compress', '-9', '--force', filename],
                             stderr=null)
                 except OSError as e:
                     if e.errno == errno.ENOENT:
diff --git a/framework/tests/compressed_backend_tests.py 
b/framework/tests/compressed_backend_tests.py
index 6e0f4ec..5d9678e 100644
--- a/framework/tests/compressed_backend_tests.py
+++ b/framework/tests/compressed_backend_tests.py
@@ -30,6 +30,7 @@ import os
 import functools
 
 import nose.tools as nt
+from nose.plugins.skip import SkipTest
 
 from framework.tests import utils
 from framework.backends import compression, abstract
@@ -223,3 +224,23 @@ def test_update_piglit_conf():
 
     """
     nt.eq_(compression.get_mode(), 'foobar')
+
+
+@utils.set_env(PIGLIT_COMPRESSION='xz')
+@utils.test_in_tempdir
+def test_xz_shell_override():
+    """framework.backends.compression: the xz shell utility path can 
overwrite"""
+    # TODO: this test will not be required by python3, where the builtin lzma
+    # module replaces all of this.
+    try:
+        import backports.lzma  # pylint: disable=unused-variable
+    except ImportError:
+        pass
+    else:
+        raise SkipTest('Test requires shell path, not backports.lzma path.')
+
+    with open('foo.json.xz', 'w') as f:
+        f.write('foo')
+
+    with compression.COMPRESSORS['xz']('foo.json') as f:
+        f.write('foobar')
-- 
2.4.6

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to