zope.testing.doctestunit pprint and deprecation warnings
Hi there, zope.testing.doctestunit emits a deprecation warning. It also defines a function pprint. How does one use pprint without getting a deprecation warning? It seems impossible now, and an equivalent pprint doesn't appear to be in the standard library doctest.. Regards, Martijn
On Wed, Dec 30, 2009 at 6:38 PM, Martijn Faassen <faassen@startifact.com> wrote:
zope.testing.doctestunit emits a deprecation warning. It also defines a function pprint. How does one use pprint without getting a deprecation warning? It seems impossible now, and an equivalent pprint doesn't appear to be in the standard library doctest..
When I recently converted some tests, I replaced that pprint function with the one from the standard library: from pprint import pprint There weren't any differences in the output, as far as I could tell. Hanno
Hanno Schlichting wrote:
On Wed, Dec 30, 2009 at 6:38 PM, Martijn Faassen<faassen@startifact.com> wrote:
zope.testing.doctestunit emits a deprecation warning. It also defines a function pprint. How does one use pprint without getting a deprecation warning? It seems impossible now, and an equivalent pprint doesn't appear to be in the standard library doctest..
When I recently converted some tests, I replaced that pprint function with the one from the standard library:
from pprint import pprint
There weren't any differences in the output, as far as I could tell.
Not sure if this is related, but one thing I found which bit me recently is that prior to Python 2.5, pprint did not sort dict keys in the output. That means that a test like this:
pprint(foo) {'omega': 1, 'alpha': 2}
will pass on 2.4 and fail on 2.5/2.6; to fix it for 2.5/2.6 you do:
pprint(foo) {'alpha': 2, 'omega': 1}
but now it fails on 2.4. The only way I could find it make it work reliably was to not rely on dicts at all, but do:
pprint(sorted(foo.items()) [('alpha', 2), ('omega', 1)]
Which works the same on both. I don't know if the zope.doctest pprint function was meant to fix this, but maybe it did? Martin -- Author of `Professional Plone Development`, a book for developers who want to work with Plone. See http://martinaspeli.net/plone-book
On Thu, Dec 31, 2009 at 02:21, Martin Aspeli <optilude+lists@gmail.com> wrote:
Hanno Schlichting wrote:
On Wed, Dec 30, 2009 at 6:38 PM, Martijn Faassen<faassen@startifact.com> wrote:
zope.testing.doctestunit emits a deprecation warning. It also defines a function pprint. How does one use pprint without getting a deprecation warning? It seems impossible now, and an equivalent pprint doesn't appear to be in the standard library doctest..
When I recently converted some tests, I replaced that pprint function with the one from the standard library:
from pprint import pprint
There weren't any differences in the output, as far as I could tell.
Not sure if this is related, but one thing I found which bit me recently is that prior to Python 2.5, pprint did not sort dict keys in the output. That means that a test like this:
>>> pprint(foo) {'omega': 1, 'alpha': 2}
will pass on 2.4 and fail on 2.5/2.6; to fix it for 2.5/2.6 you do:
>>> pprint(foo) {'alpha': 2, 'omega': 1}
but now it fails on 2.4. The only way I could find it make it work reliably was to not rely on dicts at all, but do:
>>> pprint(sorted(foo.items()) [('alpha', 2), ('omega', 1)]
Which works the same on both. I don't know if the zope.doctest pprint function was meant to fix this, but maybe it did?
That could be it. It seems silly to have a whole module just for that, but we can change the deprecation to just deprecate the BBB imports. -- Lennart Regebro: Python, Zope, Plone, Grok http://regebro.wordpress.com/ +33 661 58 14 64
Lennart Regebro wrote: [[doctestunit]
That could be it. It seems silly to have a whole module just for that, but we can change the deprecation to just deprecate the BBB imports.
+1 We can deprecate pprint then once we require Python 2.5 for all our packages.. Regards, Martijn
On Thu, Dec 31, 2009 at 09:21:12AM +0800, Martin Aspeli wrote:
Hanno Schlichting wrote:
On Wed, Dec 30, 2009 at 6:38 PM, Martijn Faassen<faassen@startifact.com> wrote:
zope.testing.doctestunit emits a deprecation warning. It also defines a function pprint. How does one use pprint without getting a deprecation warning? It seems impossible now, and an equivalent pprint doesn't appear to be in the standard library doctest..
When I recently converted some tests, I replaced that pprint function with the one from the standard library:
from pprint import pprint
There weren't any differences in the output, as far as I could tell.
Not sure if this is related, but one thing I found which bit me recently is that prior to Python 2.5, pprint did not sort dict keys in the output.
More precisely, it printed repr(dict) when the repr was shorter than the number of columns pprint was aiming for.
That means that a test like this:
pprint(foo) {'omega': 1, 'alpha': 2}
will pass on 2.4 and fail on 2.5/2.6; to fix it for 2.5/2.6 you do:
pprint(foo) {'alpha': 2, 'omega': 1}
but now it fails on 2.4.
Also, on 2.4 the dict order could change between 32 and 64-bit systems.
The only way I could find it make it work reliably was to not rely on dicts at all, but do:
pprint(sorted(foo.items()) [('alpha', 2), ('omega', 1)]
Which works the same on both. I don't know if the zope.doctest pprint function was meant to fix this, but maybe it did?
Yes, by changing the default wrapping width of pprint.pprint() to 1 column, so it would force dict sorting (and add a bunch of extra newlines) >>> zope.testing.doctestunit.pprint(foo) {'alpha': 2, 'omega': 1} The extra newlines often got a bit ridiculous: >>> foo = {'alpha': [2, 3, 4, 5], 'omega': [1]} >>> zope.testing.doctestunit.pprint(foo) {'alpha': [2, 3, 4, 5], 'omega': [1]} so I can't say I'll miss the doctestunit's pprint hack. Marius Gedminas -- http://pov.lt/ -- Zope 3 consulting and development
participants (5)
-
Hanno Schlichting -
Lennart Regebro -
Marius Gedminas -
Martijn Faassen -
Martin Aspeli