On Mon, Jul 28, 2014 at 8:24 AM, Simon King <[email protected]> wrote:
> Hi Daniel,
>
> On 2014-07-28, Daniel Krenn <[email protected]> wrote:
>> Background: The output of a doctest is a dictionary; therefore there is
>> some uncertainty about the ordering of the entires. To have the
>> dict-output, but get tested as well, I want to do the following:
>>
>> sage: dict = {'a': 'b', 'x': 'y'}  # random
>> {'a': 'b', 'x': 'y'}
>> sage: sorted(dict.iteritems())  # hide doctest
>> [('a', 'b'), ('x', 'y')]
>
> I'd suggest to remove the random test and keep the non-random test in
> the doc. I see no reason for hiding it.
>
> Another possibility to deal with randomness of string representation:
> Explicitly assign the expected result to a variable in the doctest, and
> test for equality (here I assume that you have a function/method
> returning a dictionary. Hence, for testing method "bar" of instance
> "Foo", you could do
>
>   sage: D = {'a': 'b', 'x': 'y'}
>   sage: D == Foo.bar(pi)
>   True
>
> But testing against sorted(dict.iteritems()) is perfectly fine in the
> docs (of course it needs to be the case that the sorting of the
> dictionary keys is non-random).

I agree with Simon -- make the test non-random.

That said, there is a ready-made solution [1] for exactly the original
question, which I'm surprised that neither Volker nor Simon mentioned
[1]:

    "A TESTS block (optional), formatted just like EXAMPLES, for
additional tests which should be part of the regression suite but are
not illustrative enough to merit placement in EXAMPLES."

Basically, you put

    TESTS::

         sage: 2+2
         4

in your code, and it gets doctested, but doesn't appear in the reference manual.

[1] 
http://www.sagemath.org/doc/developer/coding_basics.html#documentation-strings

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to