Re: Program __main__ function

2007-03-13 Thread André Malo
Ben Finney wrote:

 Ben Finney [EMAIL PROTECTED] writes:
 
 Now, when I write unit tests for my program (i.e. a Python module
 designed to be run as a command), it can still be imported safely
 into my unit tests, and all the code gets covered by test cases
 except the three-line stanza at the end.
 
 All I need now is for Python to automatically execute a '__main__'
 function if the module name is '__main__' (which it seems the OP
 expected should happen), and unit test coverage could be 100% :-)

Short hint to go further:
exec file('/usr/lib/python2.4/timeit.py') in {'__name__': '__main__'}

nd
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Program __main__ function

2007-03-12 Thread Ben Finney
Ben Finney [EMAIL PROTECTED] writes:

 Now, when I write unit tests for my program (i.e. a Python module
 designed to be run as a command), it can still be imported safely
 into my unit tests, and all the code gets covered by test cases
 except the three-line stanza at the end.

All I need now is for Python to automatically execute a '__main__'
function if the module name is '__main__' (which it seems the OP
expected should happen), and unit test coverage could be 100% :-)

 Htag.pl 0.0.23 -  Simon Huggins [EMAIL PROTECTED]  Released under GPL
 Copyright (C) 1999-2002 Project Purple. http://www.earth.li/projectpurple/

 Got sigmatch == ^/home/bignose/\.sigs/news.*$

Er, okay. That was a bit strange. Sorry for the flubbed sigmonster.

-- 
 \   I bet one legend that keeps recurring throughout history, in |
  `\   every culture, is the story of Popeye.  -- Jack Handey |
_o__)  |
Ben Finney

-- 
http://mail.python.org/mailman/listinfo/python-list