diff options
author | R David Murray <rdmurray@bitdance.com> | 2014-10-03 02:43:51 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2014-10-03 02:43:51 (GMT) |
commit | f355943002b0bf957d3481e7699dc626997ed901 (patch) | |
tree | fb12135dcfee873e6fa14b0441b98b1494cef055 /Lib/test/test_doctest.py | |
parent | 34b9c24b3589e40fe63ffdcf34bef2a4b5dae366 (diff) | |
parent | b48cb29ac4b9ac6b7e2a835c70c4fdd1b5333bcf (diff) | |
download | cpython-f355943002b0bf957d3481e7699dc626997ed901.zip cpython-f355943002b0bf957d3481e7699dc626997ed901.tar.gz cpython-f355943002b0bf957d3481e7699dc626997ed901.tar.bz2 |
Merge: #8473: Add tests that doctest uses universal newlines in testfile.
Diffstat (limited to 'Lib/test/test_doctest.py')
-rw-r--r-- | Lib/test/test_doctest.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index c62e7ca..4b8d0d2 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -2616,6 +2616,36 @@ Test the verbose output: >>> 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: + + >>> import tempfile, os + >>> fn = tempfile.mktemp() + >>> with open(fn, 'w') as f: + ... f.write('Test:\r\n\r\n >>> x = 1 + 1\r\n\r\nDone.\r\n') + 35 + >>> doctest.testfile(fn, False) + TestResults(failed=0, attempted=1) + >>> os.remove(fn) + +And now *nix line endings: + + >>> fn = tempfile.mktemp() + >>> with open(fn, 'w') as f: + ... f.write('Test:\n\n >>> x = 1 + 1\n\nDone.\n') + 30 + >>> doctest.testfile(fn, False) + TestResults(failed=0, attempted=1) + >>> os.remove(fn) + +""" + def test_testmod(): r""" Tests for the testmod function. More might be useful, but for now we're just testing the case raised by Issue 6195, where trying to doctest a C module would |