diff --git a/tests/__init__.py b/tests/__init__.py index c07eb59..4024c5e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -93,3 +93,23 @@ def needs_program (program): newfunc.func_name = f.func_name return newfunc return check_prog + + +def needs_codec (program, codec): + """Decorator skipping test if given program codec is not available.""" + def check_prog (f): + def newfunc (*args, **kwargs): + if not find_codec(program, codec): + raise nose.SkipTest("codec `%s' for program `%s' not available" % (codec, program)) + return f(*args, **kwargs) + newfunc.func_name = f.func_name + return newfunc + return check_prog + + +def find_codec (program, codec): + if program == '7z' and codec == 'rar': + return os.path.exists('/usr/lib/p7zip/Codecs/Rar29.so') + if program == 'tar': + return find_executable(codec) + return False diff --git a/tests/test_archives.py b/tests/test_archives.py index 96a4da8..28833a5 100644 --- a/tests/test_archives.py +++ b/tests/test_archives.py @@ -13,27 +13,70 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from . import ArchiveTest, needs_program +from . import ArchiveTest, needs_program, needs_codec class TestArchives (ArchiveTest): @needs_program('tar') def test_tar (self): self.program = 'tar' - self.tar_test() + self.archive_commands('t.tar') + + @needs_codec('tar', 'gzip') + def test_tar_gz (self): + self.program = 'tar' + self.archive_commands('t.tar.gz') + + @needs_codec('tar', 'compress') + def test_tar_z (self): + self.program = 'tar' + self.archive_commands('t.tar.Z') + + @needs_codec('tar', 'bzip2') + def test_tar_bz2 (self): + self.program = 'tar' + self.archive_commands('t.tar.bz2') + self.archive_commands('t.tbz2') + + @needs_codec('tar', 'lzma') + def test_tar_lzma (self): + self.program = 'tar' + self.archive_commands('t.tar.lzma') + + @needs_codec('tar', 'xz') + def test_tar_xz (self): + self.program = 'tar' + self.archive_commands('t.tar.xz') @needs_program('star') def test_star (self): self.program = 'star' - self.tar_test() - - def tar_test (self): self.archive_commands('t.tar') + + @needs_codec('tar', 'gzip') + def test_star_gz (self): + self.program = 'star' self.archive_commands('t.tar.gz') + + @needs_codec('tar', 'compress') + def test_star_z (self): + self.program = 'star' self.archive_commands('t.tar.Z') + + @needs_codec('tar', 'bzip2') + def test_star_bz2 (self): + self.program = 'star' self.archive_commands('t.tar.bz2') self.archive_commands('t.tbz2') + + @needs_codec('tar', 'lzma') + def test_star_lzma (self): + self.program = 'star' self.archive_commands('t.tar.lzma') + + @needs_codec('tar', 'xz') + def test_star_xz (self): + self.program = 'star' self.archive_commands('t.tar.xz') @needs_program('bzip2') @@ -120,6 +163,7 @@ class TestArchives (ArchiveTest): self.archive_test('t.deb') @needs_program('7z') + @needs_codec('7z', 'rar') def test_p7zip_rar (self): # only succeeds with the rar module for 7z installed self.program = '7z'