-
-
Save u1and0/d9f729d7d98e9e8de10ea03ee2193119 to your computer and use it in GitHub Desktop.
python docstring内にテストを記述 ref: http://qiita.com/u1and0/items/3a7b73dca38414f3a703
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
1 items had no tests: | |
__main__ | |
1 items passed all tests: | |
2 tests in __main__.twice | |
2 tests in 2 items. | |
2 passed and 0 failed. | |
Test passed. | |
body... |
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
In [81]: run doctest_use.py | |
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
name?>> __main__ | |
Trying: | |
twice(8) | |
Expecting: | |
16 | |
ok | |
Trying: | |
twice(1850923) | |
Expecting: | |
3701846 | |
ok | |
1 items had no tests: | |
__main__ | |
1 items passed all tests: | |
2 tests in __main__.twice | |
2 tests in 2 items. | |
2 passed and 0 failed. | |
Test passed. | |
EOF | |
[Finished in 0.5s] |
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
name?>> doctest_sample | |
EOF | |
[Finished in 0.4s] |
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
import docstring | |
def hoge(): | |
''' | |
hoge(args) | |
''' | |
if __name__ == "__main__": | |
doctest.testmod() |
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 twice(n): | |
""" 引数を 2 倍して返す関数 | |
>>> twice(8) | |
16 | |
>>> twice(1850923) | |
3701846 | |
""" | |
return n * 2 | |
print('name?>>', __name__) | |
if __name__ == "__main__": | |
doctest.testmod() | |
print('EOF') | |
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
Show hidden characters
{ | |
"cmd": ["python", "$file", "-v"], | |
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", | |
"selector": "source.python" | |
} |
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 twice(n): | |
""" 引数を 2 倍して返す関数 | |
>>> twice(8) | |
16 | |
>>> twice(1850923) | |
""" | |
return n * 2 | |
'''TEST | |
twice(8) | |
# 実行結果 | |
#16 | |
twice(1850923) | |
# 実行結果 | |
#3701846 | |
'''# ←ここのトリプルクォートを'TEST'って書いてあるところまで引き上げてやることでtwice(8), twice(1850923)を実行する |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment