From 5a2d518bf264889771f3989ff3c096ba091ab854 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 7 Oct 2011 15:14:13 -0400 Subject: [PATCH] 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 ;) --- fail2ban-testcases | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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()