Ticket #6042: 6042_introom_2.patch

File 6042_introom_2.patch, 5.4 KB (added by eddie, 8 years ago)
  • twisted/protocols/test/test_basic.py

     
    218218
    219219    rawpauseOutput1 = [b'twiddle1', b'twiddle2', b'len 5', b'rawpause', b'']
    220220    rawpauseOutput2 = [b'twiddle1', b'twiddle2', b'len 5', b'rawpause',
    221                         b'12345', b'twiddle3']
     221                       b'12345', b'twiddle3']
    222222
    223223
    224224    def test_rawPausing(self):
     
    264264        t = proto_helpers.StringIOWithoutClosing()
    265265        a.makeConnection(protocol.FileWrapper(t))
    266266        a.dataReceived(b'produce\nhello world\nunproduce\ngoodbye\n')
    267         self.assertEqual(a.received,
    268                           [b'produce', b'hello world', b'unproduce', b'goodbye'])
     267        self.assertEqual(
     268            a.received, [b'produce', b'hello world', b'unproduce', b'goodbye'])
    269269
    270270
    271271    def test_clearLineBuffer(self):
     
    630630        """
    631631        tooLong = self.netstringReceiver.MAX_LENGTH + 1
    632632        self.netstringReceiver.dataReceived(b"".join(
    633                 (bytes(tooLong), b":", b"a" * tooLong)))
     633            (bytes(tooLong), b":", b"a" * tooLong)))
    634634        self.assertTrue(self.transport.disconnecting)
    635635
    636636
     
    728728        r = self.getProtocol()
    729729        r.sendString(b"b" * 16)
    730730        self.assertEqual(r.transport.value(),
    731             struct.pack(r.structFormat, 16) + b"b" * 16)
     731                         struct.pack(r.structFormat, 16) + b"b" * 16)
    732732
    733733
    734734    def test_lengthLimitExceeded(self):
     
    882882
    883883
    884884
    885 class Int32TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin, RecvdAttributeMixin):
     885class Int32TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin,
     886                    RecvdAttributeMixin):
    886887    """
    887888    Test case for int32-prefixed protocol
    888889    """
     
    912913
    913914
    914915
    915 class Int16TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin, RecvdAttributeMixin):
     916class Int16TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin,
     917                    RecvdAttributeMixin):
    916918    """
    917919    Test case for int16-prefixed protocol
    918920    """
     
    970972
    971973
    972974
    973 class Int8TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin, RecvdAttributeMixin):
     975class Int8TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin,
     976                   RecvdAttributeMixin):
    974977    """
    975978    Test case for int8-prefixed protocol
    976979    """
     
    10021005
    10031006
    10041007class OnlyProducerTransport(object):
    1005     # Transport which isn't really a transport, just looks like one to
    1006     # someone not looking very hard.
     1008    """
     1009    Transport which isn't really a transport, just looks like one to
     1010    someone not looking very hard.
     1011    """
    10071012
    10081013    paused = False
    10091014    disconnecting = False
     
    10261031
    10271032
    10281033class ConsumingProtocol(basic.LineReceiver):
    1029     # Protocol that really, really doesn't want any more bytes.
     1034    """
     1035    Protocol that really, really doesn't want any more bytes.
     1036    """
    10301037
    10311038    def lineReceived(self, line):
    10321039        self.transport.write(line)
     
    10351042
    10361043
    10371044class ProducerTestCase(unittest.SynchronousTestCase):
     1045    """
     1046    Pause and resume a producer.
     1047    """
    10381048
    10391049    def testPauseResume(self):
     1050        """
     1051        The producer should be paused when data is received and not paused when
     1052        resumed.
     1053        """
    10401054        p = ConsumingProtocol()
    10411055        t = OnlyProducerTransport()
    10421056        p.makeConnection(t)
    10431057
    10441058        p.dataReceived(b'hello, ')
    1045         self.failIf(t.data)
    1046         self.failIf(t.paused)
    1047         self.failIf(p.paused)
     1059        self.assertEqual(t.data, [])
     1060        self.assertFalse(t.paused)
     1061        self.assertFalse(p.paused)
    10481062
    10491063        p.dataReceived(b'world\r\n')
    10501064
    10511065        self.assertEqual(t.data, [b'hello, world'])
    1052         self.failUnless(t.paused)
    1053         self.failUnless(p.paused)
     1066        self.assertTrue(t.paused)
     1067        self.assertTrue(p.paused)
    10541068
    10551069        p.resumeProducing()
    10561070
    1057         self.failIf(t.paused)
    1058         self.failIf(p.paused)
     1071        self.assertFalse(t.paused)
     1072        self.assertFalse(p.paused)
    10591073
    10601074        p.dataReceived(b'hello\r\nworld\r\n')
    10611075
    10621076        self.assertEqual(t.data, [b'hello, world', b'hello'])
    1063         self.failUnless(t.paused)
    1064         self.failUnless(p.paused)
     1077        self.assertTrue(t.paused)
     1078        self.assertTrue(p.paused)
    10651079
    10661080        p.resumeProducing()
    10671081        p.dataReceived(b'goodbye\r\n')
    10681082
    10691083        self.assertEqual(t.data, [b'hello, world', b'hello', b'world'])
    1070         self.failUnless(t.paused)
    1071         self.failUnless(p.paused)
     1084        self.assertTrue(t.paused)
     1085        self.assertTrue(p.paused)
    10721086
    10731087        p.resumeProducing()
    10741088
    1075         self.assertEqual(t.data, [b'hello, world', b'hello', b'world', b'goodbye'])
    1076         self.failUnless(t.paused)
    1077         self.failUnless(p.paused)
     1089        self.assertEqual(
     1090            t.data, [b'hello, world', b'hello', b'world', b'goodbye'])
     1091        self.assertTrue(t.paused)
     1092        self.assertTrue(p.paused)
    10781093
    10791094        p.resumeProducing()
    10801095
    1081         self.assertEqual(t.data, [b'hello, world', b'hello', b'world', b'goodbye'])
    1082         self.failIf(t.paused)
    1083         self.failIf(p.paused)
     1096        self.assertEqual(
     1097            t.data, [b'hello, world', b'hello', b'world', b'goodbye'])
     1098        self.assertFalse(t.paused)
     1099        self.assertFalse(p.paused)
    10841100
    10851101
    10861102