diff options
author | Yaroslav Halchenko <debian@onerussian.com> | 2011-10-07 15:14:13 -0400 |
---|---|---|
committer | Yaroslav Halchenko <debian@onerussian.com> | 2011-10-07 15:14:13 -0400 |
commit | 5a2d518bf264889771f3989ff3c096ba091ab854 (patch) | |
tree | d2bd77f8a398185569f91fadcd42f146177f5c82 | |
parent | 08fced9646c7edfa61c21280152f7c6bd76df5b6 (diff) | |
download | fail2ban-5a2d518bf264889771f3989ff3c096ba091ab854.tar.gz |
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 ;)
-rwxr-xr-x | fail2ban-testcases | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/fail2ban-testcases b/fail2ban-testcases index 9573d62b..28945ae3 100755 --- a/fail2ban-testcases +++ b/fail2ban-testcases @@ -26,7 +26,7 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -import unittest, logging, sys +import unittest, logging, sys, time, os from common.version import version from testcases import banmanagertestcase @@ -40,6 +40,11 @@ from server.mytime import MyTime # Set the time to a fixed, known value # 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) # Gets the instance of the logger. @@ -73,3 +78,10 @@ tests.addTest(unittest.makeSuite(datedetectortestcase.DateDetectorTest)) # Tests runner testRunner = unittest.TextTestRunner() 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() |