Ticket #6042: my-twisted-patch-6042-3.patch
File my-twisted-patch-6042-3.patch, 8.2 KB (added by , 5 years ago) |
---|
-
twisted/protocols/test/test_basic.py
54 54 @type delimiter: C{bytes} 55 55 @ivar delimiter: character used between received lines. 56 56 @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. 58 59 @type clock: L{twisted.internet.task.Clock} 59 60 @ivar clock: clock simulating reactor callLater. Pass it to constructor if 60 61 you want to use the pause/rawpause functionalities. … … 105 106 106 107 def rawDataReceived(self, data): 107 108 """ 108 Read raw data, until the quantity specified by a previous 'len' line is109 reached.109 Read raw data, until the quantity specified by a previous 'len' 110 line is reached. 110 111 """ 111 112 data, rest = data[:self.length], data[self.length:] 112 113 self.length = self.length - len(data) … … 260 261 a.makeConnection(protocol.FileWrapper(t)) 261 262 a.dataReceived(b'produce\nhello world\nunproduce\ngoodbye\n') 262 263 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']) 264 266 265 267 266 268 def test_clearLineBuffer(self): … … 311 313 312 314 def test_maximumLineLengthRemaining(self): 313 315 """ 314 C{LineReceiver} disconnects the transport it if receives a non-finished315 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}. 316 318 """ 317 319 proto = basic.LineReceiver() 318 320 transport = proto_helpers.StringTransport() … … 425 427 426 428 427 429 428 class NetstringReceiverTestCase(unittest.SynchronousTestCase, LPTestCaseMixin): 430 class NetstringReceiverTestCase(unittest.SynchronousTestCase, 431 LPTestCaseMixin): 429 432 430 433 strings = [b'hello', b'world', b'how', b'are', b'you123', b':today', 431 434 b"a" * 515] … … 715 718 r = self.getProtocol() 716 719 r.sendString(b"b" * 16) 717 720 self.assertEqual(r.transport.value(), 718 struct.pack(r.structFormat, 16) + b"b" * 16)721 struct.pack(r.structFormat, 16) + b"b" * 16) 719 722 720 723 721 724 def test_lengthLimitExceeded(self): … … 735 738 def test_longStringNotDelivered(self): 736 739 """ 737 740 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 is739 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}. 740 743 """ 741 744 r = self.getProtocol() 742 745 r.MAX_LENGTH = 10 … … 749 752 class RecvdAttributeMixin(object): 750 753 """ 751 754 Mixin defining tests for string receiving protocols with a C{recvd} 752 attribute which should be settable by application code, to be combined with753 L{IntNTestCaseMixin} on a L{TestCase} subclass755 attribute which should be settable by application code, to be combined 756 with L{IntNTestCaseMixin} on a L{TestCase} subclass 754 757 """ 755 758 756 759 def makeMessage(self, protocol, data): 757 760 """ 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. 760 763 """ 761 764 return struct.pack(protocol.structFormat, len(data)) + data 762 765 763 766 764 767 def test_recvdContainsRemainingData(self): 765 768 """ 766 In stringReceived, recvd contains the remaining data that was passed to767 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. 768 771 """ 769 772 result = [] 770 773 r = self.getProtocol() … … 860 863 861 864 862 865 863 class Int32TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin, RecvdAttributeMixin): 866 class Int32TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin, 867 RecvdAttributeMixin): 864 868 """ 865 869 Test case for int32-prefixed protocol 866 870 """ … … 890 894 891 895 892 896 893 class Int16TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin, RecvdAttributeMixin): 897 class Int16TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin, 898 RecvdAttributeMixin): 894 899 """ 895 900 Test case for int16-prefixed protocol 896 901 """ … … 929 934 930 935 class NewStyleInt16TestCase(Int16TestCase): 931 936 """ 932 This test case verifies that IntNStringReceiver still works when inherited933 by a new-style class.937 This test case verifies that IntNStringReceiver still works 938 when inherited by a new-style class. 934 939 """ 935 940 if _PY3: 936 941 skip = _PY3NEWSTYLESKIP … … 948 953 949 954 950 955 951 class Int8TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin, RecvdAttributeMixin): 956 class Int8TestCase(unittest.SynchronousTestCase, IntNTestCaseMixin, 957 RecvdAttributeMixin): 952 958 """ 953 959 Test case for int8-prefixed protocol 954 960 """ … … 980 986 981 987 982 988 class 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 """ 985 993 986 994 paused = False 987 995 disconnecting = False … … 1004 1012 1005 1013 1006 1014 class 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 """ 1008 1018 1009 1019 def lineReceived(self, line): 1010 1020 self.transport.write(line) … … 1013 1023 1014 1024 1015 1025 class ProducerTestCase(unittest.SynchronousTestCase): 1026 """ 1027 Pause and Resume unittest for Producers 1028 """ 1016 1029 1017 def testPauseResume(self): 1030 def test_pauseResume(self): 1031 """ 1032 Data should continue to be received while pausing a producer. 1033 """ 1018 1034 p = ConsumingProtocol() 1019 1035 t = OnlyProducerTransport() 1020 1036 p.makeConnection(t) 1021 1037 1022 1038 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) 1026 1042 1043 p.resumeProducing() 1027 1044 p.dataReceived(b'world\r\n') 1028 1029 1045 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) 1032 1048 1033 1049 p.resumeProducing() 1034 1035 self.failIf(t.paused)1036 self.failIf(p.paused)1037 1038 1050 p.dataReceived(b'hello\r\nworld\r\n') 1039 1040 1051 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) 1043 1054 1044 1055 p.resumeProducing() 1045 1056 p.dataReceived(b'goodbye\r\n') 1046 1047 1057 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) 1050 1060 1051 1061 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) 1052 1066 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 1057 1067 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)