From 595edc8d4698fd7b27630328470903b85220cb8f Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 28 Oct 2014 21:57:16 +0100 Subject: [PATCH] increase code coverage --- fail2ban/server/datedetector.py | 2 +- fail2ban/server/jail.py | 5 +++-- fail2ban/tests/datedetectortestcase.py | 13 +++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/fail2ban/server/datedetector.py b/fail2ban/server/datedetector.py index ba623f4a..bab6302c 100644 --- a/fail2ban/server/datedetector.py +++ b/fail2ban/server/datedetector.py @@ -189,7 +189,7 @@ class DateDetector(object): logSys.log(logLevel, "Got time %f for \"%r\" using template %s", date[0], date[1].group(), template.name) return date - except ValueError: + except ValueError: # pragma: no cover pass return None finally: diff --git a/fail2ban/server/jail.py b/fail2ban/server/jail.py index 1e1f7dd1..0de5f783 100644 --- a/fail2ban/server/jail.py +++ b/fail2ban/server/jail.py @@ -108,11 +108,12 @@ class Jail: logSys.info("Initiated %r backend" % b) self.__actions = Actions(self) return # we are done - except ImportError, e: + except ImportError, e: # pragma: no cover # Log debug if auto, but error if specific logSys.log( logging.DEBUG if backend == "auto" else logging.ERROR, "Backend %r failed to initialize due to %s" % (b, e)) + # pragma: no cover # log error since runtime error message isn't printed, INVALID COMMAND logSys.error( "Failed to initialize any backend for Jail %r" % self.name) @@ -272,7 +273,7 @@ class Jail: # mark ticked was restored from database - does not put it again into db: ticket.setRestored(True) self.putFailTicket(ticket) - except Exception as e: + except Exception as e: # pragma: no cover logSys.error('%s', e, exc_info=logSys.getEffectiveLevel()<=logging.DEBUG) #logSys.error('%s', e, exc_info=True) diff --git a/fail2ban/tests/datedetectortestcase.py b/fail2ban/tests/datedetectortestcase.py index fe5448d4..393991ef 100644 --- a/fail2ban/tests/datedetectortestcase.py +++ b/fail2ban/tests/datedetectortestcase.py @@ -29,19 +29,28 @@ import time import datetime from ..server.datedetector import DateDetector +from ..server import datedetector from ..server.datetemplate import DateTemplate -from .utils import setUpMyTime, tearDownMyTime +from .utils import setUpMyTime, tearDownMyTime, LogCaptureTestCase +from ..helpers import getLogger -class DateDetectorTest(unittest.TestCase): +logSys = getLogger("fail2ban") + +class DateDetectorTest(LogCaptureTestCase): def setUp(self): """Call before every test case.""" + LogCaptureTestCase.setUp(self) + self.__old_eff_level = datedetector.logLevel + datedetector.logLevel = logSys.getEffectiveLevel() setUpMyTime() self.__datedetector = DateDetector() self.__datedetector.addDefaultTemplate() def tearDown(self): """Call after every test case.""" + LogCaptureTestCase.tearDown(self) + datedetector.logLevel = self.__old_eff_level tearDownMyTime() def testGetEpochTime(self):