raise instead of implicit deduplication of arguments

This commit is contained in:
Victor Shyba 2020-09-04 00:35:38 -03:00
parent 10ad4ed8d1
commit c981c767b9
2 changed files with 22 additions and 20 deletions

View file

@ -159,7 +159,7 @@ def parse_method(method, expanders: dict) -> dict:
raise Exception(f"Expander '{expander_name}' not found, used by {d['name']}.") raise Exception(f"Expander '{expander_name}' not found, used by {d['name']}.")
for expanded in expanders[expander_name]: for expanded in expanders[expander_name]:
if expanded['name'] in known_names: if expanded['name'] in known_names:
continue raise Exception(f"Expander '{expander_name}' argument repeated: {expanded['name']}.")
d['arguments'].append(expanded) d['arguments'].append(expanded)
d['kwargs'].append(expanded) d['kwargs'].append(expanded)
known_names.add(expanded['name']) known_names.add(expanded['name'])

View file

@ -48,18 +48,6 @@ class FakeAPI:
def thing_update(self, value1: str) -> Wallet: # updated wallet def thing_update(self, value1: str) -> Wallet: # updated wallet
"""update command doc""" """update command doc"""
def thing_search(
self,
query='a',
**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
""" """
delete command doc delete command doc
@ -84,13 +72,27 @@ class FakeAPI:
""" """
class BadAPI(FakeAPI):
def thing_search(
self,
query='a',
**test_and_another_test_kwargs) -> Wallet:
"""
search command doc
Usage:
thing search [--query=<query>]
{kwargs}
"""
class TestParser(TestCase): class TestParser(TestCase):
maxDiff = None maxDiff = None
def test_parse_does_not_duplicate_arguments(self): def test_parse_does_not_duplicate_arguments(self):
parsed = parse_method(FakeAPI.thing_search, get_expanders()) with self.assertRaises(Exception) as exc:
names = [arg['name'] for arg in parsed['arguments']] parse_method(BadAPI.thing_search, get_expanders())
self.assertEqual(len(names), len(set(names))) self.assertEqual(exc.exception.args[0], "Expander 'another_test' argument repeated: thing_search.")
def test_parse_method(self): def test_parse_method(self):
expanders = get_expanders() expanders = get_expanders()