Work in progress: set up basic agent functionality (with unit tests...)
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1784 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
d66bd7591c
commit
271b0da1c2
1 changed files with 17 additions and 7 deletions
|
@ -1,8 +1,11 @@
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
import unittest, doctest
|
import unittest as standard_unittest
|
||||||
|
import doctest
|
||||||
import time
|
import time
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
|
from twisted.internet.defer import Deferred
|
||||||
|
from twisted.trial import unittest
|
||||||
|
|
||||||
from loops.agent.core import Agent
|
from loops.agent.core import Agent
|
||||||
from loops.agent.schedule import Job
|
from loops.agent.schedule import Job
|
||||||
|
@ -10,9 +13,10 @@ from loops.agent.schedule import Job
|
||||||
|
|
||||||
class TestJob(Job):
|
class TestJob(Job):
|
||||||
|
|
||||||
def execute(self, **kw):
|
def execute(self, deferred, **kw):
|
||||||
d = super(TestJob, self).execute(**kw)
|
d = super(TestJob, self).execute(**kw)
|
||||||
print 'executing'
|
#print 'executing'
|
||||||
|
deferred.callback('Done')
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,15 +26,21 @@ class Test(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.agent = Agent()
|
self.agent = Agent()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def testScheduling(self):
|
def testScheduling(self):
|
||||||
d = self.agent.scheduler.schedule(TestJob(), int(time.time())+1)
|
d = Deferred()
|
||||||
time.sleep(1)
|
job = TestJob()
|
||||||
|
job.params['deferred'] = d
|
||||||
|
w = self.agent.scheduler.schedule(job, int(time.time())+1)
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
||||||
return unittest.TestSuite((
|
return standard_unittest.TestSuite((
|
||||||
unittest.makeSuite(Test),
|
standard_unittest.makeSuite(Test),
|
||||||
doctest.DocFileSuite('README.txt', optionflags=flags),
|
doctest.DocFileSuite('README.txt', optionflags=flags),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue