Skip to content
Commits on Source (3)
......@@ -10,6 +10,7 @@ fi
export LIBGUESTFS_MEMSIZE=128
if [ "$(basename "$0")" = "pytest-with-recommends" ]; then
export DIFFOSCOPE_TESTS_FAIL_ON_MISSING_TOOLS=1
export DIFFOSCOPE_TESTS_MISSING_TOOLS="cbfstool procyon otool lipo oggDump wasm2wat"
fi
cp -r tests "$ADTTMP"
......
......@@ -54,6 +54,16 @@ def skipif(*args, **kwargs):
if os.environ.get('DIFFOSCOPE_TESTS_FAIL_ON_MISSING_TOOLS', None) != '1':
return pytest.mark.skipif(*args, **kwargs)
missing_tools = os.environ.get(
'DIFFOSCOPE_TESTS_MISSING_TOOLS', ''
).split()
missing_tools.append('/missing') # special value used in tests
tools_required = kwargs.get('tools', ())
if not tools_required or any(
x for x in tools_required if x in missing_tools
):
return pytest.mark.skipif(*args, **kwargs)
msg = "{} (DIFFOSCOPE_TESTS_FAIL_ON_MISSING_TOOLS=1)".format(
kwargs['reason']
)
......@@ -63,6 +73,7 @@ def skipif(*args, **kwargs):
# executed.
def outer(*args1, **kwargs1):
def inner(*args2, **kwargs2):
if args[0]: # i.e. the condition of the skipif() is True
return pytest.fail(msg)
return inner
......@@ -74,12 +85,13 @@ def skip_unless_tools_exist(*required):
return skipif(
tools_missing(*required),
reason="requires {}".format(" and ".join(required)),
tools=required,
)
def skip_if_tool_version_is(tool, actual_ver, target_ver, vcls=LooseVersion):
if tools_missing(tool):
return skipif(True, reason="requires {}".format(tool))
return skipif(True, reason="requires {}".format(tool), tools=(tool,))
if callable(actual_ver):
actual_ver = actual_ver()
return skipif(
......@@ -87,12 +99,13 @@ def skip_if_tool_version_is(tool, actual_ver, target_ver, vcls=LooseVersion):
reason="requires {} != {} ({} detected)".format(
tool, target_ver, actual_ver
),
tools=(tool,),
)
def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion):
if tools_missing(tool) and module_is_not_importable(tool):
return skipif(True, reason="requires {}".format(tool))
return skipif(True, reason="requires {}".format(tool), tools=(tool,))
if callable(actual_ver):
actual_ver = actual_ver()
return skipif(
......@@ -100,12 +113,13 @@ def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion):
reason="requires {} >= {} ({} detected)".format(
tool, min_ver, actual_ver
),
tools=(tool,),
)
def skip_unless_tool_is_at_most(tool, actual_ver, max_ver, vcls=LooseVersion):
if tools_missing(tool) and module_is_not_importable(tool):
return skipif(True, reason="requires {}".format(tool))
return skipif(True, reason="requires {}".format(tool), tools=(tool,))
if callable(actual_ver):
actual_ver = actual_ver()
return skipif(
......@@ -113,6 +127,7 @@ def skip_unless_tool_is_at_most(tool, actual_ver, max_ver, vcls=LooseVersion):
reason="requires {} <= {} ({} detected)".format(
tool, max_ver, actual_ver
),
tools=(tool,),
)
......@@ -120,7 +135,7 @@ def skip_unless_tool_is_between(
tool, actual_ver, min_ver, max_ver, vcls=LooseVersion
):
if tools_missing(tool):
return skipif(True, reason="requires {}".format(tool))
return skipif(True, reason="requires {}".format(tool), tools=(tool,))
if callable(actual_ver):
actual_ver = actual_ver()
return skipif(
......@@ -129,6 +144,7 @@ def skip_unless_tool_is_between(
reason="requires {} >= {} >= {} ({} detected)".format(
min_ver, tool, max_ver, actual_ver
),
tools=(tool,),
)
......@@ -139,6 +155,7 @@ def skip_if_binutils_does_not_support_x86():
return skipif(
'elf64-x86-64' not in get_supported_elf_formats(),
reason="requires a binutils capable of reading x86-64 binaries",
tools=('objdump',),
)
......@@ -170,6 +187,7 @@ def skip_unless_module_exists(name):
return skipif(
module_is_not_importable(name),
reason="requires {} module".format(name),
tools=('{}_module'.format(name)),
)
......