Entry 3361
DocTestFinder
Submitted by Joschua
on March 14, 2010 at 5:42 p.m.
Language: Python 3. Code size: 694 bytes.
from doctest import DocTestFinder dtf = DocTestFinder(True) # verbose on def sample(a, b, c): """ hey thats a test """ return a+b*c sample_ds = dtf.find(sample) # returns a list of docstrings (with tests) # sample_ds[0].examples is the list of doctests of the first docstring print(len(sample_ds[0].examples)) def with_doctests(e,b,c): """ >>> with_doctests(3,4,5) "h3" >>> with_doctests(4,3,6) "hhh4" >>> with_doctests(3,4,[1]) Traceback (most recent call last): ... TypeError: unsupported operand type(s) for -: 'list' and 'int' """ return (c-b)*"h"+str(e) with_doctests = dtf.find(with_doctests) print(len(with_doctests[0].examples))
This snippet took 0.00 seconds to highlight.
Back to the Entry List or Home.