2015-04-14 22:59:09 +00:00
|
|
|
'''Test .NET autoapi domain'''
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from mock import patch
|
|
|
|
|
2015-06-10 21:23:50 +00:00
|
|
|
from autoapi.mappers import dotnet
|
2015-04-14 22:59:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DomainTests(unittest.TestCase):
|
|
|
|
|
2015-06-01 19:37:22 +00:00
|
|
|
def setUp(self):
|
|
|
|
'''Test setup'''
|
2015-04-14 22:59:09 +00:00
|
|
|
class _config(object):
|
|
|
|
autoapi_dir = '/tmp/autoapi/tmp'
|
|
|
|
autoapi_root = '/tmp/autoapi/root'
|
|
|
|
|
|
|
|
class _application(object):
|
|
|
|
config = _config()
|
|
|
|
|
2015-06-01 19:37:22 +00:00
|
|
|
def warn(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
self.application = _application()
|
|
|
|
|
2015-04-14 22:59:09 +00:00
|
|
|
def test_create_class(self):
|
|
|
|
'''Test .NET class instance creation helper'''
|
2015-06-10 21:23:50 +00:00
|
|
|
dom = dotnet.DotNetSphinxMapper(self.application)
|
2015-06-10 18:48:15 +00:00
|
|
|
|
2015-06-01 19:37:22 +00:00
|
|
|
def _create_class(data):
|
|
|
|
return list(dom.create_class(data))[0]
|
|
|
|
cls = _create_class({'id': 'Foo.Bar', 'type': 'Namespace'})
|
2015-04-14 22:59:09 +00:00
|
|
|
self.assertIsInstance(cls, dotnet.DotNetNamespace)
|
2015-06-01 19:37:22 +00:00
|
|
|
cls = _create_class({'id': 'Foo.Bar', 'type': 'Class'})
|
2015-04-14 22:59:09 +00:00
|
|
|
self.assertIsInstance(cls, dotnet.DotNetClass)
|
2015-06-01 19:37:22 +00:00
|
|
|
cls = _create_class({'id': 'Foo.Bar', 'type': 'Property'})
|
2015-04-14 22:59:09 +00:00
|
|
|
self.assertIsInstance(cls, dotnet.DotNetProperty)
|
2015-06-01 19:37:22 +00:00
|
|
|
cls = _create_class({'id': 'Foo.Bar', 'type': 'Method'})
|
2015-04-14 22:59:09 +00:00
|
|
|
self.assertIsInstance(cls, dotnet.DotNetMethod)
|
2015-06-01 19:37:22 +00:00
|
|
|
cls = _create_class({'id': 'Foo.Bar', 'type': 'Enum'})
|
2015-04-14 22:59:09 +00:00
|
|
|
self.assertIsInstance(cls, dotnet.DotNetEnum)
|
2015-06-01 19:37:22 +00:00
|
|
|
cls = _create_class({'id': 'Foo.Bar', 'type': 'Constructor'})
|
2015-04-14 22:59:09 +00:00
|
|
|
self.assertIsInstance(cls, dotnet.DotNetConstructor)
|
2015-06-01 19:37:22 +00:00
|
|
|
cls = _create_class({'id': 'Foo.Bar', 'type': 'Struct'})
|
2015-04-14 22:59:09 +00:00
|
|
|
self.assertIsInstance(cls, dotnet.DotNetStruct)
|
2015-06-01 19:37:22 +00:00
|
|
|
cls = _create_class({'id': 'Foo.Bar', 'type': 'Interface'})
|
2015-04-14 22:59:09 +00:00
|
|
|
self.assertIsInstance(cls, dotnet.DotNetInterface)
|
2015-06-01 19:37:22 +00:00
|
|
|
cls = _create_class({'id': 'Foo.Bar', 'type': 'Delegate'})
|
2015-04-14 22:59:09 +00:00
|
|
|
self.assertIsInstance(cls, dotnet.DotNetDelegate)
|
2015-06-01 19:37:22 +00:00
|
|
|
cls = _create_class({'id': 'Foo.Bar', 'type': 'Field'})
|
2015-04-14 22:59:09 +00:00
|
|
|
self.assertIsInstance(cls, dotnet.DotNetField)
|
2015-06-01 19:37:22 +00:00
|
|
|
cls = _create_class({'id': 'Foo.Bar', 'type': 'Event'})
|
2015-04-14 22:59:09 +00:00
|
|
|
self.assertIsInstance(cls, dotnet.DotNetEvent)
|
|
|
|
|
|
|
|
def test_create_class_with_children(self):
|
2015-06-10 21:23:50 +00:00
|
|
|
dom = dotnet.DotNetSphinxMapper(self.application)
|
2015-06-10 18:48:15 +00:00
|
|
|
|
2015-06-01 19:37:22 +00:00
|
|
|
def _create_class(data):
|
|
|
|
return list(dom.create_class(data))[0]
|
|
|
|
cls = _create_class({'id': 'Foo.Bar',
|
|
|
|
'type': 'Class',
|
|
|
|
'items': [
|
|
|
|
{'id': 'Foo.Bar.Baz',
|
|
|
|
'type': 'Method'}
|
|
|
|
]})
|
2015-04-14 22:59:09 +00:00
|
|
|
self.assertIsInstance(cls, dotnet.DotNetClass)
|
2015-04-14 23:54:43 +00:00
|
|
|
self.assertDictEqual(cls.item_map, {})
|
2015-04-14 22:59:09 +00:00
|
|
|
|
2015-08-03 22:05:33 +00:00
|
|
|
@patch('subprocess.check_output', lambda foo: foo)
|
2015-04-14 22:59:09 +00:00
|
|
|
def test_get_objects(self):
|
|
|
|
'''Test basic get objects'''
|
|
|
|
objs = []
|
|
|
|
|
2015-08-05 17:27:35 +00:00
|
|
|
def _mock_find(self, patterns, **kwargs):
|
|
|
|
return {'items': ['foo', 'bar']}
|
|
|
|
|
|
|
|
def _mock_read(self, path):
|
|
|
|
return {'items': [{'id': 'Foo.Bar', 'name': 'Foo', 'type': 'property'},
|
|
|
|
{'id': 'Foo.Bar2', 'name': 'Bar', 'type': 'property'}],
|
|
|
|
'id': 'Foo.Bar', 'type': 'Class', 'summary': path}
|
|
|
|
|
|
|
|
with patch('autoapi.mappers.dotnet.DotNetSphinxMapper.find_files', _mock_find):
|
|
|
|
with patch('autoapi.mappers.dotnet.DotNetSphinxMapper.read_file', _mock_read):
|
|
|
|
dom = dotnet.DotNetSphinxMapper(self.application)
|
|
|
|
dom.load('', '', '', raise_error=False)
|
|
|
|
dom.map()
|
|
|
|
objs = dom.objects
|
|
|
|
self.assertEqual(len(objs), 2)
|
|
|
|
self.assertEqual(objs['Foo.Bar'].id, 'Foo.Bar')
|
|
|
|
self.assertEqual(objs['Foo.Bar'].name, 'Foo.Bar')
|
|
|
|
self.assertEqual(objs['Foo.Bar2'].id, 'Foo.Bar2')
|
|
|
|
self.assertEqual(objs['Foo.Bar2'].name, 'Foo.Bar2')
|
2015-08-17 21:04:07 +00:00
|
|
|
|
|
|
|
def test_xml_parse(self):
|
|
|
|
'''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 :dn:ref:`FOO`')
|
|
|
|
|
|
|
|
ret = dotnet.DotNetPythonMapper.transform_doc_comments(
|
|
|
|
'This is an example comment <see cref="FOO">inner foo</see>')
|
|
|
|
self.assertEqual(ret, 'This is an example comment :dn:ref:`FOO`')
|
|
|
|
|
|
|
|
ret = dotnet.DotNetPythonMapper.transform_doc_comments(
|
|
|
|
'Test <see cref="FOO" /> and <see cref="BAR">Blah</see>')
|
|
|
|
self.assertEqual(ret, 'Test :dn:ref:`FOO` and :dn:ref:`BAR`')
|
|
|
|
|
|
|
|
ret = dotnet.DotNetPythonMapper.transform_doc_comments(
|
|
|
|
'This is an example comment <paramref name="FOO" />')
|
|
|
|
self.assertEqual(ret, 'This is an example comment ``FOO``')
|
|
|
|
|
|
|
|
ret = dotnet.DotNetPythonMapper.transform_doc_comments(
|
|
|
|
'This is an example comment <typeparamref name="FOO" />')
|
|
|
|
self.assertEqual(ret, 'This is an example comment ``FOO``')
|