Fix spurious testcase fail, sometimes seconds didn't match.

This commit is contained in:
Elián Hanisch 2012-06-25 19:35:42 -03:00
parent 5ffcf6511a
commit a08559a758
2 changed files with 17 additions and 9 deletions

View File

@ -70,6 +70,11 @@ tz = 'UTC'
def now():
return cPickle.dumps(datetime.datetime.now(pytz.timezone(tz)))
def nowSeconds():
# apparently time.time() isn't the same thing.
# return time.time()
return int(time.mktime(time.gmtime()))
def fromTime(x):
return cPickle.dumps(datetime.datetime(*time.gmtime(x)[:6], **{'tzinfo': pytz.timezone("UTC")}))
@ -509,7 +514,8 @@ class Bantracker(callbacks.Plugin):
if not reviewTime:
# time is zero, do nothing
return
now = time.mktime(time.gmtime())
now = nowSeconds()
lastReview = self.pendingReviews.lastReview
self.pendingReviews.lastReview = now # update last time reviewed
if not lastReview:
@ -534,8 +540,9 @@ class Bantracker(callbacks.Plugin):
banAge = now - ban.when
reviewWindow = lastReview - ban.when
#self.log.debug('review ban: %s ban %s by %s (%s/%s/%s %s)', channel, ban.mask,
# ban.who, reviewWindow, reviewTime, banAge, reviewTime - reviewWindow)
#self.log.debug('review ban: %s ban %s by %s (%s/%s/%s %s)',
# channel, ban.mask, ban.who, reviewWindow, reviewTime,
# banAge, reviewTime - reviewWindow)
if reviewWindow <= reviewTime < banAge:
# ban is old enough, and inside the "review window"
try:

View File

@ -20,6 +20,7 @@ import supybot.conf as conf
import supybot.ircmsgs as ircmsgs
import supybot.world as world
import re
import time
@ -241,12 +242,12 @@ class BantrackerTestCase(ChannelPluginTestCase):
cb.reviewBans(self.irc)
# since it's a forward, it was sent already
self.assertFalse(cb.pendingReviews)
self.assertEqual(str(self.irc.takeMsg()).strip(),
"NOTICE #channel :Review: ban 'asd!*@*' set by bot on %s in #test, link: "\
"%s/bans.cgi?log=1" %(cb.bans['#test'][0].ascwhen, pluginConf.bansite()))
self.assertEqual(str(self.irc.takeMsg()).strip(),
"NOTICE #channel :Review: quiet 'asd!*@*' set by bot on %s in #test, link: "\
"%s/bans.cgi?log=2" %(cb.bans['#test'][0].ascwhen, pluginConf.bansite()))
self.assertTrue(re.search(
r"^NOTICE #channel :Review: ban 'asd!\*@\*' set by bot on .* in #test,"\
r" link: .*/bans\.cgi\?log=1$", str(self.irc.takeMsg()).strip()))
self.assertTrue(re.search(
r"^NOTICE #channel :Review: quiet 'asd!\*@\*' set by bot on .* in #test,"\
r" link: .*/bans\.cgi\?log=2$", str(self.irc.takeMsg()).strip()))
def testReviewIgnore(self):
pluginConf.review.setValue(True)