From 335e2417ac7410f3725ac360f673525d04854c17 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Tue, 27 Nov 2012 14:38:32 +0200 Subject: [PATCH] test_api_base: test .tar.gz and .tar.bz2 compression This actually revealed a bug... Change-Id: Ife39862d4b9e71beea5b5150970da9066782145b Signed-off-by: Artem Bityutskiy --- 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 5f4b73e..3342ffa 100644 --- a/tests/test_api_base.py +++ b/tests/test_api_base.py @@ -48,6 +48,7 @@ def _generate_compressed_files(file_obj, delete = True): import bz2 import gzip + import tarfile import shutil # Make sure the temporary files start with the same name as 'file_obj' in @@ -78,6 +79,26 @@ def _generate_compressed_files(file_obj, delete = True): yield gzip_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, + suffix = '.tar.gz') + tgz_file_obj = tarfile.open(tmp_file_obj.name, "w:gz") + tgz_file_obj.add(file_obj.name) + tgz_file_obj.close() + yield tgz_file_obj.name + tmp_file_obj.close() + + # Generate a tar.bz2 version of the file + tmp_file_obj = tempfile.NamedTemporaryFile('wb+', prefix = prefix, + delete = delete, dir = directory, + suffix = '.tar.gz') + tbz2_file_obj = tarfile.open(tmp_file_obj.name, "w:bz2") + tbz2_file_obj.add(file_obj.name) + tbz2_file_obj.close() + yield tbz2_file_obj.name + tmp_file_obj.close() + def _calculate_sha1(file_obj): """ Calculates SHA1 checksum for the contents of file object 'file_obj'. """ -- 2.7.4