diff options
Diffstat (limited to 'tests/component/__init__.py')
-rw-r--r-- | tests/component/__init__.py | 42 |
1 files changed, 3 insertions, 39 deletions
diff --git a/tests/component/__init__.py b/tests/component/__init__.py index cfa0422..f6b1224 100644 --- a/tests/component/__init__.py +++ b/tests/component/__init__.py @@ -27,6 +27,7 @@ import tempfile from StringIO import StringIO from nose import SkipTest from nose.tools import eq_, ok_ # pylint: disable=E0611 +from .. testutils import GbpLogTester import gbp.log from gbp.git import GitRepository, GitRepositoryError @@ -76,7 +77,7 @@ class ComponentTestGitRepository(GitRepository): "Consider doing 'git submodule update'" % __name__) -class ComponentTestBase(object): +class ComponentTestBase(GbpLogTester): """Base class for testing cmdline tools of git-buildpackage""" @classmethod @@ -103,8 +104,7 @@ class ComponentTestBase(object): """Object initialization""" self._orig_dir = None self._tmpdir = None - self._log = None - self._loghandler = None + GbpLogTester.__init__(self) def setup(self): """Test case setup""" @@ -163,39 +163,3 @@ class ComponentTestBase(object): cls.check_files(files, local_f) if dirs is not None: cls.check_files(dirs, local_d) - - 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])) - for hdl in gbp.log.LOGGER.handlers: - gbp.log.LOGGER.removeHandler(hdl) - gbp.log.LOGGER.addHandler(self._loghandler) - elif self._log is not None: - gbp.log.LOGGER.removeHandler(self._loghandler) - self._loghandler.close() - 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, regex): - """Check that the specified line on log matches expectations""" - if self._log is None: - raise Exception("BUG in unittests: no log captured!") - output = self._get_log()[linenum].strip() - ok_(re.match(regex, output), - "Log entry '%s' doesn't match '%s'" % (output, regex)) - - def _clear_log(self): - """Clear the mock strerr""" - if self._log is not None: - self._log.seek(0) - self._log.truncate() |