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

Running DocTest on Strings

Hi,
I have two strings - a docstring containing doctests and a code string
containing code to be tested with those doctests. I've been trying for
a day now to run the test without concatenating the two strings,
adding:

import doctest
doctest.testmod

to the bottom, writing it all to a file and executing it using popen().

There must be some way of doing this without writing to a temporary
file, any ideas?

thanks in advance,

johannes Woolard

Jun 29 '06 #1
3 1334

notanotheridiot wrote:
Hi,
I have two strings - a docstring containing doctests and a code string
containing code to be tested with those doctests. I've been trying for
a day now to run the test without concatenating the two strings,
adding:

import doctest
doctest.testmod

to the bottom, writing it all to a file and executing it using popen().

There must be some way of doing this without writing to a temporary
file, any ideas?

thanks in advance,

johannes Woolard

Create the concatenated string then exec it?

- Pad.

Jun 29 '06 #2

Paddy wrote:
notanotheridiot wrote:
Hi,
I have two strings - a docstring containing doctests and a code string
containing code to be tested with those doctests. I've been trying for
a day now to run the test without concatenating the two strings,
adding:

import doctest
doctest.testmod

to the bottom, writing it all to a file and executing it using popen().

There must be some way of doing this without writing to a temporary
file, any ideas?

thanks in advance,

johannes Woolard Create the concatenated string then exec it?


I know from experience that this approach does not work. When you do
that, the entire module from which it is run turns out to be scanned
for doctests - not only the string being executed by exec. However, I
understand that Johannes found a solution.

André

- Pad.


Jun 29 '06 #3

André wrote:
Paddy wrote:
notanotheridiot wrote:
Hi,
I have two strings - a docstring containing doctests and a code string
containing code to be tested with those doctests. I've been trying for
a day now to run the test without concatenating the two strings,
adding:

import doctest
doctest.testmod

to the bottom, writing it all to a file and executing it using popen().

There must be some way of doing this without writing to a temporary
file, any ideas?

thanks in advance,

johannes Woolard

Create the concatenated string then exec it?


I know from experience that this approach does not work. When you do
that, the entire module from which it is run turns out to be scanned
for doctests - not only the string being executed by exec. However, I
understand that Johannes found a solution.

André

- Pad.


Got it, I've blogged about it here:
http://pytute.blogspot.com/2006/06/s...ary-files.html
Basically the trick is to pass the docstring ino the exec environment
as a variable and use the advanced doctest api to get a doctest.

Johannes

Jun 30 '06 #4

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: Edward K. Ream | last post by:
Hi, I am trying to run the following docstring using docutils.DocTestSuite: """ >>> s = "a\n \t\n\t\t \t\nb" etc... """ However, docutils complains about "inconsistent leading...
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)...
1
by: Thomas Heller | last post by:
I'm trying to integrate some doctest tests with unittest. The tests must be exposed as one or more subclasses of unittest.TestCase, so I'm collecting them with a call to doctest.DocTestSuite(),...
3
by: Michele Simionato | last post by:
I am getting trouble with nested triple quoted strings in doctest. For instance $ cat x.py """ >>> dummy = ''' something here ''' """
1
by: Runsun Pan | last post by:
I intend to use the doctect heavily. For this I am thinking of coding a class that comes with a built-in doctest functionality. I'd like to seek for input before I start. The idea is to have a...
2
by: Paddy | last post by:
Hi, Anyone know of something that can turn an interactive bash or tcsh session into a test the way doctest does? - Cheers, Paddy.
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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...
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...

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.