~pythonregexp2.7/python/issue2636-12

« back to all changes in this revision

Viewing changes to Lib/test/test_subprocess.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-06-09 14:52:42 UTC
  • mfrom: (39033.1.3 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080609145242-9m268zc6u87rp1vp
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
287
287
                             stderr=subprocess.PIPE)
288
288
        (stdout, stderr) = p.communicate()
289
289
        self.assertEqual(stdout, None)
290
 
        # When running with a pydebug build, the # of references is outputted
291
 
        # to stderr, so just check if stderr at least started with "pinapple"
292
 
        self.assert_(stderr.startswith("pineapple"))
 
290
        self.assertEqual(remove_stderr_debug_decorations(stderr), "pineapple")
293
291
 
294
292
    def test_communicate(self):
295
293
        p = subprocess.Popen([sys.executable, "-c",
296
 
                          'import sys,os;' \
297
 
                          'sys.stderr.write("pineapple");' \
 
294
                          'import sys,os;'
 
295
                          'sys.stderr.write("pineapple");'
298
296
                          'sys.stdout.write(sys.stdin.read())'],
299
297
                         stdin=subprocess.PIPE,
300
298
                         stdout=subprocess.PIPE,
304
302
        self.assertEqual(remove_stderr_debug_decorations(stderr),
305
303
                         "pineapple")
306
304
 
 
305
    # This test is Linux specific for simplicity to at least have
 
306
    # some coverage.  It is not a platform specific bug.
 
307
    if os.path.isdir('/proc/%d/fd' % os.getpid()):
 
308
        # Test for the fd leak reported in http://bugs.python.org/issue2791.
 
309
        def test_communicate_pipe_fd_leak(self):
 
310
            fd_directory = '/proc/%d/fd' % os.getpid()
 
311
            num_fds_before_popen = len(os.listdir(fd_directory))
 
312
            p = subprocess.Popen([sys.executable, '-c', 'print()'],
 
313
                                 stdout=subprocess.PIPE)
 
314
            p.communicate()
 
315
            num_fds_after_communicate = len(os.listdir(fd_directory))
 
316
            del p
 
317
            num_fds_after_destruction = len(os.listdir(fd_directory))
 
318
            self.assertEqual(num_fds_before_popen, num_fds_after_destruction)
 
319
            self.assertEqual(num_fds_before_popen, num_fds_after_communicate)
 
320
 
307
321
    def test_communicate_returns(self):
308
322
        # communicate() should return None if no redirection is active
309
323
        p = subprocess.Popen([sys.executable, "-c",