Merge pull request #64 from rtfd/comment-parsing-fixes

Fix parsing issues with code comment XML
v0.5-alpha
Eric Holscher 8 years ago
commit 3a73a2c9c4

@ -276,8 +276,10 @@ class DotNetPythonMapper(PythonMapperBase):
param.get('description', ''))
})
self.returns = self.transform_doc_comments(
syntax.get('return', None))
self.returns = {}
self.returns['type'] = syntax.get('return', {}).get('type')
self.returns['description'] = self.transform_doc_comments(
syntax.get('return', {}).get('description'))
# Inheritance
# TODO Support more than just a class type here, should support enum/etc
@ -400,8 +402,19 @@ class DotNetPythonMapper(PythonMapperBase):
text_start = re.sub(r'(\S)$', r'\1 ', text_start)
text = ''.join([text_start, replacement, text_end])
text = DOC_COMMENT_PARAM_PATTERN.sub(
'``\g<attr_value>``', text)
while True:
found = DOC_COMMENT_PARAM_PATTERN.search(text)
if found is None:
break
# Escape following text
text_end = text[found.end():]
text_start = text[:found.start()]
text_end = re.sub(r'^(\S)', r'\\\1', text_end)
text_start = re.sub(r'(\S)$', r'\1 ', text_start)
text = ''.join([text_start, '``', found.group('attr_value'),
'``', text_end])
except TypeError:
pass
return text

@ -7,7 +7,7 @@ from mock import patch
from autoapi.mappers import dotnet
class DomainTests(unittest.TestCase):
class DotNetSphinxMapperTests(unittest.TestCase):
def setUp(self):
'''Test setup'''
@ -91,8 +91,11 @@ class DomainTests(unittest.TestCase):
self.assertEqual(objs['Foo.Bar2'].id, 'Foo.Bar2')
self.assertEqual(objs['Foo.Bar2'].name, 'Foo.Bar2')
class DotNetPythonMapperTests(unittest.TestCase):
def test_xml_parse(self):
'''XML doc comment parsing'''
"""XML doc comment parsing"""
ret = dotnet.DotNetPythonMapper.transform_doc_comments(
'This is an example comment <see cref="FOO" />')
self.assertEqual(ret, 'This is an example comment :any:`FOO`')
@ -117,6 +120,14 @@ class DomainTests(unittest.TestCase):
'This is an example comment <typeparamref name="FOO" />')
self.assertEqual(ret, 'This is an example comment ``FOO``')
ret = dotnet.DotNetPythonMapper.transform_doc_comments(
'With surrounding characters s<see cref="FOO" />s')
self.assertEqual(ret, 'With surrounding characters s :any:`FOO`\s')
ret = dotnet.DotNetPythonMapper.transform_doc_comments(
'With surrounding characters s<paramref name="FOO" />s')
self.assertEqual(ret, 'With surrounding characters s ``FOO``\s')
def test_xml_transform_escape(self):
"""XML transform escaping"""
ret = dotnet.DotNetPythonMapper.transform_doc_comments(
@ -126,3 +137,31 @@ class DomainTests(unittest.TestCase):
ret = dotnet.DotNetPythonMapper.transform_doc_comments(
'No space before<see cref="M:Foo`1" />or after')
self.assertEqual(ret, 'No space before :dn:meth:`Foo\\`1`\\or after')
def test_parsing_obj(self):
"""Parse out object, test for transforms, etc"""
obj = {
'uid': 'Foo`1',
'name': 'Foo<TUser>',
'summary': 'Test parsing <see cref="Bar" />',
'syntax': {
'parameters': [
{'id': 'a', 'type': '{TUser}',
'description': 'Test <see cref="TUser" />'}
],
'return': {
'type': 'Bar',
'description': ('Test references <see cref="Bar" /> '
'and paramrefs <paramref name="a" />'),
}
}
}
mapped = dotnet.DotNetPythonMapper(obj)
self.assertEqual(
mapped.parameters[0],
{'name': 'a', 'type': '{TUser}', 'desc': 'Test :any:`TUser`'}
)
self.assertEqual(
mapped.returns['description'],
'Test references :any:`Bar` and paramrefs ``a``'
)

Loading…
Cancel
Save