Re: Dealing with dicts in doctest

2018-07-06 Thread Serhiy Storchaka
05.07.18 20:57, Steven D'Aprano пише: I think that's really clever. Is it too clever? How do you deal with dicts in doctests? There was a proposition for adding a doctest option for order-insensitive matching (like NORMALIZE_WHITESPACE and ELLIPSIS). But it was rejected because there is a sim

Re: Dealing with dicts in doctest

2018-07-05 Thread Peter Otten
Steven D'Aprano wrote: > On Fri, 06 Jul 2018 09:31:50 +1000, Cameron Simpson wrote: > >> On 05Jul2018 17:57, Steven D'Aprano >> wrote: >>>I have a function which returns a dict, and I want to use doctest to >>>ensure the documentation is correct. So I write a bunch of doctests: >>> >>>def func(a

Re: Dealing with dicts in doctest

2018-07-05 Thread Cameron Simpson
On 06Jul2018 01:43, Steven D'Aprano wrote: On Fri, 06 Jul 2018 09:31:50 +1000, Cameron Simpson wrote: On 05Jul2018 17:57, Steven D'Aprano wrote: I have three ways of dealing with this. Which do you prefer? Option 4: >>> func(1) == {'a': 1, 'b': 2, 'c': 3} True Alas, in reality f

Re: Dealing with dicts in doctest

2018-07-05 Thread Steven D'Aprano
On Thu, 05 Jul 2018 19:56:59 +0100, MRAB wrote: > What about sorting the items? > > def func(arg): > """blah blah blah > > >>> sorted(func(1).items()) > [('a', 1), ('b', 2), ('c', 3)] > """ Hmmm it still has the disadvantage of putting the emphasis on the sorted()

Re: Dealing with dicts in doctest

2018-07-05 Thread Steven D'Aprano
On Fri, 06 Jul 2018 09:31:50 +1000, Cameron Simpson wrote: > On 05Jul2018 17:57, Steven D'Aprano > wrote: >>I have a function which returns a dict, and I want to use doctest to >>ensure the documentation is correct. So I write a bunch of doctests: >> >>def func(arg): >>"""blah blah blah >> >>

Re: Dealing with dicts in doctest

2018-07-05 Thread Cameron Simpson
On 05Jul2018 17:57, Steven D'Aprano wrote: I have a function which returns a dict, and I want to use doctest to ensure the documentation is correct. So I write a bunch of doctests: def func(arg): """blah blah blah >>> func(1) {'a': 1, 'b': 2, 'c': 3} """ which is correct, *except

Re: Dealing with dicts in doctest

2018-07-05 Thread MRAB
On 2018-07-05 18:57, Steven D'Aprano wrote: I have a function which returns a dict, and I want to use doctest to ensure the documentation is correct. So I write a bunch of doctests: def func(arg): """blah blah blah >>> func(1) {'a': 1, 'b': 2, 'c': 3} """ which is correct,

Dealing with dicts in doctest

2018-07-05 Thread Steven D'Aprano
I have a function which returns a dict, and I want to use doctest to ensure the documentation is correct. So I write a bunch of doctests: def func(arg): """blah blah blah >>> func(1) {'a': 1, 'b': 2, 'c': 3} """ which is correct, *except* that dict keys have arbitrary order in t