[bmap-tools] [PATCH 2/4] tests: cover .xz files too
dedekind1 at gmail.com
dedekind1 at gmail.com
Wed Aug 14 07:50:43 EDT 2013
From: Artem Bityutskiy <artem.bityutskiy at intel.com>
Change-Id: I4e8318174a0a92f7c795c0c5cc61aeeff7237442
Signed-off-by: Artem Bityutskiy <artem.bityutskiy at intel.com>
---
tests/test_api_base.py | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/tests/test_api_base.py b/tests/test_api_base.py
index 58f64b3..e814fa0 100644
--- a/tests/test_api_base.py
+++ b/tests/test_api_base.py
@@ -57,6 +57,15 @@ def _generate_compressed_files(file_obj, delete=True):
import tarfile
import shutil
+ lzma_present = True
+ try:
+ import lzma
+ except ImportError:
+ try:
+ from backports import lzma
+ except ImportError:
+ lzma_present = False
+
# Make sure the temporary files start with the same name as 'file_obj' in
# order to simplify debugging.
prefix = os.path.splitext(os.path.basename(file_obj.name))[0] + '.'
@@ -95,6 +104,18 @@ def _generate_compressed_files(file_obj, delete=True):
yield gzip_file_obj.name
tmp_file_obj.close()
+ if lzma_present:
+ # Generate an .xz version of the file
+ tmp_file_obj = tempfile.NamedTemporaryFile('wb+', prefix=prefix,
+ delete=delete, dir=directory,
+ suffix='.xz')
+ lzma_file_obj = lzma.LZMAFile(tmp_file_obj.name, 'wb')
+ file_obj.seek(0)
+ shutil.copyfileobj(file_obj, lzma_file_obj)
+ lzma_file_obj.close()
+ yield lzma_file_obj.name
+ tmp_file_obj.close()
+
# Generate a tar.gz version of the file
tmp_file_obj = tempfile.NamedTemporaryFile('wb+', prefix=prefix,
delete=delete, dir=directory,
--
1.8.1.4
More information about the Bmap-tools
mailing list