Ticket #4539: test_foo.py

File test_foo.py, 1.0 KB (added by Jan Urbański, 10 years ago)

failing test case

Line 
1import os
2
3from zope.interface import implements
4
5from twisted.trial import unittest
6from twisted.internet import interfaces, reactor, defer
7
8
9class TestRemovingDescriptor(object):
10
11    implements(interfaces.IReadDescriptor)
12
13    def __init__(self, reactor):
14        self.reactor = reactor
15
16        self.read, self.write = os.pipe()
17        self.d = defer.Deferred()
18        self.insideReactor = False
19
20    def start(self):
21        self.reactor.addReader(self)
22        self.insideReactor = True
23        os.write(self.write, 'a')
24        return self.d
25
26    def doRead(self):
27        self.reactor.removeReader(self)
28        self.insideReactor = False
29        self.d.callback(self)
30
31    def logPrefix(self):
32        return 'foo'
33
34    def fileno(self):
35        assert self.insideReactor, "fileno() called outside of the reactor"
36        return self.read
37
38    def connectionLost(self, reason):
39        pass
40
41
42
43class FileDescriptorTestCase(unittest.TestCase):
44
45    def test_removeFromReactor(self):
46        return TestRemovingDescriptor(reactor).start()