test for wrong linebreaks and improve fix

This commit is contained in:
Victor Shyba 2020-09-03 17:13:10 -03:00
parent c498619cca
commit e436ae7edd
2 changed files with 42 additions and 8 deletions

View file

@ -218,10 +218,8 @@ def generate_options(method, indent) -> List[str]:
# dont break on -- or docopt will parse as a new option # dont break on -- or docopt will parse as a new option
for line_number, line in enumerate(wrapped): for line_number, line in enumerate(wrapped):
if line.strip().startswith('--'): if line.strip().startswith('--'):
wrapped[line_number-1] += ' ' + line.strip() lines[-1] = lines[-1] + ' ' + line.strip()
wrapped[line_number] = '' else:
continue
for line in wrapped:
lines.append(f"{' ' * len(left)} {line}") lines.append(f"{' ' * len(left)} {line}")
options.extend(lines) options.extend(lines)
return options return options

View file

@ -13,7 +13,12 @@ def test_kwargs(somevalue=1):
@expander @expander
def another_test_kwargs(somevalue=2, repeated=3): def another_test_kwargs(
somevalue=1,
repeated=2,
bad_description=3, # using linebreaks makes docopt very very --angry
angry=4
):
pass pass
@ -45,8 +50,15 @@ class FakeAPI:
def thing_search( def thing_search(
self, self,
**test_and_another_test_kwargs): query='a',
"""search command doc""" **test_and_another_test_kwargs) -> Wallet:
"""
search command doc
Usage:
thing search [--query=<query>]
{kwargs}
"""
def thing_delete(self, value1: str, **tx_and_pagination_kwargs) -> Wallet: # deleted thing def thing_delete(self, value1: str, **tx_and_pagination_kwargs) -> Wallet: # deleted thing
""" """
@ -287,3 +299,27 @@ class TestGenerator(TestCase):
(str) cheese (str) cheese
foo bar""") foo bar""")
) )
def test_parse_does_not_break_with_two_dashes(self):
# breaking with two dashes breaks docopt parsing
definitions = get_api_definitions(FakeAPI)
self.assertEqual(definitions['commands']['thing_search']['help'], """search command doc
Usage:
thing search [--query=<query>]
[--somevalue=<somevalue>] [--repeated=<repeated>]
[--bad_description=<bad_description>] [--angry=<angry>]
Options:
--query=<query> : (str) [default: 'a']
--somevalue=<somevalue> : (int) [default: 1]
--repeated=<repeated> : (int) [default: 2]
--bad_description=<bad_description> : (int) using linebreaks makes docopt very very --angry [default: 3]
--angry=<angry> : (int) [default: 4]
Returns:
(Wallet)
{
"id": "wallet_id",
"name": "optional wallet name"
}""")