~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/conch/test/test_mixin.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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))