473,396 Members | 1,760 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,396 software developers and data experts.

doctest fails to NORMALIZE_WHITESPACE ?

Hello, I'm a python-list newbie. I've got a question about doctest; perhaps
a bug report.

I really like doctest, but sometimes doctest gives a failure when the output
looks absolutely fine to me -- indeed, even after I have gone to considerable
effort to make my documentation match the output perfectly.

http://www.aims.ac.za/~mackay/python...an/Huffman3.py

The above file is an example.

It's self-contained, so you can plop it into emacs and hit C-cC-c to run the
doctests. One of them fails.
The piece of source code concerned is here:
c = []; \

c.append(node(0.5,1,'a')); \
c.append(node(0.25,2,'b')); \
c.append(node(0.125,3,'c')); \
c.append(node(0.125,4,'d')); \
iterate(c) ; reportcode(c) # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
#Symbol Count Codeword
a (0.5) 1
b (0.25) 01
c (0.12) 000
d (0.12) 001
"""

And the output is:

Failed example:
c = []; c.append(node(0.5,1,'a')); c.append(node(0.25,2,'b')); c.append(node(0.125,3,'c')); c.append(node(0.125,4,'d')); iterate(c) ; reportcode(c) # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
Expected:
#Symbol Count Codeword
a (0.5) 1
b (0.25) 01
c (0.12) 000
d (0.12) 001
Got:
<__main__.internalnode instance at 0xb7aee76c>
#Symbol Count Codeword
a (0.5) 1
b (0.25) 01
c (0.12) 000
d (0.12) 001

===================================

I have tried numerous tweaks, and am at a loss. I am wondering whether there
is some big in doctest involving the "#" character in the output.
Or maybe I made some silly mistake.

Any advice appreciated!

Many thanks again to the authors of doctest, it gives a great feeling
to write code in the way that doctest encourages. :-)

David

--
David J.C. MacKay ma****@aims.ac.za 787 9336
http://www.aims.ac.za/~mackay/
Dec 17 '05 #1
1 1904
David MacKay wrote:
I really like doctest, but sometimes doctest gives a failure when the
output looks absolutely fine to me -- indeed, even after I have gone to
considerable effort to make my documentation match the output perfectly. The piece of source code concerned is here:
>>> c = []; \
c.append(node(0.5,1,'a')); \
c.append(node(0.25,2,'b')); \
c.append(node(0.125,3,'c')); \
c.append(node(0.125,4,'d')); \
iterate(c) ; reportcode(c) # doctest:


You have to suppress the return value of iterate()

dummy = iterate(c); reportcode(c)
+NORMALIZE_WHITESPACE, +ELLIPSIS
#Symbol Count Codeword
a (0.5) 1
b (0.25) 01
c (0.12) 000
d (0.12) 001
"""
And the output is:

Expected:
#Symbol Count Codeword
a (0.5) 1 Got:
<__main__.internalnode instance at 0xb7aee76c>


This is the result of iterate(c). The interactive interpreter ignores None
return values but prints the repr() of everything else. doctest emulates
that behaviour.

Peter
Dec 17 '05 #2

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...
3
by: John J Lee | last post by:
Is it possible to get doctest-mode to work with mmm-mode and python-mode nicely so that docstrings containing doctests are editable in doctest-mode? In my utter e-lisp ignorance, I tried this: ...
1
by: Michael Tobis | last post by:
It appears that doctest does not work straightforwardly within iPython. I would like to be able to use doctest within a file conditionally, so that I can develop it within ipython and test it...
0
by: Leo | last post by:
Could someone please spare a .i file with an example doctest that works? I tried as follows and it fails: 1) I have an osi.i file that generates osi.py and _osi.so. At the very end I added:...
0
by: davidlmontgomery | last post by:
I'm trying to use both nosetests and doctest with the tests pulled out into a separate file. My problem is that it seems that I need to use different import statements depending on from where I...
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...
12
by: thomas.guest | last post by:
I'm not making progress with the following and would appreciate any help. Here's an interpreted Python session. .... Traceback (most recent call last): File "<stdin>", line 1, in <module>...
6
by: Bzyczek | last post by:
Hello, I have problems with running doctests if I use czech national characters in UTF-8 encoding. I have Python script, which begin with encoding definition: # -*- coding: utf-8 -*- I...
3
by: Steven D'Aprano | last post by:
I have a function in my module: def selftest(verbose=False): import doctest doctest.testmod(verbose=verbose) When I run it, it fails to find any of my doc tests, including the tests in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.