2
from os.path import join as opj
3
from twisted.trial import unittest
4
from quotient.sched import SystemScheduler, SubScheduler, SchedulerService, SchedulerBase, Schedulable
5
from quotient.items.powerup import IPowerStation
6
from quotient.storq import Store, SubStore, Item
8
class MySch(Item, Schedulable):
13
class SchedTest(unittest.TestCase):
16
self.times = [0.0, 1.0, 2.0, 3.0, 10.0, 20.0, 30.0]
18
SchedulerBase.clock = staticmethod(lambda : self.times[0])
19
SystemScheduler.callLater = staticmethod(lambda t, f, *a, **b: self.calls.append((t, f)))
20
dbpath = self.mktemp()
21
self.store = Store(opj(dbpath, "db"), opj(dbpath, "files"))
23
self.svc = SchedulerService(self.store)
24
self.getTopSched = self.svc.ref.getItem
25
self.sub = SubStore(self.store)
26
IPowerStation(self.sub).installPowerup(SubScheduler)
27
self.svc.startService()
28
self.store.transact(_)
30
def testTopScheduler(self):
32
msc = MySch(self.store)
35
t, f = self.calls.pop(0)
37
self.assertEquals(msc.count, 0)
40
t, f = self.calls.pop(0)
42
self.assertEquals(msc.count, 1)
43
self.assertEquals(self.calls, [])
44
self.store.transact(_)
46
def testSubScheduler(self):
51
t, f = self.calls.pop(0)
53
self.assertEquals(msc.count, 0)
56
t, f = self.calls.pop(0)
58
self.assertEquals(msc.count, 1)
59
self.assertEquals(self.calls, [])
60
self.store.transact(_)