Ticket #5812: print-core-tests-5812.patch
| File print-core-tests-5812.patch, 12.2 KB (added by thijs, 10 months ago) |
|---|
-
twisted/test/iosim.py
182 182 ft.protocol = s 183 183 return ft 184 184 185 186 185 187 class IOPump: 186 """Utility to pump data between clients and servers for protocol testing. 188 """ 189 Utility to pump data between clients and servers for protocol testing. 187 190 188 191 Perhaps this is a utility worthy of being in protocol.py? 189 192 """ … … 194 197 self.serverIO = serverIO 195 198 self.debug = debug 196 199 200 197 201 def flush(self, debug=False): 198 """Pump until there is no more input or output. 202 """ 203 Pump until there is no more input or output. 199 204 200 205 Returns whether any data was moved. 201 206 """ … … 211 216 212 217 213 218 def pump(self, debug=False): 214 """Move data back and forth. 219 """ 220 Move data back and forth. 215 221 216 222 Returns whether any data was moved. 217 223 """ 218 224 if self.debug or debug: 219 print '-- GLUG --'225 print('-- GLUG --') 220 226 sData = self.serverIO.getOutBuffer() 221 227 cData = self.clientIO.getOutBuffer() 222 228 self.clientIO._checkProducer() 223 229 self.serverIO._checkProducer() 224 230 if self.debug or debug: 225 print '.'231 print('.') 226 232 # XXX slightly buggy in the face of incremental output 227 233 if cData: 228 print 'C: '+repr(cData)234 print('C: ' + repr(cData)) 229 235 if sData: 230 print 'S: '+repr(sData)236 print('S: ' + repr(sData)) 231 237 if cData: 232 238 self.serverIO.bufferReceived(cData) 233 239 if sData: … … 237 243 if (self.serverIO.disconnecting and 238 244 not self.serverIO.disconnected): 239 245 if self.debug or debug: 240 print '* C'246 print('* C') 241 247 self.serverIO.disconnected = True 242 248 self.clientIO.disconnecting = True 243 249 self.clientIO.reportDisconnect() 244 250 return True 245 251 if self.clientIO.disconnecting and not self.clientIO.disconnected: 246 252 if self.debug or debug: 247 print '* S'253 print('* S') 248 254 self.clientIO.disconnected = True 249 255 self.serverIO.disconnecting = True 250 256 self.serverIO.reportDisconnect() -
twisted/test/process_fds.py
1 2 """Write to a handful of file descriptors, to test the childFDs= argument of1 """ 2 Write to a handful of file descriptors, to test the childFDs= argument of 3 3 reactor.spawnProcess() 4 4 """ 5 5 6 from __future__ import print_function 7 6 8 import os, sys 7 9 8 10 debug = 0 9 11 10 if debug: stderr = os.fdopen(2, "w") 12 if debug: 13 stderr = os.fdopen(2, "w") 11 14 12 if debug: print >>stderr, "this is stderr" 15 if debug: 16 print("this is stderr", file=stderr) 13 17 14 18 abcd = os.read(0, 4) 15 if debug: print >>stderr, "read(0):", abcd 19 if debug: 20 print("read(0):", abcd, file=stderr) 16 21 if abcd != "abcd": 17 22 sys.exit(1) 18 23 19 if debug: print >>stderr, "os.write(1, righto)" 24 if debug: 25 print("os.write(1, righto)", file=stderr) 20 26 21 27 os.write(1, "righto") 22 28 23 29 efgh = os.read(3, 4) 24 if debug: print >>stderr, "read(3):", efgh 30 if debug: 31 print("read(3):", efgh, file=stderr) 25 32 if efgh != "efgh": 26 33 sys.exit(2) 27 34 28 if debug: print >>stderr, "os.close(4)" 35 if debug: 36 print("os.close(4)", file=stderr) 29 37 os.close(4) 30 38 31 39 eof = os.read(5, 4) 32 if debug: print >>stderr, "read(5):", eof 40 if debug: 41 print("read(5):", eof, file=stderr) 33 42 if eof != "": 34 43 sys.exit(3) 35 44 36 if debug: print >>stderr, "os.write(1, closed)" 45 if debug: 46 print("os.write(1, closed)", file=stderr) 37 47 os.write(1, "closed") 38 48 39 if debug: print >>stderr, "sys.exit(0)" 49 if debug: 50 print("sys.exit(0)", file=stderr) 40 51 sys.exit(0) -
twisted/test/process_linger.py
1 2 """Write to a file descriptor and then close it, waiting a few seconds before1 """ 2 Write to a file descriptor and then close it, waiting a few seconds before 3 3 quitting. This serves to make sure SIGCHLD is actually being noticed. 4 4 """ 5 5 6 6 import os, sys, time 7 7 8 print "here is some text"8 print("here is some text") 9 9 time.sleep(1) 10 print "goodbye"10 print("goodbye") 11 11 os.close(1) 12 12 os.close(2) 13 13 -
twisted/test/process_twisted.py
1 """A process that reads from stdin and out using Twisted.""" 1 """ 2 A process that reads from stdin and out using Twisted. 3 """ 4 5 from __future__ import print_function 2 6 3 7 ### Twisted Preamble 4 8 # This makes sure that users don't have to set up their environment … … 24 28 implements(interfaces.IHalfCloseableProtocol) 25 29 26 30 def connectionMade(self): 27 print "connection made"31 print("connection made") 28 32 29 33 def dataReceived(self, data): 30 34 self.transport.write(data) 31 35 32 36 def readConnectionLost(self): 33 print "readConnectionLost"37 print("readConnectionLost") 34 38 self.transport.loseConnection() 35 39 def writeConnectionLost(self): 36 print "writeConnectionLost"40 print("writeConnectionLost") 37 41 38 42 def connectionLost(self, reason): 39 print "connectionLost", reason43 print("connectionLost", reason) 40 44 reactor.stop() 41 45 42 46 stdio.StandardIO(Echo()) -
twisted/test/test_tcp.py
5 5 Tests for implementations of L{IReactorTCP}. 6 6 """ 7 7 8 from __future__ import print_function 9 8 10 import socket, random, errno 9 11 10 12 from zope.interface import implements … … 850 852 self.transport.writeSequence(seq) 851 853 peer = self.transport.getPeer() 852 854 if peer.type != "TCP": 853 print "getPeer returned non-TCP socket:", peer855 print("getPeer returned non-TCP socket:", peer) 854 856 self.factory.problem = 1 855 857 us = self.transport.getHost() 856 858 if us.type != "TCP": 857 print "getHost returned non-TCP socket:", us859 print("getHost returned non-TCP socket:", us) 858 860 self.factory.problem = 1 859 861 self.factory.done = 1 860 862 861 863 self.transport.loseConnection() 862 864 865 866 863 867 class ReaderProtocol(protocol.Protocol): 864 868 def dataReceived(self, data): 865 869 self.factory.data += data -
twisted/test/process_cmdline.py
1 """Write to stdout the command line args it received, one per line.""" 1 """ 2 Write to stdout the command line args it received, one per line. 3 """ 2 4 3 5 import sys 4 6 for x in sys.argv[1:]: 5 print x7 print(x) -
twisted/test/test_log.py
5 5 Tests for L{twisted.python.log}. 6 6 """ 7 7 8 from __future__ import print_function 9 8 10 import os, sys, time, logging, warnings, calendar 9 11 from cStringIO import StringIO 10 12 … … 737 739 oldStdout = sys.stdout 738 740 sys.stdout = log.StdioOnnaStick() 739 741 self.addCleanup(setattr, sys, "stdout", oldStdout) 740 print "This",741 print "is a test"742 print("This", end=' ') 743 print("is a test") 742 744 self.assertEqual(self.getLogMessages(), ["This is a test"]) 743 745 744 746 … … 765 767 sys.stdout = stdio 766 768 self.addCleanup(setattr, sys, "stdout", oldStdout) 767 769 # This should go to the log, utf-8 encoded too: 768 print unicodeString770 print(unicodeString) 769 771 self.assertEqual(self.getLogMessages(), 770 772 [unicodeString.encode("utf-8"), 771 773 (u"Also, " + unicodeString).encode("utf-8"), -
twisted/test/process_signal.py
3 3 signal.signal(signal.SIGINT, signal.SIG_DFL) 4 4 if getattr(signal, "SIGHUP", None) is not None: 5 5 signal.signal(signal.SIGHUP, signal.SIG_DFL) 6 print 'ok, signal us'6 print('ok, signal us') 7 7 sys.stdin.read() 8 8 sys.exit(1) -
twisted/test/test_process.py
5 5 Test running processes. 6 6 """ 7 7 8 from __future__ import print_function 9 8 10 import gzip 9 11 import os 10 12 import sys … … 766 768 self.finished = 1 767 769 self.deferred.callback(None) 768 770 771 772 769 773 class TestTwoProcessesBase: 770 774 def setUp(self): 771 775 self.processes = [None, None] … … 773 777 self.done = 0 774 778 self.verbose = 0 775 779 780 776 781 def createProcesses(self, usePTY=0): 777 782 exe = sys.executable 778 783 scriptPath = util.sibpath(__file__, "process_reader.py") … … 784 789 usePTY=usePTY) 785 790 self.processes[num] = p 786 791 792 787 793 def close(self, num): 788 if self.verbose: print "closing stdin [%d]" % num794 if self.verbose: print("closing stdin [%d]" % num) 789 795 p = self.processes[num] 790 796 pp = self.pp[num] 791 797 self.failIf(pp.finished, "Process finished too early") 792 798 p.loseConnection() 793 if self.verbose: print self.pp[0].finished, self.pp[1].finished 799 if self.verbose: print(self.pp[0].finished, self.pp[1].finished) 800 794 801 795 802 def _onClose(self): 796 803 return defer.gatherResults([ p.deferred for p in self.pp ]) 797 804 798 def testClose(self): 799 if self.verbose: print "starting processes" 805 806 def test_close(self): 807 if self.verbose: print("starting processes") 800 808 self.createProcesses() 801 809 reactor.callLater(1, self.close, 0) 802 810 reactor.callLater(2, self.close, 1) 803 811 return self._onClose() 804 812 813 814 805 815 class TestTwoProcessesNonPosix(TestTwoProcessesBase, unittest.TestCase): 806 816 pass 807 817 818 819 808 820 class TestTwoProcessesPosix(TestTwoProcessesBase, unittest.TestCase): 809 821 def tearDown(self): 810 822 for pp, pr in zip(self.pp, self.processes): … … 817 829 pass 818 830 return self._onClose() 819 831 832 820 833 def kill(self, num): 821 if self.verbose: print "kill [%d] with SIGTERM" % num834 if self.verbose: print("kill [%d] with SIGTERM" % num) 822 835 p = self.processes[num] 823 836 pp = self.pp[num] 824 837 self.failIf(pp.finished, "Process finished too early") 825 838 os.kill(p.pid, signal.SIGTERM) 826 if self.verbose: print self.pp[0].finished, self.pp[1].finished839 if self.verbose: print(self.pp[0].finished, self.pp[1].finished) 827 840 828 def testKill(self): 829 if self.verbose: print "starting processes" 841 842 def test_kill(self): 843 if self.verbose: print("starting processes") 830 844 self.createProcesses(usePTY=0) 831 845 reactor.callLater(1, self.kill, 0) 832 846 reactor.callLater(2, self.kill, 1) 833 847 return self._onClose() 834 848 835 def test ClosePty(self):836 if self.verbose: print "starting processes"849 def test_closePty(self): 850 if self.verbose: print("starting processes") 837 851 self.createProcesses(usePTY=1) 838 852 reactor.callLater(1, self.close, 0) 839 853 reactor.callLater(2, self.close, 1) 840 854 return self._onClose() 841 855 842 def testKillPty(self): 843 if self.verbose: print "starting processes" 856 857 def test_killPty(self): 858 if self.verbose: print("starting processes") 844 859 self.createProcesses(usePTY=1) 845 860 reactor.callLater(1, self.kill, 0) 846 861 reactor.callLater(2, self.kill, 1) 847 862 return self._onClose() 848 863 864 865 849 866 class FDChecker(protocol.ProcessProtocol): 850 867 state = 0 851 868 data = ""
