From: Artem Bityutskiy Date: Wed, 14 Aug 2013 10:33:09 +0000 (+0300) Subject: tests: cover .xz files too X-Git-Tag: v2.6~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4ece71be8c16f34adbf475945b556d62f1eba22e;p=tools%2Fbmap-tools.git tests: cover .xz files too Change-Id: I4e8318174a0a92f7c795c0c5cc61aeeff7237442 Signed-off-by: Artem Bityutskiy --- 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,