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

Few doctest notes

doctest module is quite useful; and I've also tried the simpler docex:
http://aima.cs.berkeley.edu/python/docex.html
http://aima.cs.berkeley.edu/python/docex.py
(docex isn't perfect, there are problems with functions without a
return, and with functions with prints inside, but it can be useful,
easy to use, and it produces very short docs.)
Looking at docex I think doctest usage can be simplified a little, and
the doctest output can be shortened, because this can become a bit
long:
Running example.__doc__
0 of 0 examples failed in example.__doc__
Running example._test.__doc__
0 of 0 examples failed in example._test.__doc__
Running example. ...
From doctest Library Reference:
For example, when printing a dict, Python doesn't guarantee that the key-value pairs will be printed in any particular order, so a test
like<
docex solves similar problems not using a string comparison, but
executing the output too, and then with a comparison of the resulting
objects (but in some special cases the output cannot be executed, like
where there is a Traceback, or ... or ==>)
I think "..." can also be used at the end of very long output lines,
this time a string comparison is used because such objects cannot be
executed.
docex uses a ==> syntax, like:
Ex: sqrt(4) ==> 2
This can be useful in doctest too for simple functions, to make
shorter docs, but it can also be triky to implement correctly.
From doctest Library Reference:Expected output cannot contain an all-whitespace line, since such a

line is taken to signal the end of expected output.<
Then maybe to distinguish such cases it can added a "tag" at the start
of every output line, like "< " or "<<< ". (but such symbols probably
have to be added by hand...). Example:

This is a useless comment:
foo(2) <<< 2
<<< 2
This is a second useless comment: foo(3) <<< 3
<<< 3
<<< 3
foo(0) prints a number with thousands of digits: foo(0) <<< 555126219729759572912...
An error: foo(-1)

<<< AssertionError: foo(n): n cannot be negative.

Hugs,
Bearophile
Jul 18 '05 #1
0 1010

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

Similar topics

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...
2
by: Michele Simionato | last post by:
Some time ago I hacked a custom solution to run doctests on text files containing documentation. The solution involved this kind of game: tester=doctest.Tester(globs={},verbose=1)...
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...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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...

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.