mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Issue #17974: Switch unittest from using getopt to using argparse.
This commit is contained in:
parent
64f7c4e4ca
commit
de2800f8f1
5 changed files with 172 additions and 179 deletions
|
@ -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))
|
||||
self.assertIs(getattr(program, attr), True)
|
||||
|
||||
for opt in short_opt, long_opt:
|
||||
not_none = object()
|
||||
setattr(program, attr, not_none)
|
||||
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,))
|
||||
|
||||
program.parseArgs([None, opt])
|
||||
self.assertEqual(getattr(program, attr), not_none)
|
||||
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"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue