[Tutor] unwanted 'zero' ending
Jim Mooney
cybervigilante at gmail.com
Fri Jun 28 01:39:25 CEST 2013
On 27 June 2013 05:38, Steven D'Aprano <steve at pearwood.info> wrote:
> Unit tests are great, but the learning curve is rather steep. I recommend that you start with doctests.
I tried a simple one and it worked, but a puzzlement. Does it Only
test what you've hard-coded? That is, here is a simple test:
def doubler(inp):
'''Return a doubled number or string
>>> doubler(24)
48
>>> doubler('zark')
'zarkzark'
'''
return inp * 2
This works on 24 or 'zark' as input when I run
C:\Python33\Jimprogs>python -m doctest
"C:/python33/jimprogs/docstringtest.py" --verbose'
and doctest prints:
48
zarkzark
And it fails if I put 'this doesn't work' as the return value of the function:
1 items had failures:
2 of 2 in docstringtest.
***Test Failed*** 2 failures.
Although that doesn't tell me much.
But it also works on different input --> 189 and 'plantagenet,' to print:
378
plantagenetplantagenet
It's odd to me that it doesn't fail on what I haven't hardcoded.
I don't see how docstring could figure what I might be doing, so I
assume that although it returns anything valid, it Only tests on the
hardcoded values, 24 and 'zark'. Is this correct? In which case it
seems like a lot of hard coding would be needed unless you tested only
endpoints or what might be problematic.
Or is it doing something more?
--
Jim
Every time I buy "As Seen on TV" it turns out to be junk.
More information about the Tutor
mailing list