summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2013-01-16 08:59:58 +0100
committerGuido Günther <agx@sigxcpu.org>2013-01-16 20:45:02 +0100
commit9e30bf2237bc5752576741001ff76b93deeb7ca3 (patch)
treeaf8ca1d36211f23dbe74f8cf81e88dfb51363a2f
parent5e6f16303f7e4c31e361d95b8cce7b0bc0a4a737 (diff)
downloadgit-buildpackage-9e30bf2237bc5752576741001ff76b93deeb7ca3.tar.gz
git-buildpackage-9e30bf2237bc5752576741001ff76b93deeb7ca3.tar.bz2
git-buildpackage-9e30bf2237bc5752576741001ff76b93deeb7ca3.zip
Add component test initialization
very heavily based on code by Markus Lehtonen
-rw-r--r--tests/component/__init__.py154
-rw-r--r--tests/component/deb/__init__.py32
-rw-r--r--tests/testutils.py87
3 files changed, 187 insertions, 86 deletions
diff --git a/tests/component/__init__.py b/tests/component/__init__.py
new file mode 100644
index 00000000..1d1f9e49
--- /dev/null
+++ b/tests/component/__init__.py
@@ -0,0 +1,154 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2012 Intel Corporation <markus.lehtonen@linux.intel.com>
+# 2013 Guido Günther <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, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import os
+import shutil
+import tempfile
+from StringIO import StringIO
+
+from nose import SkipTest
+
+import gbp.log
+from gbp.git import GitRepository, GitRepositoryError
+
+class ComponentTestGitRepository(GitRepository):
+ """Git repository class for component tests"""
+ def submodule_status(self):
+ """
+ Determine submodules and their status
+ """
+ out, err, ret = self._git_inout('submodule', ['status'],
+ capture_stderr=True)
+ if ret:
+ raise GitRepositoryError("Cannot get submodule status: %s" %
+ err.strip())
+ submodules = {}
+ for line in out.splitlines():
+ module = line.strip()
+ # Uninitialized
+ status = module[0]
+ if status == '-':
+ sha1, path = module[1:].rsplit(' ', 1)
+ else:
+ commitpath = module[1:].rsplit(' ', 1)[0]
+ sha1, path = commitpath.split(' ', 1)
+ submodules[path] = (status, sha1)
+ return submodules
+
+ @classmethod
+ def check_testdata(cls, data):
+ """Check whether the testdata is current"""
+ try:
+ repo = cls('.')
+ except GitRepositoryError:
+ raise SkipTest("Skipping '%s', since this is not a git checkout."
+ % __name__)
+
+ submodules = repo.submodule_status()
+ try:
+ status = submodules[data]
+ except KeyError:
+ raise SkipTest("Skipping '%s', testdata directory not a known submodule."
+ % __name__)
+
+ if status[0] == '-':
+ raise SkipTest("Skipping '%s', testdata directory not initialized. "
+ "Consider doing 'git submodule update'" % __name__)
+
+
+class ComponentTestBase(object):
+ """Base class for testing cmdline tools of git-buildpackage"""
+
+ @classmethod
+ def setup_class(cls):
+ """Test class case setup"""
+ # Don't let git see that we're (possibly) under a git directory
+ cls.orig_env = os.environ.copy()
+ os.environ['GIT_CEILING_DIRECTORIES'] = os.getcwd()
+
+ @classmethod
+ def teardown_class(cls):
+ """Test class case teardown"""
+ # Return original environment
+ os.environ = cls.orig_env
+
+ def __init__(self):
+ """Object initialization"""
+ self._orig_dir = None
+ self._tmpdir = None
+ self._log = None
+ self._loghandler = None
+
+ def setup(self):
+ """Test case setup"""
+ # Change to a temporary directory
+ self._orig_dir = os.getcwd()
+ self._tmpdir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.')
+ os.chdir(self._tmpdir)
+
+ self._capture_log(True)
+
+ def teardown(self):
+ """Test case teardown"""
+ # Restore original working dir
+ os.chdir(self._orig_dir)
+ shutil.rmtree(self._tmpdir)
+
+ self._capture_log(False)
+
+ @classmethod
+ def _check_repo_state(cls, repo, current_branch, branches):
+ """Check that repository is clean and given branches exist"""
+ branch = repo.branch
+ assert branch == current_branch
+ assert repo.is_clean()
+ assert set(repo.get_local_branches()) == set(branches)
+
+ def _capture_log(self, capture=True):
+ """ Capture log"""
+ if capture and self._log is None:
+ self._log = StringIO()
+ self._loghandler = gbp.log.GbpStreamHandler(self._log, False)
+ self._loghandler.addFilter(gbp.log.GbpFilter([gbp.log.WARNING,
+ gbp.log.ERROR]))
+ gbp.log.LOGGER.addHandler(self._loghandler)
+ elif self._log is not None:
+ gbp.log.LOGGER.removeHandler(self._loghandler)
+ self._loghandler = None
+ self._log.close()
+ self._log = None
+
+ def _get_log(self):
+ """Get the captured log output"""
+ self._log.seek(0)
+ return self._log.readlines()
+
+ def _check_log(self, linenum, string):
+ """Check that the specified line on log matches expectations"""
+ if self._log is None:
+ assert False, "BUG in unittests: no log captured!"
+ output = self._get_log()[linenum].strip()
+ assert output.startswith(string), ("Expected: '%s...' Got: '%s'" %
+ (string, output))
+
+ def _clear_log(self):
+ """Clear the mock strerr"""
+ if self._log is not None:
+ self._log.seek(0)
+ self._log.truncate()
diff --git a/tests/component/deb/__init__.py b/tests/component/deb/__init__.py
new file mode 100644
index 00000000..33a8ee1a
--- /dev/null
+++ b/tests/component/deb/__init__.py
@@ -0,0 +1,32 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2012 Intel Corporation <markus.lehtonen@linux.intel.com>
+# (C) 2013 Guido Günther <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, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import os
+
+from tests.component import ComponentTestGitRepository
+
+DEB_TEST_SUBMODULE = os.path.join('tests', 'component', 'deb', 'data')
+DEB_TEST_DATA_DIR = os.path.abspath(DEB_TEST_SUBMODULE)
+
+def setup():
+ """Test Module setup"""
+ ComponentTestGitRepository.check_testdata(DEB_TEST_SUBMODULE)
+
+
+
diff --git a/tests/testutils.py b/tests/testutils.py
index 04a13cd2..ff20e090 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -2,16 +2,14 @@
import os
import shutil
-import tempfile
import unittest
-from StringIO import StringIO
import gbp.log
import gbp.deb.git
import gbp.errors
class DebianGitTestRepo(unittest.TestCase):
- """Scratch repo for a single test"""
+ """Scratch repo for a single unit test"""
def setUp(self):
gbp.log.setup(False, False)
@@ -45,86 +43,3 @@ class DebianGitTestRepo(unittest.TestCase):
content == None or f.write(content)
self.repo.add_files(name, force=True)
self.repo.commit_files(path, msg or "added %s" % name)
-
-
-class ComponentTestBase(object):
- """Base class for testing cmdline tools of git-buildpackage"""
-
- @classmethod
- def setup_class(cls):
- """Test class case setup"""
- # Don't let git see that we're (possibly) under a git directory
- cls.orig_env = os.environ.copy()
- os.environ['GIT_CEILING_DIRECTORIES'] = os.getcwd()
-
- @classmethod
- def teardown_class(cls):
- """Test class case teardown"""
- # Return original environment
- os.environ = cls.orig_env
-
- def __init__(self):
- """Object initialization"""
- self._orig_dir = None
- self._tmpdir = None
- self._log = None
- self._loghandler = None
-
- def setup(self):
- """Test case setup"""
- # Change to a temporary directory
- self._orig_dir = os.getcwd()
- self._tmpdir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.')
- os.chdir(self._tmpdir)
-
- self._capture_log(True)
-
- def teardown(self):
- """Test case teardown"""
- # Restore original working dir
- os.chdir(self._orig_dir)
- shutil.rmtree(self._tmpdir)
-
- self._capture_log(False)
-
- @classmethod
- def _check_repo_state(cls, repo, current_branch, branches):
- """Check that repository is clean and given branches exist"""
- branch = repo.branch
- assert branch == current_branch
- assert repo.is_clean()
- assert set(repo.get_local_branches()) == set(branches)
-
- def _capture_log(self, capture=True):
- """ Capture log"""
- if capture and self._log is None:
- self._log = StringIO()
- self._loghandler = gbp.log.GbpStreamHandler(self._log, False)
- self._loghandler.addFilter(gbp.log.GbpFilter([gbp.log.WARNING,
- gbp.log.ERROR]))
- gbp.log.LOGGER.addHandler(self._loghandler)
- elif self._log is not None:
- gbp.log.LOGGER.removeHandler(self._loghandler)
- self._loghandler = None
- self._log.close()
- self._log = None
-
- def _get_log(self):
- """Get the captured log output"""
- self._log.seek(0)
- return self._log.readlines()
-
- def _check_log(self, linenum, string):
- """Check that the specified line on log matches expectations"""
- if self._log is None:
- assert False, "BUG in unittests: no log captured!"
- output = self._get_log()[linenum].strip()
- assert output.startswith(string), ("Expected: '%s...' Got: '%s'" %
- (string, output))
-
- def _clear_log(self):
- """Clear the mock strerr"""
- if self._log is not None:
- self._log.seek(0)
- self._log.truncate()
-