Browse files

DocumentationComment: Add from_metadata()

This function acts as a constructor to assemble a list of parsed
documentation comments. It sets up the assemble() function.
  • Loading branch information...
SanketDG committed Jul 30, 2016
1 parent 3a78aa9 commit dc35a0a9506e440ca0409d81a573731fbcc04d0e
@@ -141,3 +141,59 @@ def _parse_documentation_with_symbols(self, param_identifiers,
return parsed
def from_metadata(cls, doccomment, docstyle_definition,
marker, indent, range):
Assembles a list of parsed documentation comment metadata.
This function just assembles the documentation comment
itself, without the markers and indentation.
>>> from coalib.bearlib.languages.documentation.DocumentationComment \
... import DocumentationComment
>>> from coalib.bearlib.languages.documentation.DocstyleDefinition \
... import DocstyleDefinition
>>> from coalib.results.TextRange import TextRange
>>> Description = DocumentationComment.Description
>>> Parameter = DocumentationComment.Parameter
>>> python_default = DocstyleDefinition.load("python3", "default")
>>> parsed_doc = [Description(desc='\nDescription\n'),
... Parameter(name='age', desc=' Age\n')]
>>> str(DocumentationComment.from_metadata(
... parsed_doc, python_default,
... python_default.markers[0], 4,
... TextRange.from_values(0, 0, 0, 0)))
'\nDescription\n:param age: Age\n'
:param doccomment:
The list of parsed documentation comment metadata.
:param docstyle_definition:
The ``DocstyleDefinition`` instance that defines what docstyle is
being used in a documentation comment.
:param marker:
The markers to be used in the documentation comment.
:param indent:
The indentation to be used in the documentation comment.
:param range:
The range of the documentation comment.
A ``DocumentationComment`` instance of the assembled documentation.
assembled_doc = ""
for section in doccomment:
section_desc = section.desc.splitlines(keepends=True)
if isinstance(section, cls.Parameter):
assembled_doc += (docstyle_definition.metadata.param_start + +
elif isinstance(section, cls.ReturnValue):
assembled_doc += docstyle_definition.metadata.return_sep
assembled_doc += ''.join(section_desc)
return DocumentationComment(assembled_doc, docstyle_definition, indent,
marker, range)
@@ -64,6 +64,22 @@ def test_not_implemented(self):
with self.assertRaises(NotImplementedError):
def test_from_metadata(self):
data = load_testdata("")
original = list(extract_documentation(data, "python", "default"))
parsed_docs = [(doc.parse(), doc.marker, doc.indent, doc.range)
for doc in original]
docstyle_definition = DocstyleDefinition.load("python", "default")
assembled_docs = [DocumentationComment.from_metadata(
doc[0], docstyle_definition, doc[1], doc[2], doc[3])
for doc in parsed_docs]
self.assertEqual(assembled_docs, original)
class PythonDocumentationCommentTest(DocumentationCommentTest):

0 comments on commit dc35a0a

Please sign in to comment.