aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2018-01-23 10:48:58 +0200
committerGuido Günther <agx@sigxcpu.org>2018-03-01 12:01:27 +0100
commit042f422cf4adfd46cca7f024f1e941bc7c91c911 (patch)
tree1f67411ae89bc362235c99b37bb286f877b3236c /tests
parent99b38114d4923425e73135c4af1dbe9f41dc21d8 (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')
-rw-r--r--tests/11_test_dch_main.py5
-rw-r--r--tests/12_test_deb.py4
-rw-r--r--tests/13_test_gbp_pq.py2
-rw-r--r--tests/29_test_gbp_clone.py5
-rw-r--r--tests/doctests/test_Changelog.py5
-rw-r--r--tests/testutils/__init__.py16
6 files changed, 26 insertions, 11 deletions
diff --git a/tests/11_test_dch_main.py b/tests/11_test_dch_main.py
index d9023c3c..7fc82600 100644
--- a/tests/11_test_dch_main.py
+++ b/tests/11_test_dch_main.py
@@ -3,12 +3,11 @@
"""Test L{gbp.scripts.dch} main"""
from . import context
-from .testutils import (DebianGitTestRepo, OsReleaseFile,
+from .testutils import (DebianGitTestRepo, OsReleaseFile, skip_without_cmd,
get_dch_default_urgency, capture_stderr)
from gbp.scripts import dch
-import unittest
import os
import re
@@ -46,7 +45,7 @@ cl_debian = """test-package (0.9-1) unstable; urgency=%s
""" % default_urgency
-@unittest.skipIf(not os.path.exists('/usr/bin/debchange'), "Dch not found")
+@skip_without_cmd('debchange')
class TestScriptDch(DebianGitTestRepo):
"""Test git-dch"""
diff --git a/tests/12_test_deb.py b/tests/12_test_deb.py
index d06bc432..4a2388e2 100644
--- a/tests/12_test_deb.py
+++ b/tests/12_test_deb.py
@@ -136,7 +136,7 @@ Files:
self.assertEquals(dsc.sigs, [])
-@unittest.skipIf(not os.path.exists('/usr/bin/dpkg'), 'Dpkg not found')
+@testutils.skip_without_cmd('dpkg')
class TestDpkgCompareVersions(unittest.TestCase):
"""Test L{gbp.deb.DpkgCompareVersions}"""
@@ -160,7 +160,7 @@ class TestDpkgCompareVersions(unittest.TestCase):
self.cmp('_', '_ _')
-@unittest.skipIf(not os.path.exists('/usr/bin/dpkg'), 'Dpkg not found')
+@testutils.skip_without_cmd('dpkg')
class TestDeb(unittest.TestCase):
"""Test L{gbp.deb.__init__} """
diff --git a/tests/13_test_gbp_pq.py b/tests/13_test_gbp_pq.py
index 5f4668b6..dc53c260 100644
--- a/tests/13_test_gbp_pq.py
+++ b/tests/13_test_gbp_pq.py
@@ -77,7 +77,7 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo):
info = self.repo.get_commit_info('HEAD')
self.assertIn('Gbp-Pq: Name foobar', info['body'])
- @unittest.skipIf(not os.path.exists('/usr/bin/dpkg'), 'Dpkg not found')
+ @testutils.skip_without_cmd('dpkg')
def test_debian_missing_author(self):
"""
Check if we parse the author from debian control if it's missing in the patch.
diff --git a/tests/29_test_gbp_clone.py b/tests/29_test_gbp_clone.py
index 17e958e1..f1ac3925 100644
--- a/tests/29_test_gbp_clone.py
+++ b/tests/29_test_gbp_clone.py
@@ -1,10 +1,11 @@
# vim: set fileencoding=utf-8 :
from gbp.scripts.clone import vcs_git_url
-import os
import unittest
from mock import patch
+from . testutils import skip_without_cmd
+
class TestGbpClone(unittest.TestCase):
show_src = """
@@ -26,7 +27,7 @@ Vcs-Git: git://honk.sigxcpu.org/git/git-buildpackage.git
"""
- @unittest.skipIf(not os.path.exists('/usr/bin/dpkg'), 'Dpkg not found')
+ @skip_without_cmd('dpkg')
@patch('gbp.scripts.clone.apt_showsrc', return_value=show_src)
def test_vcs_git_url(self, patch):
self.assertEqual(vcs_git_url('git-buildpackage'),
diff --git a/tests/doctests/test_Changelog.py b/tests/doctests/test_Changelog.py
index dcaf08aa..1fb8a30b 100644
--- a/tests/doctests/test_Changelog.py
+++ b/tests/doctests/test_Changelog.py
@@ -4,7 +4,8 @@
Test L{gbp.deb.changelog.ChangeLog}
"""
from .. import context # noqa: 401
-import os
+from .. testutils import have_cmd
+
import nose
cl_debian = """git-buildpackage (0.5.32) unstable; urgency=low
@@ -48,7 +49,7 @@ cl_epoch = """xserver-xorg-video-nv (1:1.2.0-3) unstable; urgency=low
def setup():
"""Setup test module"""
- if not os.path.exists('/usr/bin/debchange'):
+ if not have_cmd('debchange'):
raise nose.SkipTest('debchange tool not present')
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)