Skip to content

Commit

Permalink
Added param docs to the connection method docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
toastdriven committed Nov 29, 2013
1 parent 614e838 commit 0a9402a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
25 changes: 24 additions & 1 deletion boto3/core/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,29 @@ def _build_methods(self, details):

return attrs

def _generate_docstring(self, op_data):
docstring = op_data['docs']
params = []

for param_data in op_data['params']:
param_doc = ":param {0}: {1}\n".format(
param_data['var_name'],
param_data.get('docs', 'No documentation available')
)
type_doc = ":type {0}: {1}\n".format(
param_data['var_name'],
param_data['type']
)

docstring += '\n'
docstring += param_doc
docstring += type_doc

docstring += '\n'
docstring += ':returns: The response data received\n'
docstring += ':rtype: dict\n'
return docstring

def _create_operation_method(factory_self, method_name, orig_op_data):
if not six.PY3:
method_name = str(method_name)
Expand Down Expand Up @@ -316,6 +339,6 @@ def _new_method(self, **kwargs):
# Swap the name, so it looks right.
_new_method.__name__ = method_name
# Assign docstring.
_new_method.__doc__ = orig_op_data['docs']
_new_method.__doc__ = factory_self._generate_docstring(orig_op_data)
# Return the newly constructed method.
return _new_method
22 changes: 20 additions & 2 deletions tests/unit/core/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ class TestCoreService(FakeService):
'CreateQueue',
" <p>Creates a queue.</p>\n ",
params=[
FakeParam('QueueName', required=True, ptype='string'),
FakeParam(
'QueueName',
required=True,
ptype='string',
documentation='\n <p>The name for the queue to be created.</p>\n '
),
FakeParam('Attributes', required=False, ptype='map'),
],
output={
Expand Down Expand Up @@ -177,7 +182,12 @@ def test__create_operation_method(self):
'output': True,
})
self.assertEqual(func.__name__, 'test')
self.assertEqual(func.__doc__, 'This is a test.')
self.assertEqual(
func.__doc__,
'This is a test.\n:' + \
'returns: The response data received\n' + \
':rtype: dict\n'
)

def test__post_process_results(self):
ppr = self.test_service_class()._post_process_results
Expand Down Expand Up @@ -218,6 +228,14 @@ def test_integration(self):
['queue_name', 'attributes']
)

# Check the docstring.
self.assertTrue(
':param queue_name: The name' in ts.create_queue.__doc__
)
self.assertTrue(
':type queue_name: string' in ts.create_queue.__doc__
)

def test_late_binding(self):
# If the ``ConnectionDetails`` data changes, it should be reflected in
# the dynamic methods.
Expand Down

0 comments on commit 0a9402a

Please sign in to comment.