~pythonregexp2.7/python/issue2636-11

« back to all changes in this revision

Viewing changes to Lib/test/test_file.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-21 13:47:31 UTC
  • mfrom: (39021.1.404 Regexp-2.7)
  • mto: This revision was merged to the branch mainline in revision 39030.
  • Revision ID: darklord@timehorse.com-20080921134731-rudomuzeh1b2tz1y
Merged in changes from the latest python source snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
503
503
        self._test_close_open_io(io_func)
504
504
 
505
505
 
 
506
class StdoutTests(unittest.TestCase):
 
507
 
 
508
    def test_move_stdout_on_write(self):
 
509
        # Issue 3242: sys.stdout can be replaced (and freed) during a
 
510
        # print statement; prevent a segfault in this case
 
511
        save_stdout = sys.stdout
 
512
 
 
513
        class File:
 
514
            def write(self, data):
 
515
                if '\n' in data:
 
516
                    sys.stdout = save_stdout
 
517
 
 
518
        try:
 
519
            sys.stdout = File()
 
520
            print "some text"
 
521
        finally:
 
522
            sys.stdout = save_stdout
 
523
 
506
524
 
507
525
def test_main():
508
526
    # Historically, these tests have been sloppy about removing TESTFN.
509
527
    # So get rid of it no matter what.
510
528
    try:
511
529
        run_unittest(AutoFileTests, OtherFileTests, FileSubclassTests,
512
 
            FileThreadingTests)
 
530
            FileThreadingTests, StdoutTests)
513
531
    finally:
514
532
        if os.path.exists(TESTFN):
515
533
            os.unlink(TESTFN)