mirror of https://github.com/fail2ban/fail2ban
BF: set TZ to CEST while unittesting so dates matching would work
now unittesting should work on any box (not only in CEST timezone ;) ) uff -- so much time was wasted to come to this minimal (and now obvious) solution -- it is just scary ;)pull/4/head
parent
08fced9646
commit
5a2d518bf2
|
@ -26,7 +26,7 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
|
|
||||||
import unittest, logging, sys
|
import unittest, logging, sys, time, os
|
||||||
|
|
||||||
from common.version import version
|
from common.version import version
|
||||||
from testcases import banmanagertestcase
|
from testcases import banmanagertestcase
|
||||||
|
@ -40,6 +40,11 @@ from server.mytime import MyTime
|
||||||
|
|
||||||
# Set the time to a fixed, known value
|
# Set the time to a fixed, known value
|
||||||
# Sun Aug 14 12:00:00 CEST 2005
|
# Sun Aug 14 12:00:00 CEST 2005
|
||||||
|
|
||||||
|
# yoh: we need to adjust TZ to match the one used by Cyril so all the timestamps match
|
||||||
|
old_TZ = os.environ.get('TZ', None)
|
||||||
|
os.environ['TZ'] = 'Europe/Zurich'
|
||||||
|
time.tzset()
|
||||||
MyTime.setTime(1124013600)
|
MyTime.setTime(1124013600)
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
|
@ -73,3 +78,10 @@ tests.addTest(unittest.makeSuite(datedetectortestcase.DateDetectorTest))
|
||||||
# Tests runner
|
# Tests runner
|
||||||
testRunner = unittest.TextTestRunner()
|
testRunner = unittest.TextTestRunner()
|
||||||
testRunner.run(tests)
|
testRunner.run(tests)
|
||||||
|
|
||||||
|
# Just for the sake of it reset the TZ
|
||||||
|
# yoh is planing to move all this into setup/teardown methods within tests
|
||||||
|
os.environ.pop('TZ')
|
||||||
|
if old_TZ:
|
||||||
|
os.environ['TZ'] = old_TZ
|
||||||
|
time.tzset()
|
||||||
|
|
Loading…
Reference in New Issue