473,804 Members | 3,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1276
[nr****@gmail.co m]
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(sou rce):

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_e xpected-1)
lead += 'c' + str(start + cumadj)
if len_got != 1:
lead += ',' + str(start+cumad j+len_got-1)

print lead
for old in expected.splitl ines(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
2511
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" xpos="0" ypos="0"> <image path="images2/Test1.jpg" />
1
1689
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 person1 result1 result2 person2 result1 result2 person2 result1 result2
6
10504
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 done without API calls? Thanks Ioannis
0
1202
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 converting over to using the XmlSerializer but quickly ran into a problem. One thing that is nice about the SOAP formatter's deserialization is that it can easily deal with different versions of the data file. The class we're serializing includes a...
2
1689
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 useful to me, I use nested function when I don't have attributes that I have to remember, but I want to split the logic in some subparts anyway). Example: def foo(): """
1
1378
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 what is in effect the evolutionary steady state for the system. i'm no authority on evolutionary game theory (to put it mildly), but there is a certain amount of interesting emergent behaviour if you put the initial parameters in in a certain...
2
1968
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 rejects any input other than a menu option; another ensures that the user's input is interpretable as an integer between specified bounds, etc. It is a module I wrote up when in the early stages of learning Python. It's a bit ugly :-) So, I am...
5
4221
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 00 i.e i get the output as the folowing for eg: "18/00/2007" can any one help me in changing the format... Thanks in Advance..... Sivan.G.....
4
1863
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>") I found some c# code, but I can't make it work in vb.net:
0
9707
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9585
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10586
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6856
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.