Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31726

Re: Add if...else... switch to doctest?

From Duncan Booth <duncan.booth@invalid.invalid>
Newsgroups comp.lang.python
Subject Re: Add if...else... switch to doctest?
Date 2012-10-19 09:27 +0000
Message-ID <XnsA0F169B9B360Cduncanbooth@127.0.0.1> (permalink)
References <c500a76c-3e6b-4dfc-97ca-8b24f0628620@googlegroups.com>

Show all headers | View raw


David <zhushenli@gmail.com> wrote:

> Hello, how to add if...else... switch to doctest?
> E.g. function outputs different value when global_var change.
> 
> """
> if (global_var == True):
>>>> function()
> [1,2]
> else:
>>>> function()
> [1,2,3]
> """
> 
> Thank you very much.

One other case the other replies don't seem to have covered:

If the global variable is determined by the environment, outside your 
control, and by implication doesn't change while your program is running, 
then you should use two separate functions:

if sys.platform=='win32':
    def function():
        """
        >>> function()
        [1, 2]
        """
        return [1, 2]

else:
    def function():
        """
        >>> function()
        [1, 2, 3]
        """
        return [1, 2, 3]
    
and if it's more than one such function use separate modules.

-- 
Duncan Booth http://kupuguy.blogspot.com

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Add if...else...  switch to doctest? David <zhushenli@gmail.com> - 2012-10-18 17:08 -0700
  Re: Add if...else...  switch to doctest? Ben Finney <ben+python@benfinney.id.au> - 2012-10-19 12:29 +1100
  Re: Add if...else...  switch to doctest? Terry Reedy <tjreedy@udel.edu> - 2012-10-18 21:31 -0400
  Re: Add if...else...  switch to doctest? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-19 01:57 +0000
  Re: Add if...else...  switch to doctest? Duncan Booth <duncan.booth@invalid.invalid> - 2012-10-19 09:27 +0000

csiph-web