summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-01-19 11:46:30 +0100
committerGuido Günther <agx@sigxcpu.org>2017-01-19 11:46:51 +0100
commit588b70c21ee5a30620aa9d2f3ef646e456e8dce3 (patch)
tree73cf8b43e0d037c7236d07d6381b82fe0acbd2c7
parent5211ab98f09f77082841538a1b3db935b2f21a2f (diff)
component tests: simpler test fixtures
We often need a prepared repo so add decorators for that
-rw-r--r--tests/component/deb/fixtures.py76
-rw-r--r--tests/component/deb/test_buildpackage.py68
-rw-r--r--tests/component/deb/test_clone.py53
3 files changed, 112 insertions, 85 deletions
diff --git a/tests/component/deb/fixtures.py b/tests/component/deb/fixtures.py
new file mode 100644
index 00000000..78dbb31b
--- /dev/null
+++ b/tests/component/deb/fixtures.py
@@ -0,0 +1,76 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2017 Guido Guenther <agx@sigxcpu.org>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, please see
+# <http://www.gnu.org/licenses/>
+
+import os
+
+from functools import wraps
+from tests.component import (ComponentTestBase,
+ ComponentTestGitRepository)
+from tests.component.deb import DEB_TEST_DATA_DIR
+
+from nose.tools import eq_
+
+from gbp.deb.dscfile import DscFile
+from gbp.scripts.import_dsc import main as import_dsc
+
+DEFAULT_NATIVE = os.path.join(DEB_TEST_DATA_DIR,
+ 'dsc-native',
+ 'git-buildpackage_%s.dsc' % '0.4.14')
+
+DEFAULT_QUILT30 = os.path.join(DEB_TEST_DATA_DIR,
+ 'dsc-3.0',
+ 'hello-debhelper_%s.dsc' % '2.8-1')
+
+
+class RepoFixtures(object):
+ @classmethod
+ def native(cls, fn, dsc=DEFAULT_NATIVE):
+ """Debian native test fixture"""
+ @wraps(fn)
+ def _native_repo(*args):
+ repo = cls.import_native(dsc)
+ return fn(*args, repo=repo)
+ return _native_repo
+
+ @classmethod
+ def quilt30(cls, fn, dsc=DEFAULT_QUILT30):
+ @wraps(fn)
+ def _quilt30_repo(*args):
+ repo = cls.import_quilt30(dsc)
+ return fn(*args, repo=repo)
+ return _quilt30_repo
+
+ @classmethod
+ def import_native(cls, dsc=DEFAULT_NATIVE):
+ assert import_dsc(['arg0', dsc]) == 0
+ parsed = DscFile(dsc)
+ repo = ComponentTestGitRepository(parsed.pkg)
+ ComponentTestBase._check_repo_state(repo, 'master', ['master'])
+ eq_(len(repo.get_commits()), 1)
+ return repo
+
+ @classmethod
+ def import_quilt30(cls, dsc=DEFAULT_QUILT30):
+ assert import_dsc(['arg0', dsc]) == 0
+ parsed = DscFile(dsc)
+ repo = ComponentTestGitRepository(parsed.pkg)
+ ComponentTestBase._check_repo_state(repo, 'master', ['master',
+ 'upstream'])
+ eq_(len(repo.get_commits()), 2)
+ return repo
+ assert eq_(len(repo.get_commits()), 2)
+ return repo
diff --git a/tests/component/deb/test_buildpackage.py b/tests/component/deb/test_buildpackage.py
index f5b9c415..c3dea352 100644
--- a/tests/component/deb/test_buildpackage.py
+++ b/tests/component/deb/test_buildpackage.py
@@ -23,6 +23,7 @@ import subprocess
from tests.component import (ComponentTestBase,
ComponentTestGitRepository)
from tests.component.deb import DEB_TEST_DATA_DIR
+from tests.component.deb.fixtures import RepoFixtures
from nose.tools import ok_, eq_, assert_false, assert_true
@@ -39,19 +40,15 @@ class TestBuildpackage(ComponentTestBase):
dir,
'%s_%s.dsc' % (pkg, version))
- def _test_buildpackage(self, pkg, dir, version, opts=[]):
- dsc = self._dsc_name(pkg, version, dir)
- assert import_dsc(['arg0', dsc]) == 0
- ComponentTestGitRepository(pkg)
- prebuild_out = os.path.join(os.path.abspath(pkg), 'prebuild.out')
- postbuild_out = os.path.join(os.path.abspath(pkg), 'postbuild.out')
- os.chdir(pkg)
-
+ def _test_buildpackage(self, repo, opts=[]):
+ prebuild_out = os.path.join(repo.path, 'prebuild.out')
+ postbuild_out = os.path.join(repo.path, 'postbuild.out')
args = ['arg0',
'--git-prebuild=printenv > %s' % prebuild_out,
'--git-postbuild=printenv > %s' % postbuild_out,
'--git-builder=/bin/true',
'--git-cleaner=/bin/true'] + opts
+ os.chdir(repo.path)
ret = buildpackage(args)
ok_(ret == 0, "Building the package failed")
eq_(os.path.exists(prebuild_out), True)
@@ -66,24 +63,19 @@ class TestBuildpackage(ComponentTestBase):
"GBP_CHANGES_FILE",
"GBP_BUILD_DIR"])
- def test_debian_buildpackage(self):
+ @RepoFixtures.native
+ def test_debian_buildpackage(self, repo):
"""Test that building a native debian package works"""
- self._test_buildpackage('git-buildpackage', 'dsc-native', '0.4.14')
+ self._test_buildpackage(repo)
- def test_non_native_buildpackage(self):
+ @RepoFixtures.quilt30
+ def test_non_native_buildpackage(self, repo):
"""Test that building a source 3.0 debian package works"""
- self._test_buildpackage('hello-debhelper', 'dsc-3.0', '2.8-1')
+ self._test_buildpackage(repo)
- def test_tag_only(self):
+ @RepoFixtures.native
+ def test_tag_only(self, repo):
"""Test that only tagging a native debian package works"""
- def _dsc(version):
- return os.path.join(DEB_TEST_DATA_DIR,
- 'dsc-native',
- 'git-buildpackage_%s.dsc' % version)
-
- dsc = _dsc('0.4.14')
- assert import_dsc(['arg0', dsc]) == 0
- repo = ComponentTestGitRepository('git-buildpackage')
os.chdir('git-buildpackage')
repo.delete_tag('debian/0.4.14') # make sure we can tag again
ret = buildpackage(['arg0',
@@ -144,23 +136,15 @@ class TestBuildpackage(ComponentTestBase):
for t in tarballs:
self.assertTrue(os.path.exists(t), "Tarball %s not found" % t)
- def test_export_dir_buildpackage(self):
+ @RepoFixtures.quilt30
+ def test_export_dir_buildpackage(self, repo):
"""Test that building with a export dir works"""
- self._test_buildpackage('hello-debhelper',
- 'dsc-3.0',
- '2.8-1',
- ['--git-export-dir=../foo/bar'])
+ self._test_buildpackage(repo, ['--git-export-dir=../foo/bar'])
ok_(os.path.exists('../foo/bar'))
- def test_argument_quoting(self):
+ @RepoFixtures.native
+ def test_argument_quoting(self, repo):
"""Test that we quote arguments to builder (#)"""
- def _dsc(version):
- return os.path.join(DEB_TEST_DATA_DIR,
- 'dsc-native',
- 'git-buildpackage_%s.dsc' % version)
-
- dsc = _dsc('0.4.14')
- assert import_dsc(['arg0', dsc]) == 0
os.chdir('git-buildpackage')
with open('../arg with spaces', 'w'):
pass
@@ -173,12 +157,10 @@ class TestBuildpackage(ComponentTestBase):
'../arg with spaces'])
ok_(ret == 0, "Building the package failed")
- def test_tarball_default_compression(self):
+ @RepoFixtures.quilt30
+ def test_tarball_default_compression(self, repo):
"""Test that we use defaults for compression if not given (#820846)"""
- self._test_buildpackage('hello-debhelper',
- 'dsc-3.0',
- '2.8-1',
- ['--git-no-pristine-tar'])
+ self._test_buildpackage(repo, ['--git-no-pristine-tar'])
tarball = "../hello-debhelper_2.8.orig.tar.gz"
out = subprocess.check_output(["file", tarball])
ok_("max compression" not in out)
@@ -192,11 +174,9 @@ class TestBuildpackage(ComponentTestBase):
m2 = hashlib.md5(open(tarball, 'rb').read()).hexdigest()
eq_(m1, m2, "Regenerated tarball has different checksum")
- def test_tarball_max_compression(self):
+ @RepoFixtures.quilt30
+ def test_tarball_max_compression(self, repo):
"""Test that passing max compression works (#820846)"""
- self._test_buildpackage('hello-debhelper',
- 'dsc-3.0',
- '2.8-1',
- ['--git-no-pristine-tar', '--git-compression-level=9'])
+ self._test_buildpackage(repo, ['--git-no-pristine-tar', '--git-compression-level=9'])
out = subprocess.check_output(["file", "../hello-debhelper_2.8.orig.tar.gz"])
ok_("max compression" in out)
diff --git a/tests/component/deb/test_clone.py b/tests/component/deb/test_clone.py
index 61bf46e2..9beea644 100644
--- a/tests/component/deb/test_clone.py
+++ b/tests/component/deb/test_clone.py
@@ -20,49 +20,30 @@ import os
from tests.component import (ComponentTestBase,
ComponentTestGitRepository)
-from tests.component.deb import DEB_TEST_DATA_DIR
+from tests.component.deb.fixtures import RepoFixtures
from nose.tools import ok_
-from gbp.scripts.import_dsc import main as import_dsc
from gbp.scripts.clone import main as clone
class TestClone(ComponentTestBase):
"""Test cloning from a remote"""
- def test_clone_nonempty(self):
+ @RepoFixtures.native
+ def test_clone_nonempty(self, repo):
"""Test that cloning into an existing dir fails"""
- def _dsc(version):
- return os.path.join(DEB_TEST_DATA_DIR,
- 'dsc-native',
- 'git-buildpackage_%s.dsc' % version)
-
- # Build up somethng we can clone from
- dsc = _dsc('0.4.14')
- assert import_dsc(['arg0', dsc]) == 0
- repo = ComponentTestGitRepository('git-buildpackage')
- self._check_repo_state(repo, 'master', ['master'])
- assert len(repo.get_commits()) == 1
-
ok_(clone(['arg0', repo.path]) == 1,
"Cloning did no fail as expected")
- self._check_log(-2, "gbp:error: Git command failed: Error running git clone: fatal: destination path 'git-buildpackage' already exists and is not an empty directory.")
-
- def test_clone_native(self):
+ self._check_log(-2,
+ "gbp:error: Git command failed: Error "
+ "running git clone: fatal: destination path "
+ "'git-buildpackage' already exists and is not "
+ "an empty directory.")
+
+ @RepoFixtures.native
+ def test_clone_native(self, repo):
"""Test that cloning of debian native packages works"""
- def _dsc(version):
- return os.path.join(DEB_TEST_DATA_DIR,
- 'dsc-native',
- 'git-buildpackage_%s.dsc' % version)
-
- # Build up somethng we can clone from
- dsc = _dsc('0.4.14')
- assert import_dsc(['arg0', dsc]) == 0
- repo = ComponentTestGitRepository('git-buildpackage')
- self._check_repo_state(repo, 'master', ['master'])
- assert len(repo.get_commits()) == 1
-
dest = os.path.join(self._tmpdir,
'cloned_repo')
clone(['arg0',
@@ -75,20 +56,10 @@ class TestClone(ComponentTestBase):
def test_clone_environ(self):
"""Test that environment variables influence git configuration"""
- def _dsc(version):
- return os.path.join(DEB_TEST_DATA_DIR,
- 'dsc-native',
- 'git-buildpackage_%s.dsc' % version)
-
# Build up somethng we can clone from
- dsc = _dsc('0.4.14')
os.environ['DEBFULLNAME'] = 'testing tester'
os.environ['DEBEMAIL'] = 'gbp-tester@debian.invalid'
- assert import_dsc(['arg0', dsc]) == 0
- repo = ComponentTestGitRepository('git-buildpackage')
- self._check_repo_state(repo, 'master', ['master'])
- assert len(repo.get_commits()) == 1
-
+ repo = RepoFixtures.import_native()
got = repo.get_config("user.email")
want = os.environ['DEBEMAIL']
ok_(got == want, "unexpected git config user.email: got %s, want %s" % (got, want))