1 # Copyright (C) 2014 Intra2net AG
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU Lesser General Public License as published
5 # by the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU Lesser General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see
15 # <http://www.gnu.org/licenses/lgpl-3.0.html>
17 # Authors: Victor Ramirez de la Corte <virako@wadobo.com>
18 # Eduardo Robles Elvira <edulix@wadobo.com>
25 from . import run_benchmark
26 from . import create_pseudo_random_files
28 DEFAULTS_COMPRESS_LEVEL_TEST = (int(42 / 10), 42, 42, 1, 8)
30 class CompressLevelTest(unittest.TestCase):
32 Small integration test that uses create_pseudo_random_files to create a
33 deterministic files and directories tree and then uses delta-tar with the
39 def __init__(self, num_dir=None, num_files=None, size=None,
40 compression_lvl_1=None, compression_lvl_2=None):
41 if isinstance (num_dir, str) and \
42 num_files is None and \
44 compression_lvl_1 is None and \
45 compression_lvl_2 is None:
47 num_dir = DEFAULTS_COMPRESS_LEVEL_TEST [0]
48 num_files = DEFAULTS_COMPRESS_LEVEL_TEST [1]
49 size = DEFAULTS_COMPRESS_LEVEL_TEST [2]
50 compression_lvl_1 = DEFAULTS_COMPRESS_LEVEL_TEST [3]
51 compression_lvl_2 = DEFAULTS_COMPRESS_LEVEL_TEST [4]
52 elif num_dir is None or \
53 num_files is None or \
55 compression_lvl_1 is None or \
56 compression_lvl_2 is None:
58 super(CompressLevelTest, self).__init__('test_compression_level')
59 self.num_dir = num_dir
60 self.num_files = num_files
62 self.compression_lvl_1 = compression_lvl_1
63 self.compression_lvl_2 = compression_lvl_2
67 Create pseudo random test files
69 shutil.rmtree("source_dir", ignore_errors=True)
70 args = ['--nfile', str(self.num_files),
71 '--ndir', str(self.num_dir),
72 '--size', str(self.size),
73 '--path', 'source_dir',
75 self.seed = create_pseudo_random_files.main(args)
79 Remove pseudo random files created by unit tests
81 shutil.rmtree("source_dir", ignore_errors=True)
83 def test_compression_level(self):
85 Create two test compression with two different compression level.
87 args = ['--test', 'delta-tarfile',
88 '-l', str(self.compression_lvl_1),
90 run_benchmark.main(args)
91 size1 = os.path.getsize('test_tarfile.tar.gz')
92 os.unlink('test_tarfile.tar.gz')
94 args = ['--test', 'delta-tarfile',
95 '-l', str(self.compression_lvl_2),
97 run_benchmark.main(args)
98 size2 = os.path.getsize('test_tarfile.tar.gz')
99 os.unlink('test_tarfile.tar.gz')
101 self.assertGreater(size1, size2, msg="""Fail test using lvl %d and
102 lvl %d, with the seed: %d. """ % (self.compression_lvl_1,
103 self.compression_lvl_2, self.seed))
107 suite = unittest.TestSuite()
109 suite.addTest(CompressLevelTest(int(size / 10), size, size, 1, 8))