mirror of
https://github.com/python/cpython.git
synced 2025-11-22 19:46:48 +00:00
merge heads
This commit is contained in:
commit
ea2ce47958
15 changed files with 173 additions and 85 deletions
|
|
@ -1374,6 +1374,7 @@ class TestArgumentsFromFile(TempDirMixin, ParserTestCase):
|
|||
('X @hello', NS(a=None, x='X', y=['hello world!'])),
|
||||
('-a B @recursive Y Z', NS(a='A', x='hello world!', y=['Y', 'Z'])),
|
||||
('X @recursive Z -a B', NS(a='B', x='X', y=['hello world!', 'Z'])),
|
||||
(["-a", "", "X", "Y"], NS(a='', x='X', y=['Y'])),
|
||||
]
|
||||
|
||||
|
||||
|
|
@ -1763,6 +1764,14 @@ class TestAddSubparsers(TestCase):
|
|||
parser2.add_argument('-y', choices='123', help='y help')
|
||||
parser2.add_argument('z', type=complex, nargs='*', help='z help')
|
||||
|
||||
# add third sub-parser
|
||||
parser3_kwargs = dict(description='3 description')
|
||||
if subparser_help:
|
||||
parser3_kwargs['help'] = '3 help'
|
||||
parser3 = subparsers.add_parser('3', **parser3_kwargs)
|
||||
parser3.add_argument('t', type=int, help='t help')
|
||||
parser3.add_argument('u', nargs='...', help='u help')
|
||||
|
||||
# return the main parser
|
||||
return parser
|
||||
|
||||
|
|
@ -1792,6 +1801,10 @@ class TestAddSubparsers(TestCase):
|
|||
self.parser.parse_args('--foo 0.125 1 c'.split()),
|
||||
NS(foo=True, bar=0.125, w=None, x='c'),
|
||||
)
|
||||
self.assertEqual(
|
||||
self.parser.parse_args('-1.5 3 11 -- a --foo 7 -- b'.split()),
|
||||
NS(foo=False, bar=-1.5, t=11, u=['a', '--foo', '7', '--', 'b']),
|
||||
)
|
||||
|
||||
def test_parse_known_args(self):
|
||||
self.assertEqual(
|
||||
|
|
@ -1826,15 +1839,15 @@ class TestAddSubparsers(TestCase):
|
|||
|
||||
def test_help(self):
|
||||
self.assertEqual(self.parser.format_usage(),
|
||||
'usage: PROG [-h] [--foo] bar {1,2} ...\n')
|
||||
'usage: PROG [-h] [--foo] bar {1,2,3} ...\n')
|
||||
self.assertEqual(self.parser.format_help(), textwrap.dedent('''\
|
||||
usage: PROG [-h] [--foo] bar {1,2} ...
|
||||
usage: PROG [-h] [--foo] bar {1,2,3} ...
|
||||
|
||||
main description
|
||||
|
||||
positional arguments:
|
||||
bar bar help
|
||||
{1,2} command help
|
||||
{1,2,3} command help
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
|
|
@ -1845,15 +1858,15 @@ class TestAddSubparsers(TestCase):
|
|||
# Make sure - is still used for help if it is a non-first prefix char
|
||||
parser = self._get_parser(prefix_chars='+:-')
|
||||
self.assertEqual(parser.format_usage(),
|
||||
'usage: PROG [-h] [++foo] bar {1,2} ...\n')
|
||||
'usage: PROG [-h] [++foo] bar {1,2,3} ...\n')
|
||||
self.assertEqual(parser.format_help(), textwrap.dedent('''\
|
||||
usage: PROG [-h] [++foo] bar {1,2} ...
|
||||
usage: PROG [-h] [++foo] bar {1,2,3} ...
|
||||
|
||||
main description
|
||||
|
||||
positional arguments:
|
||||
bar bar help
|
||||
{1,2} command help
|
||||
{1,2,3} command help
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
|
|
@ -1864,15 +1877,15 @@ class TestAddSubparsers(TestCase):
|
|||
def test_help_alternate_prefix_chars(self):
|
||||
parser = self._get_parser(prefix_chars='+:/')
|
||||
self.assertEqual(parser.format_usage(),
|
||||
'usage: PROG [+h] [++foo] bar {1,2} ...\n')
|
||||
'usage: PROG [+h] [++foo] bar {1,2,3} ...\n')
|
||||
self.assertEqual(parser.format_help(), textwrap.dedent('''\
|
||||
usage: PROG [+h] [++foo] bar {1,2} ...
|
||||
usage: PROG [+h] [++foo] bar {1,2,3} ...
|
||||
|
||||
main description
|
||||
|
||||
positional arguments:
|
||||
bar bar help
|
||||
{1,2} command help
|
||||
{1,2,3} command help
|
||||
|
||||
optional arguments:
|
||||
+h, ++help show this help message and exit
|
||||
|
|
@ -1881,18 +1894,19 @@ class TestAddSubparsers(TestCase):
|
|||
|
||||
def test_parser_command_help(self):
|
||||
self.assertEqual(self.command_help_parser.format_usage(),
|
||||
'usage: PROG [-h] [--foo] bar {1,2} ...\n')
|
||||
'usage: PROG [-h] [--foo] bar {1,2,3} ...\n')
|
||||
self.assertEqual(self.command_help_parser.format_help(),
|
||||
textwrap.dedent('''\
|
||||
usage: PROG [-h] [--foo] bar {1,2} ...
|
||||
usage: PROG [-h] [--foo] bar {1,2,3} ...
|
||||
|
||||
main description
|
||||
|
||||
positional arguments:
|
||||
bar bar help
|
||||
{1,2} command help
|
||||
{1,2,3} command help
|
||||
1 1 help
|
||||
2 2 help
|
||||
3 3 help
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
|
|
|
|||
|
|
@ -495,7 +495,19 @@ class UTF16LETest(ReadTest):
|
|||
)
|
||||
|
||||
def test_errors(self):
|
||||
self.assertRaises(UnicodeDecodeError, codecs.utf_16_le_decode, "\xff", "strict", True)
|
||||
tests = [
|
||||
(b'\xff', u'\ufffd'),
|
||||
(b'A\x00Z', u'A\ufffd'),
|
||||
(b'A\x00B\x00C\x00D\x00Z', u'ABCD\ufffd'),
|
||||
(b'\x00\xd8', u'\ufffd'),
|
||||
(b'\x00\xd8A', u'\ufffd'),
|
||||
(b'\x00\xd8A\x00', u'\ufffdA'),
|
||||
(b'\x00\xdcA\x00', u'\ufffdA'),
|
||||
]
|
||||
for raw, expected in tests:
|
||||
self.assertRaises(UnicodeDecodeError, codecs.utf_16_le_decode,
|
||||
raw, 'strict', True)
|
||||
self.assertEqual(raw.decode('utf-16le', 'replace'), expected)
|
||||
|
||||
class UTF16BETest(ReadTest):
|
||||
encoding = "utf-16-be"
|
||||
|
|
@ -516,7 +528,19 @@ class UTF16BETest(ReadTest):
|
|||
)
|
||||
|
||||
def test_errors(self):
|
||||
self.assertRaises(UnicodeDecodeError, codecs.utf_16_be_decode, "\xff", "strict", True)
|
||||
tests = [
|
||||
(b'\xff', u'\ufffd'),
|
||||
(b'\x00A\xff', u'A\ufffd'),
|
||||
(b'\x00A\x00B\x00C\x00DZ', u'ABCD\ufffd'),
|
||||
(b'\xd8\x00', u'\ufffd'),
|
||||
(b'\xd8\x00\xdc', u'\ufffd'),
|
||||
(b'\xd8\x00\x00A', u'\ufffdA'),
|
||||
(b'\xdc\x00\x00A', u'\ufffdA'),
|
||||
]
|
||||
for raw, expected in tests:
|
||||
self.assertRaises(UnicodeDecodeError, codecs.utf_16_be_decode,
|
||||
raw, 'strict', True)
|
||||
self.assertEqual(raw.decode('utf-16be', 'replace'), expected)
|
||||
|
||||
class UTF8Test(ReadTest):
|
||||
encoding = "utf-8"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue