mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
test: Mock calls to time.sleep()
The tests now take 7 seconds instead of 30.
This commit is contained in:
parent
a6392c8582
commit
fcb342cb2c
@ -248,7 +248,7 @@ class IrcUserTestCase(IrcdbTestCase):
|
||||
u = ircdb.IrcUser()
|
||||
u.addAuth('foo!bar@baz')
|
||||
self.failUnless(u.checkHostmask('foo!bar@baz'))
|
||||
time.sleep(2.1)
|
||||
timeFastForward(2.1)
|
||||
self.failIf(u.checkHostmask('foo!bar@baz'))
|
||||
finally:
|
||||
conf.supybot.databases.users.timeoutIdentification.setValue(orig)
|
||||
@ -265,7 +265,7 @@ class IrcUserTestCase(IrcdbTestCase):
|
||||
self.failUnless(len(u.auth) == 1)
|
||||
u.addAuth('boo!far@fizz')
|
||||
self.failUnless(u.checkHostmask('boo!far@fizz'))
|
||||
time.sleep(2.1)
|
||||
timeFastForward(2.1)
|
||||
self.failIf(u.checkHostmask('foo!bar@baz'))
|
||||
self.failIf(u.checkHostmask('boo!far@fizz'))
|
||||
finally:
|
||||
|
@ -53,10 +53,10 @@ class TestSchedule(SupyTestCase):
|
||||
|
||||
sched.addEvent(add10, time.time() + 3)
|
||||
sched.addEvent(add1, time.time() + 1)
|
||||
time.sleep(1.2)
|
||||
timeFastForward(1.2)
|
||||
sched.run()
|
||||
self.assertEqual(i[0], 1)
|
||||
time.sleep(1.9)
|
||||
timeFastForward(1.9)
|
||||
sched.run()
|
||||
self.assertEqual(i[0], 11)
|
||||
|
||||
@ -65,7 +65,7 @@ class TestSchedule(SupyTestCase):
|
||||
self.assertEqual(i[0], 11)
|
||||
sched.removeEvent('test')
|
||||
self.assertEqual(i[0], 11)
|
||||
time.sleep(3)
|
||||
timeFastForward(3)
|
||||
self.assertEqual(i[0], 11)
|
||||
|
||||
def testReschedule(self):
|
||||
@ -75,10 +75,10 @@ class TestSchedule(SupyTestCase):
|
||||
i[0] += 1
|
||||
n = sched.addEvent(inc, time.time() + 1)
|
||||
sched.rescheduleEvent(n, time.time() + 3)
|
||||
time.sleep(1.2)
|
||||
timeFastForward(1.2)
|
||||
sched.run()
|
||||
self.assertEqual(i[0], 0)
|
||||
time.sleep(2)
|
||||
timeFastForward(2)
|
||||
sched.run()
|
||||
self.assertEqual(i[0], 1)
|
||||
|
||||
@ -88,20 +88,20 @@ class TestSchedule(SupyTestCase):
|
||||
def inc():
|
||||
i[0] += 1
|
||||
n = sched.addPeriodicEvent(inc, 1, name='test_periodic')
|
||||
time.sleep(0.6)
|
||||
timeFastForward(0.6)
|
||||
sched.run() # 0.6
|
||||
self.assertEqual(i[0], 1)
|
||||
time.sleep(0.6)
|
||||
timeFastForward(0.6)
|
||||
sched.run() # 1.2
|
||||
self.assertEqual(i[0], 2)
|
||||
time.sleep(0.6)
|
||||
timeFastForward(0.6)
|
||||
sched.run() # 1.8
|
||||
self.assertEqual(i[0], 2)
|
||||
time.sleep(0.6)
|
||||
timeFastForward(0.6)
|
||||
sched.run() # 2.4
|
||||
self.assertEqual(i[0], 3)
|
||||
sched.removePeriodicEvent(n)
|
||||
time.sleep(1)
|
||||
timeFastForward(1)
|
||||
sched.run() # 3.4
|
||||
self.assertEqual(i[0], 3)
|
||||
|
||||
@ -111,19 +111,19 @@ class TestSchedule(SupyTestCase):
|
||||
def inc():
|
||||
i[0] += 1
|
||||
n = sched.addPeriodicEvent(inc, 1, name='test_periodic', count=3)
|
||||
time.sleep(0.6)
|
||||
timeFastForward(0.6)
|
||||
sched.run() # 0.6
|
||||
self.assertEqual(i[0], 1)
|
||||
time.sleep(0.6)
|
||||
timeFastForward(0.6)
|
||||
sched.run() # 1.2
|
||||
self.assertEqual(i[0], 2)
|
||||
time.sleep(0.6)
|
||||
timeFastForward(0.6)
|
||||
sched.run() # 1.8
|
||||
self.assertEqual(i[0], 2)
|
||||
time.sleep(0.6)
|
||||
timeFastForward(0.6)
|
||||
sched.run() # 2.4
|
||||
self.assertEqual(i[0], 3)
|
||||
time.sleep(1)
|
||||
timeFastForward(1)
|
||||
sched.run() # 3.4
|
||||
self.assertEqual(i[0], 3)
|
||||
|
||||
|
@ -1123,7 +1123,7 @@ class TestTimeoutQueue(SupyTestCase):
|
||||
q.enqueue(3)
|
||||
self.assertEqual(len(q), 3)
|
||||
self.assertEqual(sum(q), 6)
|
||||
time.sleep(1.1)
|
||||
timeFastForward(1.1)
|
||||
self.assertEqual(len(q), 0)
|
||||
self.assertEqual(sum(q), 0)
|
||||
|
||||
@ -1136,7 +1136,7 @@ class TestTimeoutQueue(SupyTestCase):
|
||||
q.enqueue(3)
|
||||
self.assertEqual(len(q), 3)
|
||||
self.assertEqual(sum(q), 6)
|
||||
time.sleep(1.1)
|
||||
timeFastForward(1.1)
|
||||
self.assertEqual(len(q), 0)
|
||||
self.assertEqual(sum(q), 0)
|
||||
|
||||
@ -1146,7 +1146,7 @@ class TestTimeoutQueue(SupyTestCase):
|
||||
self.failUnless(1 in q)
|
||||
self.failUnless(1 in q) # For some reason, the second one might fail.
|
||||
self.failIf(2 in q)
|
||||
time.sleep(1.1)
|
||||
timeFastForward(1.1)
|
||||
self.failIf(1 in q)
|
||||
|
||||
def testReset(self):
|
||||
|
Loading…
Reference in New Issue
Block a user