Commit 042f422c authored by Markus Lehtonen's avatar Markus Lehtonen Committed by Guido Günther

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: 's avatarMarkus Lehtonen <markus.lehtonen@linux.intel.com>
parent 99b38114
......@@ -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"""
......
......@@ -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__} """
......
......@@ -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.
......
# 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'),
......
......@@ -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')
......
......@@ -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)
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