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

Evolving doctests for changing output format

Hi,

I've got a number of doctests which rely on a certain output format,
and since I wrote the tests I've changed the output format. Now,
almost all the tests fail.

What I'd like is if I could get doctest to take my tests, and
substitute the obtained output for the provided output. Then, I could
in this case just replace the doctest file with the generated file, or
in general be able to run it through a file comparison tool so I could
examine the differences.

If it's not clear from the above, here's an example, assuming for the
sake of simplicity that Python somehow changed its default output base
between runs.

INPUT:
>10 + 10
20

OUTPUT:
>10 + 10
0x14

Is it possible to use doctest in such a "run-only" mode, or script the
above using its API? I read the documentation several times but just
got further confused (sorry!).

Thanks,

--Nicholas

Jan 9 '07 #1
1 1263
[nr****@gmail.com]
What I'd like is if I could get doctest to take my tests, and
substitute the obtained output for the provided output.
There's currently no support for auto-updating doctests. I think it
would make for a good feature request.

In the meantime, it may not be difficult to roll your own by converting
the current expected/got output into a diff and then applying it to the
original source code being doctested.

Start with a regular expression like this:

pat = re.compile(r'''
File.+,\sline\s(\d+),.+\n
Failed\sexample:\n((?:.*?\n)*?)
Expected:\n((?:.*?\n)*?)
Got:\n((?:.*?\n)*?)
\*{70,70}
''', (re.MULTILINE | re.VERBOSE))

Then, build-up a diff in your preferred format. Perhaps like this:

cumadj = 0
for lineno, example, expected, got in pat.findall(source):

len_example, len_expected, len_got = example.count('\n'),
expected.count('\n') , got.count('\n')
start = int(lineno) + len_example
lead = str(start)
if len_expected !=1:
lead += ',' + str(start+len_expected-1)
lead += 'c' + str(start + cumadj)
if len_got != 1:
lead += ',' + str(start+cumadj+len_got-1)

print lead
for old in expected.splitlines(False):
print '<' + old
print '---'
for new in got.splitlines(False):
print '>' + new

cumadj += len_got - len_expected

Raymond

Jan 11 '07 #2

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

Similar topics

2
by: Paolo Pignatelli | last post by:
I am trying to get an output/file like this (below) in an XML file (MyXmlFile.xml) (which I will use for a slide show) -- <gallery timer="3" order="sequential" fadetime="2" looping="yes"...
1
by: Colin Graham | last post by:
I have a problem regarding the output of data from a access xp database. Basically we have data in the following format in a table: person1 result1 result2 person1 result1 result2...
6
by: Ioannis Demetriades | last post by:
Hi, I need to change the printer's font to "control" -a printer font, and then send a sequence of characters to the printer. My problem is that I cannot change the printer's font. Can this be...
0
by: Joel Moore | last post by:
We have an app that currently uses SOAP for a data file format. It works well enuogh but I would prefer an XML format that's a little friendlier to the human eye. I had started looking at...
2
by: bearophileHUGS | last post by:
Recently I have posted this same question on it.comp.lang.python, maybe there aren't solutions, but I'd like to know what you think. Can doctests be added to nested functions too? (This can be...
1
by: sam | last post by:
dear all, i've just finished a program which sets up an initial population consisting of four different phenotypes, allows them to evolve over time and graphs the output at the end, displaying...
2
by: Brian van den Broek | last post by:
Hi all, I have a module of classes for getting input from the user that satisfies various constraints. For instance, one class is created with a menu of option, presents them to the user, and...
5
mgpsivan
by: mgpsivan | last post by:
Hi, i have form in Asp.net(2003) in that i've to change the format of the date by the following statement Format(Date.Today, "dd/mm/yyyy") but when i give this code the month part displays as...
4
by: wildman | last post by:
RE: Replacing Text without changing case?? This code works great, but case has to be exact. Research.Text = Research.Text.Replace(textboxSearch.Text, "<b>" + textboxSearch.Text + "</b>") ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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...

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.