Skip to content
Snippets Groups Projects
Verified Commit cf4a4c3b authored by Mattia Rizzolo's avatar Mattia Rizzolo
Browse files

tests: rewrite tool_older_than() into skip_unless_tool_is_older_than()

parent 3b98ffeb
No related branches found
No related tags found
No related merge requests found
......@@ -19,16 +19,20 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import pytest
import subprocess
from diffoscope.comparators.ar import ArFile
from diffoscope.comparators.utils import diff_ignore_line_numbers
from utils import skip_unless_tools_exist, tool_older_than, data, \
load_fixture, assert_non_existing
from utils import skip_unless_tools_exist, skip_unless_tool_is_older_than, \
data, load_fixture, assert_non_existing
rlib1 = load_fixture(data('test1.rlib'))
rlib2 = load_fixture(data('test2.rlib'))
def llvm_version():
return subprocess.check_output(['llvm-config', '--version']).decode("utf-8").strip()
def test_identification(rlib1):
assert isinstance(rlib1, ArFile)
......@@ -60,7 +64,7 @@ def test_item2_rust_metadata_bin(differences):
assert differences[2].source2 == 'rust.metadata.bin'
@skip_unless_tools_exist('llvm-dis')
@pytest.mark.skipif(tool_older_than(['llvm-config', '--version'], '3.8'), reason='llvm version too low')
@skip_unless_tool_is_older_than('llvm-config', llvm_version, '3.8')
def test_item3_deflate_llvm_bitcode(differences):
assert differences[3].source1 == 'alloc_system-d16b8f0e.0.bytecode.deflate'
assert differences[3].source2 == 'alloc_system-d16b8f0e.0.bytecode.deflate'
......
......@@ -24,7 +24,8 @@ from diffoscope.config import Config
from diffoscope.difference import Difference
from diffoscope.comparators.utils import Command
from utils import tools_missing, skip_unless_tools_exist, data, load_fixture
from utils import tools_missing, skip_unless_tools_exist, data, load_fixture, \
skip_unless_tool_is_older_than
try:
import tlsh # noqa
......@@ -50,6 +51,16 @@ def test_skip_unless_tools_exist_empty():
def test_skip_unless_tools_exist_missing():
pytest.xfail("Test should always be skipped")
def skip_unless_tool_is_older_than():
func = skip_unless_tool_is_older_than
assert func('/missing', 1, 1).name is 'skip'
# pytest.skipif().args[0] contains the evaluated statement
assert func('cat', 1, 1).args[0] is False
assert func('cat', 1, '1.2d.45+b8').args[0] is True
def version():
return '4.3-git'
assert func('cat', version, '4.3').args[0] is False
@pytest.mark.skipif(miss_tlsh, reason='tlsh is missing')
def test_fuzzy_matching(fuzzy_tar1, fuzzy_tar2):
differences = fuzzy_tar1.compare(fuzzy_tar2).details
......
......@@ -20,10 +20,9 @@
import os
import pytest
import diffoscope
import subprocess
from distutils.spawn import find_executable
from distutils.version import StrictVersion
from distutils.version import LooseVersion
from diffoscope.config import Config
from diffoscope.comparators import specialize
......@@ -45,6 +44,16 @@ def skip_unless_tools_exist(*required):
reason="requires {}".format(" and ".join(required)),
)
def skip_unless_tool_is_older_than(tool, actual_ver, min_ver, vcls=LooseVersion):
if tools_missing(tool):
return pytest.mark.skip(reason="requires {}".format(tool))
if callable(actual_ver):
actual_ver = actual_ver()
return pytest.mark.skipif(
vcls(str(actual_ver)) < vcls(str(min_ver)),
reason="requires {} >= {}".format(tool, min_ver)
)
def load_fixture(filename):
return pytest.fixture(
lambda: specialize(FilesystemFile(filename))
......@@ -57,12 +66,6 @@ def data(filename):
filename,
)
def tool_older_than(cmdline, min_ver, vcls=StrictVersion):
if find_executable(cmdline[0]) is None:
return True
actual_ver = subprocess.check_output(cmdline).decode("utf-8").strip()
return vcls(actual_ver) < vcls(min_ver)
def assert_non_existing(monkeypatch, fixture, has_null_source=True, has_details=True):
monkeypatch.setattr(Config.general, 'new_file', True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment