[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Writing tests for the Python bug tracker

Steven D'Aprano

3/20/2010 6:23:00 AM

I have two reported bugs in the bug tracker waiting on tests:

http://bugs.python.org...
http://bugs.python.org...

Are there any guidelines for writing tests for the standard library and
language? I've googled, but found nothing useful: lots of guidelines for
writing tests, and of course I've read PEP 8, but I'm not sure if there
are conventions for tests I'm missing.



--
Steven
5 Answers

Steven D'Aprano

3/20/2010 6:52:00 AM

0

On Sat, 20 Mar 2010 06:23:14 +0000, Steven D'Aprano wrote:

> Are there any guidelines for writing tests for the standard library and
> language? I've googled, but found nothing useful: lots of guidelines for
> writing tests, and of course I've read PEP 8, but I'm not sure if there
> are conventions for tests I'm missing.

I've found this:

http://docs.python.org/library...

and I've written a small test:

$ cat test_unicode_interpolation.py
# For testing http://bugs.python.org...

import test.test_support
import unittest

class K(unicode):
def __str__(self): return "Surprise!"

class UnicodeInterpolationTest(unittest.TestCase):
def test_interpolation(self):
self.assertEquals(u'%s' % K('some text'), 'Surprise!')

def test_main():
test.test_support.run_unittest(UnicodeInterpolationTest)

if __name__ == "__main__":
test_main()


but when I try running the test, I get an error:

$ python test_unicode_interpolation.py
Options: {'delimiter': None}
str of options.delimiter = None
repr of options.delimiter = None
len of options.delimiter
Traceback (most recent call last):
File "test_unicode_interpolation.py", line 3, in <module>
import test.test_support
File "/home/steve/python/test.py", line 8, in <module>
print "len of options.delimiter", len(options.delimiter)
TypeError: object of type 'NoneType' has no len()


What am I doing wrong?



(By the way, I'm expecting the unit test above to fail.)




--
Steven

exarkun

3/20/2010 7:08:00 AM

0

On 06:52 am, steve@remove-this-cybersource.com.au wrote:
>
>but when I try running the test, I get an error:
>
>$ python test_unicode_interpolation.py
>Options: {'delimiter': None}
>str of options.delimiter = None
>repr of options.delimiter = None
>len of options.delimiter
>Traceback (most recent call last):
> File "test_unicode_interpolation.py", line 3, in <module>
> import test.test_support
> File "/home/steve/python/test.py", line 8, in <module>
> print "len of options.delimiter", len(options.delimiter)
>TypeError: object of type 'NoneType' has no len()
>
>
>What am I doing wrong?

Take a careful look at the stack being reported. Then, think of a
better name than "test" for your file.

Jean-Paul

Steven D'Aprano

3/20/2010 9:54:00 AM

0

On Sat, 20 Mar 2010 07:07:58 +0000, exarkun wrote:

>>What am I doing wrong?
>
> Take a careful look at the stack being reported. Then, think of a
> better name than "test" for your file.

Doh! *face-palm*

I was shadowing the test package with a long forgotten test module.


--
Steven

Mark Dickinson

3/20/2010 10:57:00 AM

0

On Mar 20, 6:23 am, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote:
> I have two reported bugs in the bug tracker waiting on tests:
>
> http://bugs.python.org/issue8128http://bugs.python.org...
>
> Are there any guidelines for writing tests for the standard library and
> language?

Not that I can think of, beyond those you've already mentioned. I
mostly just copy the style of existing tests (though there are
definitely some test_*** files that aren't particularly well written).

For quick questions, you might get good answers by asking on the
#python-dev freenode IRC channel: a good few of the people interested
in testing (esp. Michael Foord, Ezio Melotti) can often be found
there.

--
Mark

Mark Dickinson

3/20/2010 11:01:00 AM

0

On Mar 20, 6:52 am, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote:
> I've found this:
>
> http://docs.python.org/library...
>
> and I've written a small test:
>
> $ cat test_unicode_interpolation.py
> # For testinghttp://bugs.python.org...
>
> import test.test_support
> import unittest
>
> class K(unicode):
>     def __str__(self): return "Surprise!"
>
> class UnicodeInterpolationTest(unittest.TestCase):
>     def test_interpolation(self):
>         self.assertEquals(u'%s' % K('some text'), 'Surprise!')
>
> def test_main():
>     test.test_support.run_unittest(UnicodeInterpolationTest)
>
> if __name__ == "__main__":
>     test_main()

This looks like a fine start to me. I have a feeling that the current
fashion is for assertEqual rather than assertEquals, but I might be
wrong. :)

--
Mark