[TIP] argv with unitest
magawake at gmail.com
Sun Sep 6 05:53:41 PDT 2009
I have tried using the
http://www.artima.com/weblogs/viewpost.jsp?thread=4829 for a reference
but I am still having problems,
I think I should take couple of steps back....and write some
pseudocode for a good testing framework template.
Foo.pl -- The purpose is to to count from 1 to 100
Should raise an exception if a wrong argument was given and run a
I would invoke it like this:
python Foo.pl --stdout outfile --stderr errorfile
My tests would be like this:
If stdout is set, will it create a file of stdout?
If --help or -h is set the Usage() call should be called and return an
error code 1
If --help and --stdout is set --help should over ride and still return
an error code 1
How can I incorporate this to a good testing framework?
On Tue, Aug 18, 2009 at 11:05 PM, Mag Gam<magawake at gmail.com> wrote:
> good stuff. thanks
> On Tue, Aug 18, 2009 at 9:55 AM, Ben Finney<ben+python at benfinney.id.au> wrote:
>> Mag Gam <magawake at gmail.com> writes:
>>> How do I simulate argv with unittest? Is it better to place it in
>>> setUp() or somewhere else?
>> This is a classic instance where the practice of unit testing encourages
>> you to design your code to be more easily tested, and hence think about
>> how your code will be more easily used from outside, and hence
>> indirectly encourages good design: narrow, well-defined interfaces.
>> You should structure your program so that the “mainline code” function
>> receives the commandline arguments as its (preferably only) explicit
>> function call parameter, so that it can more easily become a component
>> in some larger system — such as your unit test suite.
>> Guido van Rossum made a weblog entry on one good recipe for this
>> <URL:http://www.artima.com/weblogs/viewpost.jsp?thread=4829>, and I do
>> something similar with all my Python programs.
>> \ “Do not enter the lift backwards, and only when lit up.” |
>> `\ —elevator, Leipzig |
>> _o__) |
>> Ben Finney
>> testing-in-python mailing list
>> testing-in-python at lists.idyll.org
More information about the testing-in-python