Ticket #4522: 0006-Address-review-from-exarkun.patch

File 0006-Address-review-from-exarkun.patch, 2.5 KB (added by Carlos Valiente, 12 years ago)

Diff against svn://svn.twistedmatrix.com/svn/Twisted/branches/faster-close-fds-4522, revision 29522

  • twisted/internet/test/test_posixprocess.py

     
     1# Copyright (c) 2010 Twisted Matrix Laboratories.
     2# See LICENSE for details.
     3
     4"""
     5Tests for POSIX-based L{IReactorProcess} implementations.
     6"""
     7
     8import errno, os, sys
     9
     10from twisted.internet import process
     11from twisted.python.runtime import platformType
     12from twisted.trial.unittest import TestCase
     13
     14
     15class FileDescriptorTests(TestCase):
     16    """
     17    Tests for L{twisted.internet.process._listOpenFDs}
     18    """
     19
     20    if platformType != "posix":
     21        skip = "non-POSIX platform"
     22
     23
     24    def test_openFDs(self):
     25        """
     26        File descriptors returned by L{_listOpenFDs} are mostly open.
     27
     28        This test assumes that zero-legth writes fail with EBADF on closed
     29        file descriptors.
     30        """
     31        for fd in process._listOpenFDs():
     32            try:
     33                os.write(fd, "")
     34            except OSError, err:
     35                self.assertEquals(errno.EBADF, err.errno)
     36
     37
     38    def test_expectedFDs(self):
     39        """
     40        L{_listOpenFDs} lists expected file descriptors.
     41        """
     42        openfds = process._listOpenFDs()
     43        for f in sys.stdin, sys.stdout, sys.stderr:
     44            self.assertIn(f.fileno(), openfds)
     45
     46        f = file(os.devnull)
     47        new_openfds = process._listOpenFDs()
     48        self.assertTrue(len(new_openfds) > len(openfds))
     49
     50        f.close()
     51        new_openfds = process._listOpenFDs()
     52        self.assertEqual(len(new_openfds), len(openfds))
  • twisted/internet/test/test_process.py

     
    478478        self.runReactor(reactor)
    479479
    480480
    481     def test_listOpenFDs(self):
    482         """
    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 
    496481    def test_openFileDescriptors(self):
    497482        """
    498483        A spawned process has only stdin, stdout and stderr open