homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jedie
Recipients jedie
Date 2008年07月10日.13:59:50
SpamBayes Score 0.0015510931
Marked as misclassified No
Message-id <1215698394.53.0.241298622742.issue3332@psf.upfronthosting.co.za>
In-reply-to
Content
The doctest doesn't work good, if a function returns a dict.
Here a simple example:
def test(d):
 """
 This works:
 >>> test({"A":1, "B":2, "C":3})
 {'A': 1, 'C': 3, 'B': 2}
 
 This failed, because of different dict sort:
 >>> test({"A":1, "B":2, "C":3})
 {'A': 1, 'B': 2, 'C': 3}
 
 The Error messages:
 Failed example:
 test({"A":1, "B":2, "C":3})
 Expected:
 {'A': 1, 'B': 2, 'C': 3}
 Got:
 {'A': 1, 'C': 3, 'B': 2}
 """
 return d
The problem is IMHO that doctest.py [1] OutputChecker.check_output()
does compare the repr() of the dict and not the real dict as data.
One solution: Use eval() to convert the string repr. of the dict into
the real dict:
...
 #-----<add>-----
 try:
 if eval(got) == eval(want):
 return True
 except:
 pass #*pfeif* kein schoener stil, aber pragmatisch
 #-----</add>----
 # We didn't find any match; return false.
 return False
German discuss can be found here:
http://www.python-forum.de/topic-15321.html
[1] http://svn.python.org/view/python/trunk/Lib/doctest.py?view=markup 
History
Date User Action Args
2008年07月10日 13:59:55jediesetspambayes_score: 0.00155109 -> 0.0015510931
recipients: + jedie
2008年07月10日 13:59:54jediesetspambayes_score: 0.00155109 -> 0.00155109
messageid: <1215698394.53.0.241298622742.issue3332@psf.upfronthosting.co.za>
2008年07月10日 13:59:53jedielinkissue3332 messages
2008年07月10日 13:59:52jediecreate

AltStyle によって変換されたページ (->オリジナル) /