It seems that the problem with any solution based on interpreting repr
(especially when nothing in know about the object) is that there are just
too many exceptions. Another approach might be to allow for a custom
compare function to be defined on doctest. E.g., in the module to be
tested:
import doctest
def _compare(got, expected):
return (sorted(eval(got)) == sorted(eval(expected)) or
doctest.compare(got, expected))
doctest.usercompare = _compare
The compare function would only need to deal with the idiosyncrasies of
types actually used in doctests in that module.
I don't know how practical this idea is in terms of implementation - from
my brief look through the code I think it should be fairly easy to slot
this into OutputChecker, but it was a very brief look!
David
On Fri, Mar 2, 2012 at 7:36 AM, Steven D'Aprano
Steven D'Aprano wrote:
This approach doesn't try to be too clever: it's a dumb, understandable
test which should fit in nicely with the other tests in doctest.OutputChecker.check_**output, perhaps something like this:
if optionflags & IGNORE_WORD_ORDER: if sorted(got.split()) == sorted(want.split()): return True
Ah, buggarit, too simple. I neglected to take into account the delimiters.
Getting this right is harder than I thought, particularly with nested sets/dicts.
Still, I reckon a directive is the right approach.
-- Steven
______________________________**_________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/**mailman/listinfo/python-ideashttp://mail.python.org/mailman/listinfo/python-ideas