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


Groups > comp.lang.python > #89818

Re: Is this a good way to implement testing

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Is this a good way to implement testing
Date 2015-05-02 20:06 -0400
References <878ud6mx4y.fsf@Equus.decebal.nl>
Newsgroups comp.lang.python
Message-ID <mailman.38.1430611594.12865.python-list@python.org> (permalink)

Show all headers | View raw


On 5/2/2015 6:29 PM, Cecil Westerhof wrote:

> At the moment I define the test functionality in the following way:

Any automated testing is better than none.  For idlelib, I use unittest. 
  For an individual project with specialized needs, I use a custom test 
framework tuned to those needs.

>          else:
>              action = options[0][0]
>              if   action == '--all':
>                  do_all          = True
>              elif action == '--factorial':
>                  do_factorial    = True
>              elif action == '--fibonacci':
>                  do_fibonacci    = True
>              elif action == '--happy':
>                  do_happy        = True
>              elif action == '--lucky':
>                  do_lucky        = True
>              else:
>                  print >> sys.stderr, progname + ': Unhandled parameter ' + action
>                  sys.exit(1)

There is usually a way to factor out the duplication of repetitive code 
like this.  Often, a dict is somehow involved. I believe the following 
is equivalent to the above.

else:
   action = options[0][0]
   try:
     globals()['do_'+action[2:]] = True
   except KeyError:
     print >> sys.stderr, progname + ': Unhandled parameter ' + action
     sys.exit(1)

-- 
Terry Jan Reedy

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


Thread

Is this a good way to implement testing Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 00:29 +0200
  Re: Is this a good way to implement testing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-03 00:17 +0100
  Re: Is this a good way to implement testing Terry Reedy <tjreedy@udel.edu> - 2015-05-02 20:06 -0400
  Re: Is this a good way to implement testing Paul Rubin <no.email@nospam.invalid> - 2015-05-02 20:58 -0700
    Re: Is this a good way to implement testing Ben Finney <ben+python@benfinney.id.au> - 2015-05-03 14:49 +1000
  Re: Is this a good way to implement testing Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 09:36 +0200
    Re: Is this a good way to implement testing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-03 09:38 +0100
    Re: Is this a good way to implement testing Peter Otten <__peter__@web.de> - 2015-05-03 10:45 +0200
      Re: Is this a good way to implement testing Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 11:49 +0200
        Re: Is this a good way to implement testing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-03 11:21 +0100
          Re: Is this a good way to implement testing Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 12:50 +0200
    Re: Is this a good way to implement testing Ben Finney <ben+python@benfinney.id.au> - 2015-05-03 18:52 +1000
  Re: Is this a good way to implement testing Peter Otten <__peter__@web.de> - 2015-05-03 11:22 +0200

csiph-web