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
50 def testOutputBlocker(self
):
51 readable
, writeable
= os
.pipe()
53 # Fill the input buffer...
56 ob
= tasks
.OutputBlocker(writeable
)
57 tb
= tasks
.TimeoutBlocker(0.2)
60 sent
+= os
.write(writeable
, 'Hello\n')
65 #print "send %d bytes" % sent
70 got
+= len(os
.read(readable
, sent
- got
))
72 ob
= tasks
.OutputBlocker(writeable
)
73 tb
= tasks
.TimeoutBlocker(0.2)
76 assert not tb
.happened
82 suite
= unittest
.makeSuite(TestTasks
)
83 if __name__
== '__main__':