eval(repr(x)) == x

Oren Tirosh oren-py-l at hishome.net
Sun Jan 27 17:00:24 CET 2002


On Sun, Jan 27, 2002 at 04:25:05PM +0100, Alex Martelli wrote:
> > A unit test often consists of a sequence of method calls and their
> > expected results.  Writing these expected results is a pain in the a**. A
> > relatively easy way to generate the expected result is to construct it in
> > an interactive session, print it and then select and paste to the test
> > code. But this depends on eval(repr(x))==x.
> 
> I still can't see it.  I generally use doctest for unit tests, and it does 

Functions, classes and types are first-class objects in Python.  I tend to
use them as such: pass them around, use them as members of containers,
dictionary keys, etc.  It bothers me that for the repr function they are 
second-class citizens.  Their repr is some kind of 'tourist information'
instead of valid expressions like the repr of numbers, sequences, 
dictionaries, etc.

I guess your programming style is different so it doesn't bother you.

> I still can't see it.  I generally use doctest for unit tests, and it does 
> lend itself to working that way (just cutting and pasting an interactive
> session) without dependency on eval and repr being inverse.  

Not everyone uses doctest.  Some people write dedicated test code.

	Oren




More information about the Python-list mailing list