patool/tests/__init__.py

86 lines
2.9 KiB
Python
Raw Normal View History

2010-02-21 11:14:57 +00:00
# -*- coding: utf-8 -*-
2012-04-08 16:54:37 +00:00
# Copyright (C) 2010-2012 Bastian Kleineidam
2010-02-21 11:14:57 +00:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import patoolib
2012-11-14 19:24:34 +00:00
import pytest
2012-05-24 21:09:37 +00:00
2010-02-21 11:14:57 +00:00
basedir = os.path.dirname(__file__)
datadir = os.path.join(basedir, 'data')
2012-05-24 21:09:37 +00:00
def needs_os (name):
"""Decorator skipping test if given program is not available."""
def check_prog (f):
def newfunc (*args, **kwargs):
if os.name != name:
2012-11-14 19:24:34 +00:00
raise pytest.skip("operating system %s not found" % name)
return f(*args, **kwargs)
newfunc.func_name = f.func_name
return newfunc
return check_prog
def needs_program (program):
"""Decorator skipping test if given program is not available."""
2010-02-21 11:14:57 +00:00
def check_prog (f):
def newfunc (*args, **kwargs):
if not patoolib.util.find_program(program):
2012-11-14 19:24:34 +00:00
raise pytest.skip("program `%s' not available" % program)
2010-02-21 11:14:57 +00:00
return f(*args, **kwargs)
newfunc.func_name = f.func_name
return newfunc
return check_prog
2010-03-11 17:33:58 +00:00
def needs_one_program (programs):
"""Decorator skipping test if not one of given programs are available."""
def check_prog (f):
def newfunc (*args, **kwargs):
for program in programs:
if patoolib.util.find_program(program):
break
else:
2012-11-14 19:24:34 +00:00
raise pytest.skip("None of programs %s available" % programs)
2010-03-11 17:33:58 +00:00
return f(*args, **kwargs)
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 patoolib.util.find_program(program):
2012-11-14 19:24:34 +00:00
raise pytest.skip("program `%s' not available" % program)
if not has_codec(program, codec):
2012-11-14 19:24:34 +00:00
raise pytest.skip("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 has_codec (program, codec):
"""Test if program supports given codec."""
if program == '7z' and codec == 'rar':
return patoolib.util.p7zip_supports_rar()
2012-05-23 03:19:14 +00:00
if patoolib.program_supports_compression(program, codec):
return True
return patoolib.util.find_program(codec)
2012-05-25 13:01:18 +00:00