Ticket #15244: 15244_doctest_flush.patch

File 15244_doctest_flush.patch, 1.3 KB (added by jdemeyer, 8 years ago)
  • sage/doctest/control.py

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1382956716 -3600
    # Node ID 28ab507cd354f2d76c27139bd13fc20c5718ee88
    # Parent  61129ab7d17c128243f663d23502b9cdccab6a30
    Flush buffers in log()
    
    diff --git a/sage/doctest/control.py b/sage/doctest/control.py
    a b  
    347347            sage: DC.log("hello world")
    348348            hello world
    349349            sage: DC.logfile.close()
    350             sage: with open(DD.logfile) as logger: print logger.read()
     350            sage: print open(DD.logfile).read()
     351            hello world
     352
     353        Check that no duplicate logs appear, even when forking (:trac:`15244`)::
     354
     355            sage: DD = DocTestDefaults(logfile=tmp_filename())
     356            sage: DC = DocTestController(DD, [])
     357            sage: DC.log("hello world")
     358            hello world
     359            sage: if os.fork() == 0:
     360            ....:     DC.logfile.close()
     361            ....:     os._exit(0)
     362            sage: DC.logfile.close()
     363            sage: print open(DD.logfile).read()
    351364            hello world
    352365
    353366        """
    354367        s += end
    355368        if self.logfile is not None:
    356369            self.logfile.write(s)
     370            self.logfile.flush()
    357371        sys.stdout.write(s)
     372        sys.stdout.flush()
    358373
    359374    def test_safe_directory(self, dir=None):
    360375        """