cpython: 4a5f79ca8ef0 (original) (raw)
Mercurial > cpython
changeset 92763:4a5f79ca8ef0 2.7
#8473: make doctest.testfile use universal newline mode. [#8473]
R David Murray rdmurray@bitdance.com | |
---|---|
date | Thu, 02 Oct 2014 21:53:50 -0400 |
parents | a53f2cf4b556 |
children | 18c40112122b |
files | Lib/doctest.py Lib/test/test_doctest.py Misc/NEWS |
diffstat | 3 files changed, 30 insertions(+), 1 deletions(-)[+] [-] Lib/doctest.py 2 Lib/test/test_doctest.py 26 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -216,7 +216,7 @@ def _load_testfile(filename, package, mo # 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
Use sys.stdout encoding for ouput.
--- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -2569,6 +2569,32 @@ bothering with the current sys.stdout en >>> sys.argv = save_argv """ +def test_lineendings(): r""" +*nix systems use \n line endings, while Windows systems use \r\n. Python +handles this using universal newline mode for reading files. Let's make +sure doctest does so (issue 8473) by creating temporary test files using each +of the two line disciplines. One of the two will be the "wrong" one for the +platform the test is run on. + +Windows line endings first: +
open(fn, 'w').write('Test:\r\n\r\n >>> x = 1 + 1\r\n\r\nDone.\r\n')
- TestResults(failed=0, attempted=1)
+ +And now *nix line endings: +
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.
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -31,6 +31,9 @@ Core and Builtins Library ------- +- Issue #8473: doctest.testfile now uses universal newline mode to read