Created
December 23, 2011 17:03
-
-
Save daneko/1514769 to your computer and use it in GitHub Desktop.
doctestメモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
以下失敗事例 | |
''' | |
def reverseStr( param ): | |
''' | |
# 一見正しそうだけど「>>>」の後にスペースねぇと実行時に怒られる | |
>>>reverseStr('hoge') | |
'egoh' | |
# 一見正しそうだけど テストは失敗する | |
# 返却配列の「,」の後にスペースがない 正しくは['cba', 'gfe'] | |
>>> [reverseStr(param) for param in ['abc','efg']] | |
['cba','gfe'] | |
>>> reverseStr('hoge') | |
'egoh' | |
# ここにコメントのつもりで書いたら実行結果の一部と思われるよ! | |
# 必ず空白行か「>>> 」を入れること | |
''' | |
return param[::-1] | |
def _test(): | |
import doctest | |
doctest.testmod() | |
if __name__ == "__main__": | |
_test() | |
あとはここ見る | |
http://www.python.jp/doc/2.5/lib/module-doctest.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment