lundi 29 décembre 2014

Is there a python-based utility for testing examples in comments

Is there a python-based utility for testing examples in function comments? For example, given the following code in orwell_1984.py:



def two_plus_two():
"""Returns 2 + 2 according to Orwell's 1984"""
# EX: two_plus_two() => 5
return 5


The utility would do the equivalent of the following:



import orwell_1984
verify_test(orwell_1984.two_plus_two, (), 5)


where verify_test invokes the passed-in function with the specified parameters, and then makes sure equal to the expected value.


A while back I wrote something to do this in perl; see http://www.cs.nmsu.edu/~tomohara/useful-scripts/test-perl-examples.perl. Before trying to port that, I am hoping to find a python-based utility that does something similar.


Aucun commentaire:

Enregistrer un commentaire