increase code coverage

pull/716/head
sebres 2014-10-28 21:57:16 +01:00
parent c1db282fcd
commit 595edc8d46
3 changed files with 15 additions and 5 deletions

View File

@ -189,7 +189,7 @@ class DateDetector(object):
logSys.log(logLevel, "Got time %f for \"%r\" using template %s", logSys.log(logLevel, "Got time %f for \"%r\" using template %s",
date[0], date[1].group(), template.name) date[0], date[1].group(), template.name)
return date return date
except ValueError: except ValueError: # pragma: no cover
pass pass
return None return None
finally: finally:

View File

@ -108,11 +108,12 @@ class Jail:
logSys.info("Initiated %r backend" % b) logSys.info("Initiated %r backend" % b)
self.__actions = Actions(self) self.__actions = Actions(self)
return # we are done return # we are done
except ImportError, e: except ImportError, e: # pragma: no cover
# Log debug if auto, but error if specific # Log debug if auto, but error if specific
logSys.log( logSys.log(
logging.DEBUG if backend == "auto" else logging.ERROR, logging.DEBUG if backend == "auto" else logging.ERROR,
"Backend %r failed to initialize due to %s" % (b, e)) "Backend %r failed to initialize due to %s" % (b, e))
# pragma: no cover
# log error since runtime error message isn't printed, INVALID COMMAND # log error since runtime error message isn't printed, INVALID COMMAND
logSys.error( logSys.error(
"Failed to initialize any backend for Jail %r" % self.name) "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: # mark ticked was restored from database - does not put it again into db:
ticket.setRestored(True) ticket.setRestored(True)
self.putFailTicket(ticket) 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=logSys.getEffectiveLevel()<=logging.DEBUG)
#logSys.error('%s', e, exc_info=True) #logSys.error('%s', e, exc_info=True)

View File

@ -29,19 +29,28 @@ import time
import datetime import datetime
from ..server.datedetector import DateDetector from ..server.datedetector import DateDetector
from ..server import datedetector
from ..server.datetemplate import DateTemplate 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): def setUp(self):
"""Call before every test case.""" """Call before every test case."""
LogCaptureTestCase.setUp(self)
self.__old_eff_level = datedetector.logLevel
datedetector.logLevel = logSys.getEffectiveLevel()
setUpMyTime() setUpMyTime()
self.__datedetector = DateDetector() self.__datedetector = DateDetector()
self.__datedetector.addDefaultTemplate() self.__datedetector.addDefaultTemplate()
def tearDown(self): def tearDown(self):
"""Call after every test case.""" """Call after every test case."""
LogCaptureTestCase.tearDown(self)
datedetector.logLevel = self.__old_eff_level
tearDownMyTime() tearDownMyTime()
def testGetEpochTime(self): def testGetEpochTime(self):