tests: allow specifying which tools are known missing using...

tests: allow specifying which tools are known missing using DIFFOSCOPE_TESTS_MISSING_TOOLS, to override a DIFFOSCOPE_TESTS_FAIL_ON_MISSING_TOOLS
Signed-off-by: Mattia Rizzolo's avatarMattia Rizzolo <mattia@debian.org>
parent 2e111824
...@@ -54,6 +54,16 @@ def skipif(*args, **kwargs): ...@@ -54,6 +54,16 @@ def skipif(*args, **kwargs):
if os.environ.get('DIFFOSCOPE_TESTS_FAIL_ON_MISSING_TOOLS', None) != '1': if os.environ.get('DIFFOSCOPE_TESTS_FAIL_ON_MISSING_TOOLS', None) != '1':
return pytest.mark.skipif(*args, **kwargs) 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( msg = "{} (DIFFOSCOPE_TESTS_FAIL_ON_MISSING_TOOLS=1)".format(
kwargs['reason'] kwargs['reason']
) )
...@@ -74,12 +84,13 @@ def skip_unless_tools_exist(*required): ...@@ -74,12 +84,13 @@ def skip_unless_tools_exist(*required):
return skipif( return skipif(
tools_missing(*required), tools_missing(*required),
reason="requires {}".format(" and ".join(required)), reason="requires {}".format(" and ".join(required)),
tools=required,
) )
def skip_if_tool_version_is(tool, actual_ver, target_ver, vcls=LooseVersion): def skip_if_tool_version_is(tool, actual_ver, target_ver, vcls=LooseVersion):
if tools_missing(tool): if tools_missing(tool):
return skipif(True, reason="requires {}".format(tool)) return skipif(True, reason="requires {}".format(tool), tools=(tool,))
if callable(actual_ver): if callable(actual_ver):
actual_ver = actual_ver() actual_ver = actual_ver()
return skipif( return skipif(
...@@ -87,12 +98,13 @@ def skip_if_tool_version_is(tool, actual_ver, target_ver, vcls=LooseVersion): ...@@ -87,12 +98,13 @@ def skip_if_tool_version_is(tool, actual_ver, target_ver, vcls=LooseVersion):
reason="requires {} != {} ({} detected)".format( reason="requires {} != {} ({} detected)".format(
tool, target_ver, actual_ver tool, target_ver, actual_ver
), ),
tools=(tool,),
) )
def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion): def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion):
if tools_missing(tool) and module_is_not_importable(tool): 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): if callable(actual_ver):
actual_ver = actual_ver() actual_ver = actual_ver()
return skipif( return skipif(
...@@ -100,12 +112,13 @@ def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion): ...@@ -100,12 +112,13 @@ def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion):
reason="requires {} >= {} ({} detected)".format( reason="requires {} >= {} ({} detected)".format(
tool, min_ver, actual_ver tool, min_ver, actual_ver
), ),
tools=(tool,),
) )
def skip_unless_tool_is_at_most(tool, actual_ver, max_ver, vcls=LooseVersion): def skip_unless_tool_is_at_most(tool, actual_ver, max_ver, vcls=LooseVersion):
if tools_missing(tool) and module_is_not_importable(tool): 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): if callable(actual_ver):
actual_ver = actual_ver() actual_ver = actual_ver()
return skipif( return skipif(
...@@ -113,6 +126,7 @@ def skip_unless_tool_is_at_most(tool, actual_ver, max_ver, vcls=LooseVersion): ...@@ -113,6 +126,7 @@ def skip_unless_tool_is_at_most(tool, actual_ver, max_ver, vcls=LooseVersion):
reason="requires {} <= {} ({} detected)".format( reason="requires {} <= {} ({} detected)".format(
tool, max_ver, actual_ver tool, max_ver, actual_ver
), ),
tools=(tool,),
) )
...@@ -120,7 +134,7 @@ def skip_unless_tool_is_between( ...@@ -120,7 +134,7 @@ def skip_unless_tool_is_between(
tool, actual_ver, min_ver, max_ver, vcls=LooseVersion tool, actual_ver, min_ver, max_ver, vcls=LooseVersion
): ):
if tools_missing(tool): if tools_missing(tool):
return skipif(True, reason="requires {}".format(tool)) return skipif(True, reason="requires {}".format(tool), tools=(tool,))
if callable(actual_ver): if callable(actual_ver):
actual_ver = actual_ver() actual_ver = actual_ver()
return skipif( return skipif(
...@@ -129,6 +143,7 @@ def skip_unless_tool_is_between( ...@@ -129,6 +143,7 @@ def skip_unless_tool_is_between(
reason="requires {} >= {} >= {} ({} detected)".format( reason="requires {} >= {} >= {} ({} detected)".format(
min_ver, tool, max_ver, actual_ver min_ver, tool, max_ver, actual_ver
), ),
tools=(tool,),
) )
...@@ -139,6 +154,7 @@ def skip_if_binutils_does_not_support_x86(): ...@@ -139,6 +154,7 @@ def skip_if_binutils_does_not_support_x86():
return skipif( return skipif(
'elf64-x86-64' not in get_supported_elf_formats(), 'elf64-x86-64' not in get_supported_elf_formats(),
reason="requires a binutils capable of reading x86-64 binaries", reason="requires a binutils capable of reading x86-64 binaries",
tools=('objdump',),
) )
...@@ -170,6 +186,7 @@ def skip_unless_module_exists(name): ...@@ -170,6 +186,7 @@ def skip_unless_module_exists(name):
return skipif( return skipif(
module_is_not_importable(name), module_is_not_importable(name),
reason="requires {} module".format(name), reason="requires {} module".format(name),
tools=('{}_module'.format(name)),
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment