Ticket #4522: 0005-Explicit-test-for-_listOpenFDs.patch

File 0005-Explicit-test-for-_listOpenFDs.patch, 1.6 KB (added by Carlos Valiente, 12 years ago)

Generated using Git from branch 'svn/faster-close-fds-4522'

  • twisted/internet/test/test_process.py

    From bba90189db8e7d815c0cac0846ba1d777d03e198 Mon Sep 17 00:00:00 2001
    From: Carlos Valiente <carlos.valiente@ecmwf.int>
    Date: Tue, 29 Jun 2010 10:57:57 +0100
    Subject: [PATCH 5/5] Explicit test for _listOpenFDs.
    
    ---
     twisted/internet/test/test_process.py |   17 ++++++++++++++++-
     1 files changed, 16 insertions(+), 1 deletions(-)
    
    diff --git a/twisted/internet/test/test_process.py b/twisted/internet/test/test_process.py
    index e203006..74373dd 100644
    a b Tests for implementations of L{IReactorProcess}. 
    77
    88__metaclass__ = type
    99
    10 import os, sys, signal, threading
     10import errno, os, sys, signal, threading
    1111
    1212from twisted.trial.unittest import TestCase, SkipTest
    1313from twisted.internet.test.reactormixins import ReactorBuilder
    class ProcessTestsBuilder(ProcessTestsBuilderBase): 
    480480
    481481    def test_listOpenFDs(self):
    482482        """
     483        File descriptors returned by L{_listOpenFDs} are mostly open.
     484
     485        This test assumes that zero-legth writes fail with EBADF on closed
     486        file descriptors.
     487        """
     488        from twisted.internet import process
     489        for fd in process._listOpenFDs():
     490            try:
     491                os.write(fd, "")
     492            except OSError, err:
     493                self.assertEquals(errno.EBADF, err.errno)
     494
     495
     496    def test_openFileDescriptors(self):
     497        """
    483498        A spawned process has only stdin, stdout and stderr open
    484499        (file descriptor 3 is also reported as open, because of the call to
    485500        'os.listdir()').