TST: Update travis coverage config to exempt systemd related code

pull/224/head
Steven Hiscocks 2013-05-12 13:40:25 +01:00
parent c08bd67f50
commit 90de5aa568
9 changed files with 23 additions and 13 deletions

View File

@ -17,4 +17,6 @@ script:
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then export PYTHONPATH="$PYTHONPATH:/usr/share/pyshared:/usr/lib/pyshared/python2.7"; fi - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then export PYTHONPATH="$PYTHONPATH:/usr/share/pyshared:/usr/lib/pyshared/python2.7"; fi
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coverage run --rcfile=.travis_coveragerc setup.py test; else python setup.py test; fi - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coverage run --rcfile=.travis_coveragerc setup.py test; else python setup.py test; fi
after_success: after_success:
# Coverage config file must be .coveragerc for coveralls
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then cp -v .travis_coveragerc .coveragerc; fi
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coveralls; fi - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coveralls; fi

View File

@ -5,3 +5,11 @@ omit =
/usr/* /usr/*
/home/travis/virtualenv/* /home/travis/virtualenv/*
fail2ban/server/filtersystemd.py fail2ban/server/filtersystemd.py
[report]
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# systemd backend related
pragma: systemd no cover

View File

@ -648,7 +648,7 @@ class FileContainer:
# #
# Base interface class for systemd journal filters # Base interface class for systemd journal filters
class JournalFilter(Filter): class JournalFilter(Filter): # pragma: systemd no cover
def addJournalMatch(self, match): def addJournalMatch(self, match):
pass pass

View File

@ -45,7 +45,7 @@ logSys = logging.getLogger("fail2ban.filter")
# else that matches a given regular expression. This class is instantiated by # else that matches a given regular expression. This class is instantiated by
# a Jail object. # a Jail object.
class FilterSystemd(JournalFilter): class FilterSystemd(JournalFilter): # pragma: systemd no cover
## ##
# Constructor. # Constructor.
# #

View File

@ -101,7 +101,7 @@ class Jail:
from filterpyinotify import FilterPyinotify from filterpyinotify import FilterPyinotify
self.__filter = FilterPyinotify(self) self.__filter = FilterPyinotify(self)
def _initSystemd(self): def _initSystemd(self): # pragma: systemd no cover
# Try to import systemd # Try to import systemd
import systemd import systemd
logSys.info("Jail '%s' uses systemd" % self.__name) logSys.info("Jail '%s' uses systemd" % self.__name)

View File

@ -184,21 +184,21 @@ class Server:
if isinstance(filter_, FileFilter): if isinstance(filter_, FileFilter):
return [m.getFileName() return [m.getFileName()
for m in filter_.getLogPath()] for m in filter_.getLogPath()]
else: else: # pragma: systemd no cover
logSys.info("Jail %s is not a FileFilter instance" % name) logSys.info("Jail %s is not a FileFilter instance" % name)
return [] return []
def addJournalMatch(self, name, match): def addJournalMatch(self, name, match): # pragma: systemd no cover
filter_ = self.__jails.getFilter(name) filter_ = self.__jails.getFilter(name)
if isinstance(filter_, JournalFilter): if isinstance(filter_, JournalFilter):
filter_.addJournalMatch(match) filter_.addJournalMatch(match)
def delJournalMatch(self, name, match): def delJournalMatch(self, name, match): # pragma: systemd no cover
filter_ = self.__jails.getFilter(name) filter_ = self.__jails.getFilter(name)
if isinstance(filter_, JournalFilter): if isinstance(filter_, JournalFilter):
filter_.delJournalMatch(match) filter_.delJournalMatch(match)
def getJournalMatch(self, name): def getJournalMatch(self, name): # pragma: systemd no cover
filter_ = self.__jails.getFilter(name) filter_ = self.__jails.getFilter(name)
if isinstance(filter_, JournalFilter): if isinstance(filter_, JournalFilter):
return filter_.getJournalMatch() return filter_.getJournalMatch()

View File

@ -144,11 +144,11 @@ class Transmitter:
value = command[2] value = command[2]
self.__server.setLogEncoding(name, value) self.__server.setLogEncoding(name, value)
return self.__server.getLogEncoding(name) return self.__server.getLogEncoding(name)
elif command[1] == "addjournalmatch": elif command[1] == "addjournalmatch": # pragma: systemd no cover
value = ' '.join(command[2:]) value = ' '.join(command[2:])
self.__server.addJournalMatch(name, value) self.__server.addJournalMatch(name, value)
return self.__server.getJournalMatch(name) return self.__server.getJournalMatch(name)
elif command[1] == "deljournalmatch": elif command[1] == "deljournalmatch": # pragma: systemd no cover
value = ' '.join(command[2:]) value = ' '.join(command[2:])
self.__server.delJournalMatch(name, value) self.__server.delJournalMatch(name, value)
return self.__server.getJournalMatch(name) return self.__server.getJournalMatch(name)
@ -258,7 +258,7 @@ class Transmitter:
return self.__server.getLogPath(name) return self.__server.getLogPath(name)
elif command[1] == "logencoding": elif command[1] == "logencoding":
return self.__server.getLogEncoding(name) return self.__server.getLogEncoding(name)
elif command[1] == "journalmatch": elif command[1] == "journalmatch": # pragma: systemd no cover
return self.__server.getJournalMatch(name) return self.__server.getJournalMatch(name)
elif command[1] == "ignoreip": elif command[1] == "ignoreip":
return self.__server.getIgnoreIP(name) return self.__server.getIgnoreIP(name)

View File

@ -165,7 +165,7 @@ def _copy_lines_between_files(in_, fout, n=None, skip=0, mode='a', terminal_line
time.sleep(0.1) time.sleep(0.1)
return fout return fout
def _copy_lines_to_journal(in_, fields={},n=None, skip=0, terminal_line=""): def _copy_lines_to_journal(in_, fields={},n=None, skip=0, terminal_line=""): # pragma: systemd no cover
"""Copy lines from one file to systemd journal """Copy lines from one file to systemd journal
Returns None Returns None
@ -607,7 +607,7 @@ def get_monitor_failures_testcase(Filter_):
% (Filter_.__name__, testclass_name) # 'tempfile') % (Filter_.__name__, testclass_name) # 'tempfile')
return MonitorFailures return MonitorFailures
def get_monitor_failures_journal_testcase(Filter_): def get_monitor_failures_journal_testcase(Filter_): # pragma: systemd no cover
"""Generator of TestCase's for journal based filters/backends """Generator of TestCase's for journal based filters/backends
""" """

View File

@ -201,7 +201,7 @@ def gatherTests(regexps=None, no_network=False):
for Filter_ in filters: for Filter_ in filters:
tests.addTest(unittest.makeSuite( tests.addTest(unittest.makeSuite(
filtertestcase.get_monitor_failures_testcase(Filter_))) filtertestcase.get_monitor_failures_testcase(Filter_)))
try: try: # pragma: systemd no cover
from fail2ban.server.filtersystemd import FilterSystemd from fail2ban.server.filtersystemd import FilterSystemd
tests.addTest(unittest.makeSuite(filtertestcase.get_monitor_failures_journal_testcase(FilterSystemd))) tests.addTest(unittest.makeSuite(filtertestcase.get_monitor_failures_journal_testcase(FilterSystemd)))
except Exception, e: # pragma: no cover except Exception, e: # pragma: no cover