Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9840db83
Commit
9840db83
authored
Oct 02, 2014
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#8473: make doctest.testfile use universal newline mode.
parent
52d0a1b1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
1 deletion
+30
-1
Lib/doctest.py
Lib/doctest.py
+1
-1
Lib/test/test_doctest.py
Lib/test/test_doctest.py
+26
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/doctest.py
View file @
9840db83
...
...
@@ -216,7 +216,7 @@ def _load_testfile(filename, package, module_relative):
# 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
with
open
(
filename
)
as
f
:
with
open
(
filename
,
'U'
)
as
f
:
return
f
.
read
(),
filename
# Use sys.stdout encoding for ouput.
...
...
Lib/test/test_doctest.py
View file @
9840db83
...
...
@@ -2569,6 +2569,32 @@ bothering with the current sys.stdout encoding.
>>> 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()
>>> open(fn, 'w').write('Test:\r\n\r\n >>> x = 1 + 1\r\n\r\nDone.\r\n')
>>> doctest.testfile(fn, False)
TestResults(failed=0, attempted=1)
>>> os.remove(fn)
And now *nix line endings:
>>> fn = tempfile.mktemp()
>>> open(fn, 'w').write('Test:\n\n >>> x = 1 + 1\n\nDone.\n')
>>> doctest.testfile(fn, False)
TestResults(failed=0, attempted=1)
>>> os.remove(fn)
"""
# 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.
...
...
Misc/NEWS
View file @
9840db83
...
...
@@ -31,6 +31,9 @@ Core and Builtins
Library
-------
-
Issue
#
8473
:
doctest
.
testfile
now
uses
universal
newline
mode
to
read
the
test
file
.
-
Issue
#
20076
:
Added
non
derived
UTF
-
8
aliases
to
locale
aliases
table
.
-
Issue
#
20079
:
Added
locales
supported
in
glibc
2.18
to
locale
alias
table
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment