Index: Lib/doctest.py =================================================================== --- Lib/doctest.py (revision 80264) +++ Lib/doctest.py (working copy) @@ -216,7 +216,7 @@ # get_data() opens files as 'rb', so one must do the equivalent # conversion as universal newlines would do. return file_contents.replace(os.linesep, '\n'), filename - return open(filename).read(), filename + return open(filename, 'U').read(), filename # Use sys.stdout encoding for ouput. _encoding = getattr(sys.__stdout__, 'encoding', None) or 'utf-8' Index: Lib/test/test_doctest.py =================================================================== --- Lib/test/test_doctest.py (revision 80264) +++ Lib/test/test_doctest.py (working copy) @@ -2329,6 +2329,21 @@ >>> sys.argv = save_argv """ +def test_lineendings(): r""" +Due to the way releases are made on different platforms, we sometimes test +files on a *nix system with Windows file endings. Unfortunately, that leaves +some of the test files broken: + + >>> import tempfile + >>> fn = tempfile.mktemp() + >>> open(fn, 'w').write('Test:\r\n\r\n >>> x = 1 + 1\r\n\r\nDone.\r\n') + +Let's now run it as a doctest: + + >>> doctest.testfile(fn, False) + TestResults(failed=0, attempted=1) +""" + # old_test1, ... used to live in doctest.py, but cluttered it. Note # that these use the deprecated doctest.Tester, so should go away (or # be rewritten) someday.