471,338 Members | 1,196 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

doctest.testfile universal newline -- only when module_relative=True?

When running a doctest text file with doctest.testfile, I noticed that
universal newline support did not appear to work when module_relative
is False. My text file was saved on a Windows machine but I was
testing it on a Linux machine, hence the newline mismatch (doctest
would throw a SyntaxError for every incorrect newline).

I looked at the svn trunk history for doctest.py and found the
following patch:


This patch corrected for the lack of universal newline support in
package.__loader__ .get_data(), but that only applies when
module_relative is True. If it is False, the _load_testfile function
just calls open(filename) with the default mode of 'r'. It seems to
me that, for consistent behavior when module_relative is False, the
mode should be 'rU'.

Here's a diff against the current svn trunk that corrects this' I've
tested it on my machine and it runs correctly:
--- doctest_trunk.py 2008-01-10 18:59:15.000000000 -0500
+++ doctest_modified.py 2008-01-10 18:59:15.000000000 -0500
@@ -213,7 +213,8 @@
# 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
+ # Here we just need to ensure universal newline mode when opening
+ return open(filename, 'rU').read(), filename

def _indent(s, indent=4):

Has anyone else noticed this behavior? If it seems worthwhile, I can
submit this to the patch tracker. (It would also seem that there should
be a corresponding patch to test_doctest to include this case--that
should be easy enough for me to generate from what I have already.)

Peter Donis
Jan 11 '08 #1
0 1398

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Pierre Rouleau | last post: by
2 posts views Thread by Alan G Isaac | last post: by
5 posts views Thread by Michele Simionato | last post: by
24 posts views Thread by john_sips_tea | last post: by
reply views Thread by Eric Mahurin | last post: by
4 posts views Thread by petr.jakes.tpc | last post: by
reply views Thread by dj | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.