Skip to content

Commit

Permalink
Test alias handling only on Python >= 3
Browse files Browse the repository at this point in the history
  • Loading branch information
hstock committed Feb 21, 2019
1 parent dee3707 commit edd52b4
Showing 1 changed file with 76 additions and 75 deletions.
151 changes: 76 additions & 75 deletions test/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
from sphinxarg.parser import parse_parser, parser_navigate
import six


def test_parse_options():
Expand Down Expand Up @@ -187,82 +188,82 @@ def test_parse_nested():
]


def test_parse_nested_with_alias():
parser = argparse.ArgumentParser()
parser.add_argument('foo', default=False, help='foo help')
parser.add_argument('bar', default=False)

subparsers = parser.add_subparsers()

subparser = subparsers.add_parser('install', aliases=['i'], help='install help')
subparser.add_argument('ref', type=str, help='foo1 help')
subparser.add_argument('--upgrade', action='store_true', default=False, help='foo2 help')

data = parse_parser(parser)

assert data['action_groups'][0]['options'] == [
{
'name': ['foo'],
'help': 'foo help',
'default': False
}, {
'name': ['bar'],
if six.PY3:
def test_parse_nested_with_alias():
parser = argparse.ArgumentParser()
parser.add_argument('foo', default=False, help='foo help')
parser.add_argument('bar', default=False)

subparsers = parser.add_subparsers()

subparser = subparsers.add_parser('install', aliases=['i'], help='install help')
subparser.add_argument('ref', type=str, help='foo1 help')
subparser.add_argument('--upgrade', action='store_true', default=False, help='foo2 help')

data = parse_parser(parser)

assert data['action_groups'][0]['options'] == [
{
'name': ['foo'],
'help': 'foo help',
'default': False
}, {
'name': ['bar'],
'help': '',
'default': False
}
]

assert data['children'] == [
{
'name': 'install (i)',
'identifier': 'install',
'help': 'install help',
'usage': 'usage: py.test install [-h] [--upgrade] ref',
'bare_usage': 'py.test install [-h] [--upgrade] ref',
'action_groups': [
{
'title': 'Positional Arguments',
'description': None,
'options': [
{
'name': ['ref'],
'help': 'foo1 help',
'default': None
}
]
},
{
'description': None,
'title': 'Named Arguments',
'options': [
{
'name': ['--upgrade'],
'default': False,
'help': 'foo2 help'
}
]
}
]
}
]

def test_aliased_traversal():
parser = argparse.ArgumentParser()

subparsers1 = parser.add_subparsers()
subparsers1.add_parser('level1', aliases=['l1'])

data = parse_parser(parser)

data2 = parser_navigate(data, 'level1')

assert(data2 == {
'bare_usage': 'py.test level1 [-h]',
'help': '',
'default': False
}
]

assert data['children'] == [
{
'name': 'install (i)',
'identifier': 'install',
'help': 'install help',
'usage': 'usage: py.test install [-h] [--upgrade] ref',
'bare_usage': 'py.test install [-h] [--upgrade] ref',
'action_groups': [
{
'title': 'Positional Arguments',
'description': None,
'options': [
{
'name': ['ref'],
'help': 'foo1 help',
'default': None
}
]
},
{
'description': None,
'title': 'Named Arguments',
'options': [
{
'name': ['--upgrade'],
'default': False,
'help': 'foo2 help'
}
]
}
]
}
]


def test_aliased_traversal():
parser = argparse.ArgumentParser()

subparsers1 = parser.add_subparsers()
subparsers1.add_parser('level1', aliases=['l1'])

data = parse_parser(parser)

data2 = parser_navigate(data, 'level1')

assert(data2 == {
'bare_usage': 'py.test level1 [-h]',
'help': '',
'usage': 'usage: py.test level1 [-h]',
'name': 'level1 (l1)',
'identifier': 'level1'})
'usage': 'usage: py.test level1 [-h]',
'name': 'level1 (l1)',
'identifier': 'level1'})


def test_parse_nested_traversal():
Expand Down

0 comments on commit edd52b4

Please sign in to comment.