A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-February/012851.html below:

doctest and Python 2.1 (was RE: [Python-Dev] Unit testing (again))

doctest and Python 2.1 (was RE: [Python-Dev] Unit testing (again)) doctest and Python 2.1 (was RE: [Python-Dev] Unit testing (again))Guido van Rossum guido@digicool.com
Tue, 13 Feb 2001 08:55:29 -0500
> [a satisfied customer reports:]
> I like doctest very much.  I'm using it for our company projects a lot.
> This is a very valuable tool.
> 
> However Pings latest changes, which turned 'foobar\012' into 'foobar\n'
> and '\377\376\345' into '\xff\xfe\xe5' has broken some of the doctests
> in our software.  
> 
> Since we have to keep our code compatible with Python 1.5.2 for at
> least one, two or may be three more years, it isn't obvious to me
> how to fix this.

This is a general problem with doctest, and a general solution
exists.  It's the same when you have a function that returns a
dictionary: you can't include the dictionary in the output, because
the key order isn't guaranteed.  So, instead of writing your example
like this:

    >>> foo()
    {"Hermione": "hippogryph", "Harry": "broomstick"}
    >>>

you write it like this:

    >>> foo() == {"Hermione": "hippogryph", "Harry": "broomstick"}
    1
    >>>

I'll leave it as an exercise to the reader to apply this to string
literals.

--Guido van Rossum (home page: http://www.python.org/~guido/)



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4