[Biopython-dev] docstring tests

Bruce Southey bsouthey at gmail.com
Fri Feb 13 10:37:38 EST 2009


Michiel de Hoon wrote:
> Thanks for the patch. I've updated run_tests.py along these lines, and I added an option "doctest" to specify running the doctests:
>
> $ python run_tests.py doctest
> Bio.Seq docstring test ... ok
> Bio.SeqRecord docstring test ... ok
> Bio.SeqIO docstring test ... ok
> Bio.Align.Generic docstring test ... ok
> Bio.AlignIO docstring test ... ok
> Bio.KEGG.Compound docstring test ... ok
> Bio.KEGG.Enzyme docstring test ... ok
> Bio.Wise docstring test ... ok
> Bio.Wise.psw docstring test ... ok
> Bio.Statistics.lowess docstring test ... ok
> ----------------------------------------------------------------------
> Ran 10 tests in 0.726 seconds
>
>
>
>
> --- On Thu, 2/12/09, Peter <biopython at maubp.freeserve.co.uk> wrote:
>
>   
>> From: Peter <biopython at maubp.freeserve.co.uk>
>> Subject: Re: [Biopython-dev] docstring tests
>> To: mjldehoon at yahoo.com
>> Cc: biopython-dev at biopython.org
>> Date: Thursday, February 12, 2009, 6:49 AM
>> Hi Michiel (and everyone else),
>>
>> I was wondering about how the doctests are currently
>> integrated into
>> run_tests.py, and wondered if this patch makes things more
>> concise?
>> This patch is against run_tests.py CVS revision 1.22,
>> essentially it
>> adds the doctest modules to the list of tests - rather than
>> as a
>> separate list.  The code becomes slightly shorter, but I am
>> not sure
>> if this is actually clearer or not.
>>
>> Note - this does not address the issue of how to run just
>> the doctests
>> - something I think is very useful when working on them.
>>
>> Peter
>>
>> $ diff run_tests.py run_tests2.py
>> 209,211c209
>> <         if self.tests:
>> <             self.doctest_modules = []
>> <         else:
>> ---
>>     
>>>         if not self.tests:
>>>       
>> 218c216,222
>> <             self.doctest_modules = DOCTEST_MODULES
>> ---
>>     
>>>             if sys.version_info[:2] < (2, 4):
>>>                 #On python 2.3, doctest uses slightly
>>>       
>> different formatting
>>     
>>>                 #which would be a problem as the
>>>       
>> expected output won't match.
>>     
>>>                 #Also, it can't cope with
>>>       
>> <BLANKLINE> in a doctest string.
>>     
>>>                 sys.stderr.write("Skipping
>>>       
>> doctests which require Python 2.4+\n")
>>     
>>>             else :
>>>                 self.tests.extend(DOCTEST_MODULES)
>>>       
>> 234,240c238,253
>> <                 module = __import__(name)
>> <                 suite =
>> unittest.TestLoader().loadTestsFromModule(module)
>> <                 if suite.countTestCases()==0:
>> <                     # This is a print-and-compare test
>> instead of a unittest-
>> <                     # type test.
>> <                     test = ComparisonTestCase(name,
>> output)
>> <                     suite = unittest.TestSuite([test])
>> ---
>>     
>>>                 if "." in name :
>>>                     #Its a doc test
>>>                     #Can't use
>>>       
>> fromlist=name.split(".") until python 2.5+
>>     
>>>                     module = __import__(name, None,
>>>       
>> None, name.split("."))
>>     
>>>                     suite =
>>>       
>> doctest.DocTestSuite(module)
>>     
>>>                     del module
>>>                 else :
>>>                     #Its a unittest (or a
>>>       
>> print-and-compare test)
>>     
>>>                     suite =
>>>       
>> unittest.TestLoader().loadTestsFromName(name)
>>     
>>>                     if suite.countTestCases()==0:
>>>                         # This is a print-and-compare
>>>       
>> test instead of a
>>     
>>>                         # unittest-type test.
>>>                         test =
>>>       
>> ComparisonTestCase(name, output)
>>     
>>>                         suite =
>>>       
>> unittest.TestSuite([test])
>> 263,277d275
>> <     def runDocTest(self, name):
>> <         #Can't use
>> fromlist=name.split(".") until python 2.5+
>> <         module = __import__(name, None, None,
>> name.split("."))
>> <         sys.stderr.write("%s docstring test ...
>> " % module.__name__)
>> <         suite = doctest.DocTestSuite(module)
>> <         result = self._makeResult()
>> <         suite.run(result)
>> <         if result.wasSuccessful():
>> <             sys.stderr.write("ok\n")
>> <             return True
>> <         else:
>> <             sys.stderr.write("FAIL\n")
>> <             result.printErrors()
>> <             return False
>> <
>> 287,297d284
>> <         if sys.version_info[:2] < (2, 4):
>> <             #On python 2.3, doctest uses slightly
>> different formatting
>> <             #which would be a problem as the expected
>> output won't match.
>> <             #Also, it can't cope with
>> <BLANKLINE> in a doctest string.
>> <             sys.stderr.write("Docstring tests
>> require Python 2.4 or
>> later; skipping\n")
>> <         else:
>> <             for test in self.doctest_modules:
>> <                 ok = self.runDocTest(test)
>> <                 if not ok:
>> <                     failures += 1
>> <                 total += 1
>>     
>
>
>       
> _______________________________________________
> Biopython-dev mailing list
> Biopython-dev at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biopython-dev
>   
Hi,
At present 'python setup.py test'  does do all the tests including the 
doctests. Just curious, will you also add the ability to select the 
doctests there as well?

Bruce




More information about the Biopython-dev mailing list