1 #!/usr/bin/env python2.3
2 from __future__
import generators
6 from os
.path
import dirname
, abspath
, join
8 rox_lib
= dirname(dirname(dirname(abspath(sys
.argv
[0]))))
9 sys
.path
.insert(0, join(rox_lib
, 'python'))
11 from rox
import tasks
, g
13 class TestTasks(unittest
.TestCase
):
14 def testIdleBlocker(self
):
21 def testTimeoutBlocker(self
):
24 yield tasks
.TimeoutBlocker(0.5)
26 assert end
> start
+ 0.5
31 def testInputBlocker(self
):
32 readable
, writeable
= os
.pipe()
34 ib
= tasks
.InputBlocker(readable
)
35 tb
= tasks
.TimeoutBlocker(0.2)
37 assert not ib
.happened
39 os
.write(writeable
, "!")
41 tb
= tasks
.TimeoutBlocker(0.2)
44 assert not tb
.happened
46 assert os
.read(readable
, 1) == '!'
48 ib
= tasks
.InputBlocker(readable
)
56 def testOutputBlocker(self
):
57 readable
, writeable
= os
.pipe()
59 # Fill the input buffer...
62 ob
= tasks
.OutputBlocker(writeable
)
63 tb
= tasks
.TimeoutBlocker(0.2)
66 sent
+= os
.write(writeable
, 'Hello\n')
71 #print "send %d bytes" % sent
76 got
+= len(os
.read(readable
, sent
- got
))
78 ob
= tasks
.OutputBlocker(writeable
)
79 tb
= tasks
.TimeoutBlocker(0.2)
82 assert not tb
.happened
88 suite
= unittest
.makeSuite(TestTasks
)
89 if __name__
== '__main__':