Created
July 4, 2012 02:47
-
-
Save usaturn/3044955 to your computer and use it in GitHub Desktop.
引数のテストをするには?
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
# -*- coding:utf-8 -*- | |
# こんな感じで書くよーと教えてもらいました | |
import sys | |
import unittest | |
from StringIO import StringIO | |
from url_checker import * | |
class TestCaseForArgparse(unittest.TestCase): | |
def test_options_judgment(self): | |
# set STDERR to null | |
_stderr = sys.stderr | |
sys.stderr = StringIO() | |
sys.argv = ['script_name', '-a'] # set arguments | |
self.assertRaises(SystemExit, options_judgment) | |
sys.argv = [] # clear | |
sys.stderr = _stderr # restore STDERR | |
if __name__ == '__main__': | |
unittest.main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment