diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2018-01-23 10:48:58 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2018-03-01 12:01:27 +0100 |
commit | 042f422cf4adfd46cca7f024f1e941bc7c91c911 (patch) | |
tree | 1f67411ae89bc362235c99b37bb286f877b3236c /tests/testutils | |
parent | 99b38114d4923425e73135c4af1dbe9f41dc21d8 (diff) |
tests.testutils: helpers for checking existence of commands
Add new have_cmd() helper for checking if a command is available,
and, a skip_without_cmd() decorator for skipping tests in case a command
is missing. Convert existing checks for commands to use these new
functions.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'tests/testutils')
-rw-r--r-- | tests/testutils/__init__.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/tests/testutils/__init__.py b/tests/testutils/__init__.py index c17bc815..6ce1bc59 100644 --- a/tests/testutils/__init__.py +++ b/tests/testutils/__init__.py @@ -7,6 +7,7 @@ import shutil import subprocess import tarfile import tempfile +import unittest import zipfile import gbp.log @@ -22,7 +23,7 @@ __all__ = ['GbpLogTester', 'DebianGitTestRepo', 'OsReleaseFile', 'MockedChangeLog', 'get_dch_default_urgency', 'capture_stderr', 'capture_stdout', 'ls_dir', 'ls_tar', 'ls_zip', - 'patch_popen'] + 'patch_popen', 'have_cmd', 'skip_without_cmd'] class OsReleaseFile(object): @@ -127,3 +128,16 @@ def ls_zip(archive, directories=True): return ls_dir(tmpdir, directories) finally: shutil.rmtree(tmpdir) + + +def have_cmd(cmd): + """Check if a command is available""" + return True if shutil.which(cmd) else False + + +def skip_without_cmd(cmd): + """Skip if a command is not available""" + if have_cmd(cmd): + return lambda func: func + else: + return unittest.skip("Command '%s' not found" % cmd) |