473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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:

http://svn.python.org/view?rev=59082&view=rev

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 1515

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Pierre Rouleau | last post by:
I have a problem writing self-testable modules using doctest when these modules have internationalized strings using gettext _('...'). - The main module of an application (say app.py) calls...
2
by: Alan G Isaac | last post by:
> python doctest.py -v Running doctest.__doc__ Trying: .remove(42) Expecting: Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: list.remove(x): x not in list ok...
5
by: Michele Simionato | last post by:
I am getting a strange error with this script: $ cat doctest-threads.py """ >>> import time, threading >>> def example(): .... thread.out = .... while thread.running: .... ...
24
by: john_sips_tea | last post by:
For writing testcode, it looks like there's three ways that it's typically done: (1). using the doctest module, (2). using the unittest module (i.e. "pyunit"), or else (3). just putting an...
0
by: Eric Mahurin | last post by:
Noob here. Just got into python a little over a week ago... One of the (unique?) things I really like about python is the concept of doctesting. But, now I want more! Here's what I'd like to...
0
by: ChrisMiddle10 | last post by:
Hey All, I suppose the subject says it all. I'm new to the IHttpHandler interface. I'm just trying to figure out how long - by default - an instance of an HttpHandler is kept alive when the...
6
by: jaishu | last post by:
Hi, Thanks buddies for all ur help for the threads that i posted earlier!! Again i have some questions.. The form that i created is one that shows records that are not in a particular table ,...
4
by: petr.jakes.tpc | last post by:
Hi, inspired by the article written by Tarek Ziade in the February 07 issue of the "Linux +" magazine I am experimenting with the doctest module. I have two files, "displeje_pokus.py" and...
0
by: dj | last post by:
Hello, I have just started working with minimock in doctest. I want to create a mock pyodbc object which returns a string value when the method execute is called. Here is my doctest: ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.