forked from pool/python-sphinx-argparse
- Resolve the mess with different
patches. different_pytest_name.patch has been replaced by prog-in-description.patch from gh#alex-rudakov/sphinx-argparse#121 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-sphinx-argparse?expand=0&rev=3
This commit is contained in:
83
prog-in-description.patch
Normal file
83
prog-in-description.patch
Normal file
@@ -0,0 +1,83 @@
|
||||
--- a/sphinxarg/parser.py
|
||||
+++ b/sphinxarg/parser.py
|
||||
@@ -10,7 +10,7 @@ def parser_navigate(parser_result, path,
|
||||
if isinstance(path, str):
|
||||
if path == '':
|
||||
return parser_result
|
||||
- path = re.split('\s+', path)
|
||||
+ path = re.split(r'\s+', path)
|
||||
current_path = current_path or []
|
||||
if len(path) == 0:
|
||||
return parser_result
|
||||
@@ -35,7 +35,7 @@ def _try_add_parser_attribute(data, pars
|
||||
if not isinstance(attribval, str):
|
||||
return
|
||||
if len(attribval) > 0:
|
||||
- data[attribname] = attribval
|
||||
+ data[attribname] = attribval % {'prog': data['prog']}
|
||||
|
||||
|
||||
def _format_usage_without_prefix(parser):
|
||||
--- a/test/test_parser.py
|
||||
+++ b/test/test_parser.py
|
||||
@@ -129,7 +129,7 @@ def test_parse_description():
|
||||
|
||||
|
||||
def test_parse_nested():
|
||||
- parser = argparse.ArgumentParser()
|
||||
+ parser = argparse.ArgumentParser(prog='test_parse_nested')
|
||||
parser.add_argument('foo', default=False, help='foo help')
|
||||
parser.add_argument('bar', default=False)
|
||||
|
||||
@@ -157,8 +157,8 @@ def test_parse_nested():
|
||||
{
|
||||
'name': 'install',
|
||||
'help': 'install help',
|
||||
- 'usage': 'usage: py.test install [-h] [--upgrade] ref',
|
||||
- 'bare_usage': 'py.test install [-h] [--upgrade] ref',
|
||||
+ 'usage': 'usage: test_parse_nested install [-h] [--upgrade] ref',
|
||||
+ 'bare_usage': 'test_parse_nested install [-h] [--upgrade] ref',
|
||||
'action_groups': [
|
||||
{
|
||||
'title': 'Positional Arguments',
|
||||
@@ -188,7 +188,7 @@ def test_parse_nested():
|
||||
|
||||
|
||||
def test_parse_nested_traversal():
|
||||
- parser = argparse.ArgumentParser()
|
||||
+ parser = argparse.ArgumentParser(prog='test_parse_nested_traversal')
|
||||
|
||||
subparsers1 = parser.add_subparsers()
|
||||
subparser1 = subparsers1.add_parser('level1')
|
||||
@@ -223,8 +223,8 @@ def test_parse_nested_traversal():
|
||||
{
|
||||
'name': 'level3',
|
||||
'help': '',
|
||||
- 'usage': 'usage: py.test level1 level2 level3 [-h] foo bar',
|
||||
- 'bare_usage': 'py.test level1 level2 level3 [-h] foo bar',
|
||||
+ 'usage': 'usage: test_parse_nested_traversal level1 level2 level3 [-h] foo bar',
|
||||
+ 'bare_usage': 'test_parse_nested_traversal level1 level2 level3 [-h] foo bar',
|
||||
'action_groups': [
|
||||
{
|
||||
'title': 'Positional Arguments',
|
||||
@@ -265,6 +265,20 @@ def test_fill_in_default_prog():
|
||||
]
|
||||
|
||||
|
||||
+def test_fill_in_description_epilog():
|
||||
+ """
|
||||
+ Ensure that %(prog)s gets filled in inside description and epilog.
|
||||
+ """
|
||||
+ parser = argparse.ArgumentParser(
|
||||
+ prog='test_fill_in_description',
|
||||
+ description='Welcome to %(prog)s',
|
||||
+ epilog='%(prog)s salutes you')
|
||||
+ data = parse_parser(parser)
|
||||
+
|
||||
+ assert data['description'] == 'Welcome to test_fill_in_description'
|
||||
+ assert data['epilog'] == 'test_fill_in_description salutes you'
|
||||
+
|
||||
+
|
||||
def test_string_quoting():
|
||||
"""
|
||||
If an optional argument has a string type and a default, then the default should be in quotes.
|
Reference in New Issue
Block a user