
On Fri, Feb 17, 2012 at 10:08 PM, Steven D'Aprano <steve@pearwood.info> wrote:
Sure, I wish I had a good example off the top of my head, but perhaps this will convey the idea: class MyClass(): """Yadda Yadda: foo's bars.
def method1(self, other): """Method method method method. >>> m.method("foo") #Now we see m is already defined and useable. "bar" """ def meth2(self, other): """Method to foo all bars >>> m.method("bar") #would have to decide whether a fresh m is redefined with each innerscope doctest (if we want side-effects to carry across inner doctests). (END) This is a basic example, sorry it's rather crude. There's probably a better example. (Think establishing a network socket connection or something in the class' doc which is then used by all the methods, for example.)
I think this would be as simple as lifting the (string) output and doing an eval("{1,2,3}")=={3,2,1}, or (for security) using ast.literal_eval like Devin suggested.
I'd like a #3 as well: an abbreviated way to spell doctest directives, because they invariably push my tests well past the 80 character mark.
Hmm, seem like an alias could be defined easily enough, but I'll try to think about this when I have more time. mark

On 27 February 2012 19:27, Mark Janssen <dreamingforward@gmail.com> wrote:
How will that handle not-particularly-obscure code like this:
I don't think a *general* solution for unordered types is even possible because you can't parse arbitrary reprs. All the best, Michael
-- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html

On 27 February 2012 19:27, Mark Janssen <dreamingforward@gmail.com> wrote:
How will that handle not-particularly-obscure code like this:
I don't think a *general* solution for unordered types is even possible because you can't parse arbitrary reprs. All the best, Michael
-- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html
participants (2)
-
Mark Janssen
-
Michael Foord