OLD | NEW |
| (Empty) |
1 # -*- twisted.conch.test.test_mixin -*- | |
2 # Copyright (c) 2001-2004 Twisted Matrix Laboratories. | |
3 # See LICENSE for details. | |
4 | |
5 import time | |
6 | |
7 from twisted.internet import reactor, protocol | |
8 | |
9 from twisted.trial import unittest | |
10 from twisted.test.proto_helpers import StringTransport | |
11 | |
12 from twisted.conch import mixin | |
13 | |
14 | |
15 class TestBufferingProto(mixin.BufferingMixin): | |
16 scheduled = False | |
17 rescheduled = 0 | |
18 def schedule(self): | |
19 self.scheduled = True | |
20 return object() | |
21 | |
22 def reschedule(self, token): | |
23 self.rescheduled += 1 | |
24 | |
25 | |
26 | |
27 class BufferingTest(unittest.TestCase): | |
28 def testBuffering(self): | |
29 p = TestBufferingProto() | |
30 t = p.transport = StringTransport() | |
31 | |
32 self.failIf(p.scheduled) | |
33 | |
34 L = ['foo', 'bar', 'baz', 'quux'] | |
35 | |
36 p.write('foo') | |
37 self.failUnless(p.scheduled) | |
38 self.failIf(p.rescheduled) | |
39 | |
40 for s in L: | |
41 n = p.rescheduled | |
42 p.write(s) | |
43 self.assertEquals(p.rescheduled, n + 1) | |
44 self.assertEquals(t.value(), '') | |
45 | |
46 p.flush() | |
47 self.assertEquals(t.value(), 'foo' + ''.join(L)) | |
OLD | NEW |