diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2014-02-25 12:12:27 +0200 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2014-02-25 13:23:18 +0200 |
commit | be28b24e9617c6ac59c5a5b33c46245a34cdef61 (patch) | |
tree | 1554e56c3329a375de8c9a75f4d53f33517b84e3 /tests | |
parent | a97ef1445a155d34bbeb84a3be74129515af2264 (diff) | |
download | git-buildpackage-be28b24e9617c6ac59c5a5b33c46245a34cdef61.tar.gz git-buildpackage-be28b24e9617c6ac59c5a5b33c46245a34cdef61.tar.bz2 git-buildpackage-be28b24e9617c6ac59c5a5b33c46245a34cdef61.zip |
rpm tests: refactor test repository initialization
Create a baseclass for tests that are run in a git repository containing
valid packaging for an rpm package. Makes it possible to re-use the
repository initializations (from the test data manifest file).
Change-Id: Ia034c6f8f82e8732efcbd2b9f7f852bd19eba500
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/component/rpm/__init__.py | 51 | ||||
-rw-r--r-- | tests/component/rpm/test_pq_rpm.py | 53 |
2 files changed, 54 insertions, 50 deletions
diff --git a/tests/component/rpm/__init__.py b/tests/component/rpm/__init__.py index 913ceeec..607aec49 100644 --- a/tests/component/rpm/__init__.py +++ b/tests/component/rpm/__init__.py @@ -16,10 +16,14 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Test module for RPM command line tools of the git-buildpackage suite""" +from nose.tools import nottest import os +import shutil from xml.dom import minidom -from tests.component import ComponentTestGitRepository +from gbp.git import GitRepository, GitRepositoryError + +from tests.component import ComponentTestBase, ComponentTestGitRepository RPM_TEST_DATA_SUBMODULE = os.path.join('tests', 'component', 'rpm', 'data') RPM_TEST_DATA_DIR = os.path.abspath(RPM_TEST_DATA_SUBMODULE) @@ -65,4 +69,49 @@ def setup(): """Test Module setup""" ComponentTestGitRepository.check_testdata(RPM_TEST_DATA_SUBMODULE) + +class RpmRepoTestBase(ComponentTestBase): + """Baseclass for tests run in a Git repository with packaging data""" + + @classmethod + def setup_class(cls): + """Initializations only made once per test run""" + super(RpmRepoTestBase, cls).setup_class() + cls.manifest = RepoManifest(os.path.join(RPM_TEST_DATA_DIR, + 'test-repo-manifest.xml')) + cls.orig_repos = {} + for prj, brs in cls.manifest.projects_iter(): + repo = GitRepository.create(os.path.join(cls._tmproot, + '%s.repo' % prj)) + try: + repo.add_remote_repo('origin', RPM_TEST_DATA_DIR, fetch=True) + except GitRepositoryError: + # Workaround for older git working on submodules initialized + # with newer git + gitfile = os.path.join(RPM_TEST_DATA_DIR, '.git') + if os.path.isfile(gitfile): + with open(gitfile) as fobj: + link = fobj.readline().replace('gitdir:', '').strip() + link_dir = os.path.join(RPM_TEST_DATA_DIR, link) + repo.remove_remote_repo('origin') + repo.add_remote_repo('origin', link_dir, fetch=True) + else: + raise + # Fetch all remote refs of the orig repo, too + repo.fetch('origin', tags=True, + refspec='refs/remotes/*:refs/upstream/*') + for branch, rev in brs.iteritems(): + repo.create_branch(branch, rev) + repo.force_head('master', hard=True) + cls.orig_repos[prj] = repo + + @classmethod + @nottest + def init_test_repo(cls, pkg_name): + """Initialize git repository for testing""" + dirname = os.path.basename(cls.orig_repos[pkg_name].path) + shutil.copytree(cls.orig_repos[pkg_name].path, dirname) + os.chdir(dirname) + return GitRepository('.') + # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/tests/component/rpm/test_pq_rpm.py b/tests/component/rpm/test_pq_rpm.py index 244bfa70..1babb023 100644 --- a/tests/component/rpm/test_pq_rpm.py +++ b/tests/component/rpm/test_pq_rpm.py @@ -17,72 +17,27 @@ """Tests for the gbp pq-rpm tool""" import os -import shutil import tempfile -from nose.tools import assert_raises, nottest, eq_, ok_ # pylint: disable=E0611 +from nose.tools import assert_raises, eq_, ok_ # pylint: disable=E0611 from gbp.scripts.pq_rpm import main as pq -from gbp.git import GitRepository, GitRepositoryError +from gbp.git import GitRepository from gbp.command_wrappers import GitCommand -from tests.component import ComponentTestBase -from tests.component.rpm import RPM_TEST_DATA_DIR, RepoManifest +from tests.component.rpm import RpmRepoTestBase # Disable "Method could be a function warning" # pylint: disable=R0201 -DATA_DIR = RPM_TEST_DATA_DIR - def mock_pq(args): """Wrapper for pq""" # Call pq-rpm with added arg0 return pq(['arg0'] + args) -class TestPqRpm(ComponentTestBase): +class TestPqRpm(RpmRepoTestBase): """Basic tests for gbp-pq-rpm""" - @classmethod - def setup_class(cls): - """Initializations only made once per test run""" - super(TestPqRpm, cls).setup_class() - cls.manifest = RepoManifest(os.path.join(DATA_DIR, - 'test-repo-manifest.xml')) - cls.orig_repos = {} - for prj, brs in cls.manifest.projects_iter(): - repo = GitRepository.create(os.path.join(cls._tmproot, - '%s.repo' % prj)) - try: - repo.add_remote_repo('origin', DATA_DIR, fetch=True) - except GitRepositoryError: - # Workaround for older git working on submodules initialized - # with newer git - gitfile = os.path.join(DATA_DIR, '.git') - if os.path.isfile(gitfile): - with open(gitfile) as fobj: - link = fobj.readline().replace('gitdir:', '').strip() - link_dir = os.path.join(DATA_DIR, link) - repo.remove_remote_repo('origin') - repo.add_remote_repo('origin', link_dir, fetch=True) - else: - raise - # Fetch all remote refs of the orig repo, too - repo.fetch('origin', tags=True, - refspec='refs/remotes/*:refs/upstream/*') - for branch, rev in brs.iteritems(): - repo.create_branch(branch, rev) - repo.force_head('master', hard=True) - cls.orig_repos[prj] = repo - - @classmethod - @nottest - def init_test_repo(cls, pkg_name): - """Initialize git repository for testing""" - dirname = os.path.basename(cls.orig_repos[pkg_name].path) - shutil.copytree(cls.orig_repos[pkg_name].path, dirname) - os.chdir(dirname) - return GitRepository('.') - def test_invalid_args(self): """See that pq-rpm fails gracefully when called with invalid args""" GitRepository.create('.') |