Unit tests and coverage

J

Joseph L. Casale

I have a script that accepts cmdline arguments and receives input via stdin..
I have a unit test for it that uses Popen to setup an environment, pass theargs
and provide the stdin.

Problem is obviously this does nothing for providing coverage. Given the above
specifics, anyone know of a way to work around this?

Thanks,
jlc
 
R

Roy Smith

Joseph L. Casale said:
I have a script that accepts cmdline arguments and receives input via stdin.
I have a unit test for it that uses Popen to setup an environment, pass the
args and provide the stdin.

Problem is obviously this does nothing for providing coverage. Given the
above specifics, anyone know of a way to work around this?

What do you mean by "providing coverage"? If you mean, "automatically
generate every possible combination of inputs", that's not, in general,
possible.

There are lots of different meanings people give to the word "coverage"
when talking about testing code. One common definition is, "provide
sufficient sets of inputs to cause every branch in the code to be taken
at least once". That's a pretty weak definition (since it doesn't talk
about combinations of branches), but even that can be amazingly hard to
satisfy. For example, imagine the following code:

try:
big_hairy_operation()
except MemoryError:
print "Oh noes, out of memory!"

what combination of inputs do you have to provide to cause the except
clause to be executed? Or, to touch on an example I mentioned in a
recent thread:

t0 = time.time()
while True:
t1 = time.time()
if t1 < t0:
print "Distortion detected in the time-space continuum"
t0 = t1

So, back to my original question; what do you mean by "providing
coverage"?
 
J

Joseph L. Casale

So, back to my original question; what do you mean by "providing
coverage"?

Hi Roy,
I meant touch every line, such as what https://pypi.python.org/pypi/coverage
measures.

As the script is being invoked with Popen, I lose that luxury and only gain
the assertions tests but that of course doesn't show me untested branches.

Thanks,
jlc
 
J

Joseph L. Casale

As the script is being invoked with Popen, I lose that luxury and only gain
the assertions tests but that of course doesn't show me untested branches..

Should have read the docs more thoroughly, works quite nice.
jlc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top