Ticket #6042: my-twisted-patch-6042-3.patch

File my-twisted-patch-6042-3.patch, 8.2 KB (added by esacteksab, 3 years ago)
  • twisted/protocols/test/test_basic.py

     
    5454    @type delimiter: C{bytes}
    5555    @ivar delimiter: character used between received lines.
    5656    @type MAX_LENGTH: C{int}
    57     @ivar MAX_LENGTH: size of a line when C{lineLengthExceeded} will be called.
     57    @ivar MAX_LENGTH: size of a line when C{lineLengthExceeded}
     58        will be called.
    5859    @type clock: L{twisted.internet.task.Clock}
    5960    @ivar clock: clock simulating reactor callLater. Pass it to constructor if
    6061        you want to use the pause/rawpause functionalities.
     
    105106
    106107    def rawDataReceived(self, data):
    107108        """
    108         Read raw data, until the quantity specified by a previous 'len' line is
    109         reached.
     109        Read raw data, until the quantity specified by a previous 'len'
     110        line is reached.
    110111        """
    111112        data, rest = data[:self.length], data[self.length:]
    112113        self.length = self.length - len(data)
     
    260261        a.makeConnection(protocol.FileWrapper(t))
    261262        a.dataReceived(b'produce\nhello world\nunproduce\ngoodbye\n')
    262263        self.assertEqual(a.received,
    263                           [b'produce', b'hello world', b'unproduce', b'goodbye'])
     264                          [b'produce', b'hello world', b'unproduce',
     265                            b'goodbye'])
    264266
    265267
    266268    def test_clearLineBuffer(self):
     
    311313
    312314    def test_maximumLineLengthRemaining(self):
    313315        """
    314         C{LineReceiver} disconnects the transport it if receives a non-finished
    315         line longer than its C{MAX_LENGTH}.
     316        C{LineReceiver} disconnects the transport it if receives a
     317        non-finished line longer than its C{MAX_LENGTH}.
    316318        """
    317319        proto = basic.LineReceiver()
    318320        transport = proto_helpers.StringTransport()
     
    425427
    426428
    427429
    428 class NetstringReceiverTestCase(unittest.SynchronousTestCase, LPTestCaseMixin):
     430class NetstringReceiverTestCase(unittest.SynchronousTestCase,
     431                                LPTestCaseMixin):
    429432
    430433    strings = [b'hello', b'world', b'how', b'are', b'you123', b':today',
    431434               b"a" * 515]
     
    715718        r = self.getProtocol()
    716719        r.sendString(b"b" * 16)
    717720        self.assertEqual(r.transport.value(),
    718             struct.pack(r.structFormat, 16) + b"b" * 16)
     721                        struct.pack(r.structFormat, 16) + b"b" * 16)
    719722
    720723
    721724    def test_lengthLimitExceeded(self):
     
    735738    def test_longStringNotDelivered(self):
    736739        """
    737740        If a length prefix for a string longer than C{MAX_LENGTH} is delivered
    738         to C{dataReceived} at the same time as the entire string, the string is
    739         not passed to C{stringReceived}.
     741        to C{dataReceived} at the same time as the entire string, the string
     742        is not passed to C{stringReceived}.
    740743        """
    741744        r = self.getProtocol()
    742745        r.MAX_LENGTH = 10
     
    749752class RecvdAttributeMixin(object):
    750753    """
    751754    Mixin defining tests for string receiving protocols with a C{recvd}
    752     attribute which should be settable by application code, to be combined with
    753     L{IntNTestCaseMixin} on a L{TestCase} subclass
     755    attribute which should be settable by application code, to be combined
     756    with L{IntNTestCaseMixin} on a L{TestCase} subclass
    754757    """
    755758
    756759    def makeMessage(self, protocol, data):
    757760        """
    758         Return C{data} prefixed with message length in C{protocol.structFormat}
    759         form.
     761        Return C{data} prefixed with message length in
     762        C{protocol.structFormat} form.
    760763        """
    761764        return struct.pack(protocol.structFormat, len(data)) + data
    762765
    763766
    764767    def test_recvdContainsRemainingData(self):
    765768        """
    766         In stringReceived, recvd contains the remaining data that was passed to
    767         dataReceived that was not part of the current message.
     769        In stringReceived, recvd contains the remaining data that was passed
     770        to dataReceived that was not part of the current message.
    768771        """
    769772        result = []
    770773        r = self.getProtocol()
     
    860863
    861864
    862865
    863 class Int32TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin, RecvdAttributeMixin):
     866class Int32TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin,
     867                    RecvdAttributeMixin):
    864868    """
    865869    Test case for int32-prefixed protocol
    866870    """
     
    890894
    891895
    892896
    893 class Int16TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin, RecvdAttributeMixin):
     897class Int16TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin,
     898                    RecvdAttributeMixin):
    894899    """
    895900    Test case for int16-prefixed protocol
    896901    """
     
    929934
    930935class NewStyleInt16TestCase(Int16TestCase):
    931936    """
    932     This test case verifies that IntNStringReceiver still works when inherited
    933     by a new-style class.
     937    This test case verifies that IntNStringReceiver still works
     938    when inherited by a new-style class.
    934939    """
    935940    if _PY3:
    936941        skip = _PY3NEWSTYLESKIP
     
    948953
    949954
    950955
    951 class Int8TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin, RecvdAttributeMixin):
     956class Int8TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin,
     957                    RecvdAttributeMixin):
    952958    """
    953959    Test case for int8-prefixed protocol
    954960    """
     
    980986
    981987
    982988class OnlyProducerTransport(object):
    983     # Transport which isn't really a transport, just looks like one to
    984     # someone not looking very hard.
     989    """
     990    Transport which isn't really a transport, just looks like one to
     991    someone not looking very hard.
     992    """
    985993
    986994    paused = False
    987995    disconnecting = False
     
    10041012
    10051013
    10061014class ConsumingProtocol(basic.LineReceiver):
    1007     # Protocol that really, really doesn't want any more bytes.
     1015    """
     1016    Protocol that really, really doesn't want any more bytes.
     1017    """
    10081018
    10091019    def lineReceived(self, line):
    10101020        self.transport.write(line)
     
    10131023
    10141024
    10151025class ProducerTestCase(unittest.SynchronousTestCase):
     1026    """
     1027    Pause and Resume unittest for Producers
     1028    """
    10161029
    1017     def testPauseResume(self):
     1030    def test_pauseResume(self):
     1031    """
     1032    Data should continue to be received while pausing a producer.
     1033    """
    10181034        p = ConsumingProtocol()
    10191035        t = OnlyProducerTransport()
    10201036        p.makeConnection(t)
    10211037
    10221038        p.dataReceived(b'hello, ')
    1023         self.failIf(t.data)
    1024         self.failIf(t.paused)
    1025         self.failIf(p.paused)
     1039        self.assertEqual(t.data, [])
     1040        p.pauseProducing()
     1041        self.assertTrue(p.paused)
    10261042
     1043        p.resumeProducing()
    10271044        p.dataReceived(b'world\r\n')
    1028 
    10291045        self.assertEqual(t.data, [b'hello, world'])
    1030         self.failUnless(t.paused)
    1031         self.failUnless(p.paused)
     1046        p.pauseProducing()
     1047        self.assertTrue(p.paused)
    10321048
    10331049        p.resumeProducing()
    1034 
    1035         self.failIf(t.paused)
    1036         self.failIf(p.paused)
    1037 
    10381050        p.dataReceived(b'hello\r\nworld\r\n')
    1039 
    10401051        self.assertEqual(t.data, [b'hello, world', b'hello'])
    1041         self.failUnless(t.paused)
    1042         self.failUnless(p.paused)
     1052        p.pauseProducing()
     1053        self.assertTrue(p.paused)
    10431054
    10441055        p.resumeProducing()
    10451056        p.dataReceived(b'goodbye\r\n')
    1046 
    10471057        self.assertEqual(t.data, [b'hello, world', b'hello', b'world'])
    1048         self.failUnless(t.paused)
    1049         self.failUnless(p.paused)
     1058        p.pauseProducing()
     1059        self.assertTrue(p.paused)
    10501060
    10511061        p.resumeProducing()
     1062        self.assertEqual(t.data, [b'hello, world', b'hello', b'world',
     1063                                    b'goodbye'])
     1064        p.pauseProducing()
     1065        self.assertTrue(p.paused)
    10521066
    1053         self.assertEqual(t.data, [b'hello, world', b'hello', b'world', b'goodbye'])
    1054         self.failUnless(t.paused)
    1055         self.failUnless(p.paused)
    1056 
    10571067        p.resumeProducing()
    1058 
    1059         self.assertEqual(t.data, [b'hello, world', b'hello', b'world', b'goodbye'])
    1060         self.failIf(t.paused)
    1061         self.failIf(p.paused)
     1068        self.assertEqual(t.data, [b'hello, world', b'hello', b'world',
     1069                                    b'goodbye'])
     1070        p.pauseProducing()
     1071        self.assertTrue(p.paused)