Ticket #5812: print-core-tests-5812.patch

File print-core-tests-5812.patch, 12.2 KB (added by thijs, 4 years ago)
  • twisted/test/iosim.py

     
    182182    ft.protocol = s
    183183    return ft
    184184
     185
     186
    185187class 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.
    187190
    188191    Perhaps this is a utility worthy of being in protocol.py?
    189192    """
     
    194197        self.serverIO = serverIO
    195198        self.debug = debug
    196199
     200
    197201    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.
    199204
    200205        Returns whether any data was moved.
    201206        """
     
    211216
    212217
    213218    def pump(self, debug=False):
    214         """Move data back and forth.
     219        """
     220        Move data back and forth.
    215221
    216222        Returns whether any data was moved.
    217223        """
    218224        if self.debug or debug:
    219             print '-- GLUG --'
     225            print('-- GLUG --')
    220226        sData = self.serverIO.getOutBuffer()
    221227        cData = self.clientIO.getOutBuffer()
    222228        self.clientIO._checkProducer()
    223229        self.serverIO._checkProducer()
    224230        if self.debug or debug:
    225             print '.'
     231            print('.')
    226232            # XXX slightly buggy in the face of incremental output
    227233            if cData:
    228                 print 'C: '+repr(cData)
     234                print('C: ' + repr(cData))
    229235            if sData:
    230                 print 'S: '+repr(sData)
     236                print('S: ' + repr(sData))
    231237        if cData:
    232238            self.serverIO.bufferReceived(cData)
    233239        if sData:
     
    237243        if (self.serverIO.disconnecting and
    238244            not self.serverIO.disconnected):
    239245            if self.debug or debug:
    240                 print '* C'
     246                print('* C')
    241247            self.serverIO.disconnected = True
    242248            self.clientIO.disconnecting = True
    243249            self.clientIO.reportDisconnect()
    244250            return True
    245251        if self.clientIO.disconnecting and not self.clientIO.disconnected:
    246252            if self.debug or debug:
    247                 print '* S'
     253                print('* S')
    248254            self.clientIO.disconnected = True
    249255            self.serverIO.disconnecting = True
    250256            self.serverIO.reportDisconnect()
  • twisted/test/process_fds.py

     
    1 
    2 """Write to a handful of file descriptors, to test the childFDs= argument of
     1"""
     2Write to a handful of file descriptors, to test the childFDs= argument of
    33reactor.spawnProcess()
    44"""
    55
     6from __future__ import print_function
     7
    68import os, sys
    79
    810debug = 0
    911
    10 if debug: stderr = os.fdopen(2, "w")
     12if debug:
     13    stderr = os.fdopen(2, "w")
    1114
    12 if debug: print >>stderr, "this is stderr"
     15if debug:
     16    print("this is stderr", file=stderr)
    1317
    1418abcd = os.read(0, 4)
    15 if debug: print >>stderr, "read(0):", abcd
     19if debug:
     20    print("read(0):", abcd, file=stderr)
    1621if abcd != "abcd":
    1722    sys.exit(1)
    1823
    19 if debug: print >>stderr, "os.write(1, righto)"
     24if debug:
     25    print("os.write(1, righto)", file=stderr)
    2026
    2127os.write(1, "righto")
    2228
    2329efgh = os.read(3, 4)
    24 if debug: print >>stderr, "read(3):", efgh
     30if debug:
     31    print("read(3):", efgh, file=stderr)
    2532if efgh != "efgh":
    2633    sys.exit(2)
    2734
    28 if debug: print >>stderr, "os.close(4)"
     35if debug:
     36    print("os.close(4)", file=stderr)
    2937os.close(4)
    3038
    3139eof = os.read(5, 4)
    32 if debug: print >>stderr, "read(5):", eof
     40if debug:
     41    print("read(5):", eof, file=stderr)
    3342if eof != "":
    3443    sys.exit(3)
    3544
    36 if debug: print >>stderr, "os.write(1, closed)"
     45if debug:
     46    print("os.write(1, closed)", file=stderr)
    3747os.write(1, "closed")
    3848
    39 if debug: print >>stderr, "sys.exit(0)"
     49if debug:
     50    print("sys.exit(0)", file=stderr)
    4051sys.exit(0)
  • twisted/test/process_linger.py

     
    1 
    2 """Write to a file descriptor and then close it, waiting a few seconds before
     1"""
     2Write to a file descriptor and then close it, waiting a few seconds before
    33quitting. This serves to make sure SIGCHLD is actually being noticed.
    44"""
    55
    66import os, sys, time
    77
    8 print "here is some text"
     8print("here is some text")
    99time.sleep(1)
    10 print "goodbye"
     10print("goodbye")
    1111os.close(1)
    1212os.close(2)
    1313
  • twisted/test/process_twisted.py

     
    1 """A process that reads from stdin and out using Twisted."""
     1"""
     2A process that reads from stdin and out using Twisted.
     3"""
     4
     5from __future__ import print_function
    26
    37### Twisted Preamble
    48# This makes sure that users don't have to set up their environment
     
    2428    implements(interfaces.IHalfCloseableProtocol)
    2529   
    2630    def connectionMade(self):
    27         print "connection made"
     31        print("connection made")
    2832   
    2933    def dataReceived(self, data):
    3034        self.transport.write(data)
    3135
    3236    def readConnectionLost(self):
    33         print "readConnectionLost"
     37        print("readConnectionLost")
    3438        self.transport.loseConnection()
    3539    def writeConnectionLost(self):
    36         print "writeConnectionLost"
     40        print("writeConnectionLost")
    3741   
    3842    def connectionLost(self, reason):
    39         print "connectionLost", reason
     43        print("connectionLost", reason)
    4044        reactor.stop()
    4145
    4246stdio.StandardIO(Echo())
  • twisted/test/test_tcp.py

     
    55Tests for implementations of L{IReactorTCP}.
    66"""
    77
     8from __future__ import print_function
     9
    810import socket, random, errno
    911
    1012from zope.interface import implements
     
    850852        self.transport.writeSequence(seq)
    851853        peer = self.transport.getPeer()
    852854        if peer.type != "TCP":
    853             print "getPeer returned non-TCP socket:", peer
     855            print("getPeer returned non-TCP socket:", peer)
    854856            self.factory.problem = 1
    855857        us = self.transport.getHost()
    856858        if us.type != "TCP":
    857             print "getHost returned non-TCP socket:", us
     859            print("getHost returned non-TCP socket:", us)
    858860            self.factory.problem = 1
    859861        self.factory.done = 1
    860862
    861863        self.transport.loseConnection()
    862864
     865
     866
    863867class ReaderProtocol(protocol.Protocol):
    864868    def dataReceived(self, data):
    865869        self.factory.data += data
  • twisted/test/process_cmdline.py

     
    1 """Write to stdout the command line args it received, one per line."""
     1"""
     2Write to stdout the command line args it received, one per line.
     3"""
    24
    35import sys
    46for x in sys.argv[1:]:
    5     print x
     7    print(x)
  • twisted/test/test_log.py

     
    55Tests for L{twisted.python.log}.
    66"""
    77
     8from __future__ import print_function
     9
    810import os, sys, time, logging, warnings, calendar
    911from cStringIO import StringIO
    1012
     
    737739        oldStdout = sys.stdout
    738740        sys.stdout = log.StdioOnnaStick()
    739741        self.addCleanup(setattr, sys, "stdout", oldStdout)
    740         print "This",
    741         print "is a test"
     742        print("This", end=' ')
     743        print("is a test")
    742744        self.assertEqual(self.getLogMessages(), ["This is a test"])
    743745
    744746
     
    765767        sys.stdout = stdio
    766768        self.addCleanup(setattr, sys, "stdout", oldStdout)
    767769        # This should go to the log, utf-8 encoded too:
    768         print unicodeString
     770        print(unicodeString)
    769771        self.assertEqual(self.getLogMessages(),
    770772                         [unicodeString.encode("utf-8"),
    771773                          (u"Also, " + unicodeString).encode("utf-8"),
  • twisted/test/process_signal.py

     
    33signal.signal(signal.SIGINT, signal.SIG_DFL)
    44if getattr(signal, "SIGHUP", None) is not None:
    55    signal.signal(signal.SIGHUP, signal.SIG_DFL)
    6 print 'ok, signal us'
     6print('ok, signal us')
    77sys.stdin.read()
    88sys.exit(1)
  • twisted/test/test_process.py

     
    55Test running processes.
    66"""
    77
     8from __future__ import print_function
     9
    810import gzip
    911import os
    1012import sys
     
    766768        self.finished = 1
    767769        self.deferred.callback(None)
    768770
     771
     772
    769773class TestTwoProcessesBase:
    770774    def setUp(self):
    771775        self.processes = [None, None]
     
    773777        self.done = 0
    774778        self.verbose = 0
    775779
     780
    776781    def createProcesses(self, usePTY=0):
    777782        exe = sys.executable
    778783        scriptPath = util.sibpath(__file__, "process_reader.py")
     
    784789                                     usePTY=usePTY)
    785790            self.processes[num] = p
    786791
     792
    787793    def close(self, num):
    788         if self.verbose: print "closing stdin [%d]" % num
     794        if self.verbose: print("closing stdin [%d]" % num)
    789795        p = self.processes[num]
    790796        pp = self.pp[num]
    791797        self.failIf(pp.finished, "Process finished too early")
    792798        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
    794801
    795802    def _onClose(self):
    796803        return defer.gatherResults([ p.deferred for p in self.pp ])
    797804
    798     def testClose(self):
    799         if self.verbose: print "starting processes"
     805
     806    def test_close(self):
     807        if self.verbose: print("starting processes")
    800808        self.createProcesses()
    801809        reactor.callLater(1, self.close, 0)
    802810        reactor.callLater(2, self.close, 1)
    803811        return self._onClose()
    804812
     813
     814
    805815class TestTwoProcessesNonPosix(TestTwoProcessesBase, unittest.TestCase):
    806816    pass
    807817
     818
     819
    808820class TestTwoProcessesPosix(TestTwoProcessesBase, unittest.TestCase):
    809821    def tearDown(self):
    810822        for pp, pr in zip(self.pp, self.processes):
     
    817829                    pass
    818830        return self._onClose()
    819831
     832
    820833    def kill(self, num):
    821         if self.verbose: print "kill [%d] with SIGTERM" % num
     834        if self.verbose: print("kill [%d] with SIGTERM" % num)
    822835        p = self.processes[num]
    823836        pp = self.pp[num]
    824837        self.failIf(pp.finished, "Process finished too early")
    825838        os.kill(p.pid, signal.SIGTERM)
    826         if self.verbose: print self.pp[0].finished, self.pp[1].finished
     839        if self.verbose: print(self.pp[0].finished, self.pp[1].finished)
    827840
    828     def testKill(self):
    829         if self.verbose: print "starting processes"
     841
     842    def test_kill(self):
     843        if self.verbose: print("starting processes")
    830844        self.createProcesses(usePTY=0)
    831845        reactor.callLater(1, self.kill, 0)
    832846        reactor.callLater(2, self.kill, 1)
    833847        return self._onClose()
    834848
    835     def testClosePty(self):
    836         if self.verbose: print "starting processes"
     849    def test_closePty(self):
     850        if self.verbose: print("starting processes")
    837851        self.createProcesses(usePTY=1)
    838852        reactor.callLater(1, self.close, 0)
    839853        reactor.callLater(2, self.close, 1)
    840854        return self._onClose()
    841855
    842     def testKillPty(self):
    843         if self.verbose: print "starting processes"
     856
     857    def test_killPty(self):
     858        if self.verbose: print("starting processes")
    844859        self.createProcesses(usePTY=1)
    845860        reactor.callLater(1, self.kill, 0)
    846861        reactor.callLater(2, self.kill, 1)
    847862        return self._onClose()
    848863
     864
     865
    849866class FDChecker(protocol.ProcessProtocol):
    850867    state = 0
    851868    data = ""