diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-08-29 09:37:28 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-08-29 09:37:28 (GMT) |
commit | de2800f8f13df85d9e48b963307b2725abc2076f (patch) | |
tree | 14f77f289ec7a380c8119fb0b46fc774a57706de /Lib/unittest/test/test_program.py | |
parent | 64f7c4e4ca5141a8db28a2825f655e863d1c264f (diff) | |
download | cpython-de2800f8f13df85d9e48b963307b2725abc2076f.zip cpython-de2800f8f13df85d9e48b963307b2725abc2076f.tar.gz cpython-de2800f8f13df85d9e48b963307b2725abc2076f.tar.bz2 |
Issue #17974: Switch unittest from using getopt to using argparse.
Diffstat (limited to 'Lib/unittest/test/test_program.py')
-rw-r--r-- | Lib/unittest/test/test_program.py | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/Lib/unittest/test/test_program.py b/Lib/unittest/test/test_program.py index 151f71e..3294298 100644 --- a/Lib/unittest/test/test_program.py +++ b/Lib/unittest/test/test_program.py @@ -2,6 +2,7 @@ import io import os import sys +from test import support import unittest @@ -186,20 +187,38 @@ class TestCommandLineArgs(unittest.TestCase): if attr == 'catch' and not hasInstallHandler: continue + setattr(program, attr, None) + program.parseArgs([None]) + self.assertIs(getattr(program, attr), False) + + false = [] + setattr(program, attr, false) + program.parseArgs([None]) + self.assertIs(getattr(program, attr), false) + + true = [42] + setattr(program, attr, true) + program.parseArgs([None]) + self.assertIs(getattr(program, attr), true) + short_opt = '-%s' % arg[0] long_opt = '--%s' % arg for opt in short_opt, long_opt: setattr(program, attr, None) - - program.parseArgs([None, opt]) - self.assertTrue(getattr(program, attr)) - - for opt in short_opt, long_opt: - not_none = object() - setattr(program, attr, not_none) - program.parseArgs([None, opt]) - self.assertEqual(getattr(program, attr), not_none) + self.assertIs(getattr(program, attr), True) + + setattr(program, attr, False) + with support.captured_stderr() as stderr, \ + self.assertRaises(SystemExit) as cm: + program.parseArgs([None, opt]) + self.assertEqual(cm.exception.args, (2,)) + + setattr(program, attr, True) + with support.captured_stderr() as stderr, \ + self.assertRaises(SystemExit) as cm: + program.parseArgs([None, opt]) + self.assertEqual(cm.exception.args, (2,)) def testWarning(self): """Test the warnings argument""" |