2015-08-19 01:10:25 +00:00
|
|
|
# coding=utf8
|
|
|
|
|
2015-04-14 22:59:09 +00:00
|
|
|
'''Test .NET autoapi objects'''
|
|
|
|
|
2015-08-19 01:18:54 +00:00
|
|
|
import os
|
2015-04-14 22:59:09 +00:00
|
|
|
import unittest
|
2016-11-02 23:29:28 +00:00
|
|
|
from collections import namedtuple
|
2015-04-14 22:59:09 +00:00
|
|
|
|
2015-10-27 07:46:59 +00:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
|
2015-06-10 21:23:50 +00:00
|
|
|
from autoapi.mappers import dotnet
|
2016-11-02 23:29:28 +00:00
|
|
|
from autoapi.mappers import python
|
2015-10-27 07:46:59 +00:00
|
|
|
from autoapi.settings import TEMPLATE_DIR
|
2015-04-14 22:59:09 +00:00
|
|
|
|
|
|
|
|
2015-10-27 18:13:08 +00:00
|
|
|
class DotNetObjectTests(unittest.TestCase):
|
2015-04-14 22:59:09 +00:00
|
|
|
|
2015-04-14 23:54:43 +00:00
|
|
|
def test_type(self):
|
|
|
|
'''Test types of some of the objects'''
|
|
|
|
obj = dotnet.DotNetNamespace({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(obj.type, 'namespace')
|
2015-04-15 01:05:15 +00:00
|
|
|
self.assertEqual(obj.ref_type, 'namespace')
|
|
|
|
self.assertEqual(obj.ref_directive, 'ns')
|
2015-04-14 23:54:43 +00:00
|
|
|
|
|
|
|
obj = dotnet.DotNetMethod({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(obj.type, 'method')
|
2015-04-15 01:05:15 +00:00
|
|
|
self.assertEqual(obj.ref_type, 'method')
|
|
|
|
self.assertEqual(obj.ref_directive, 'meth')
|
|
|
|
|
|
|
|
obj = dotnet.DotNetProperty({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(obj.type, 'property')
|
|
|
|
self.assertEqual(obj.ref_type, 'property')
|
|
|
|
self.assertEqual(obj.ref_directive, 'prop')
|
|
|
|
|
|
|
|
obj = dotnet.DotNetEnum({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(obj.type, 'enum')
|
|
|
|
self.assertEqual(obj.ref_type, 'enumeration')
|
|
|
|
self.assertEqual(obj.ref_directive, 'enum')
|
|
|
|
|
|
|
|
obj = dotnet.DotNetStruct({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(obj.type, 'struct')
|
|
|
|
self.assertEqual(obj.ref_type, 'structure')
|
|
|
|
self.assertEqual(obj.ref_directive, 'struct')
|
|
|
|
|
|
|
|
obj = dotnet.DotNetConstructor({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(obj.type, 'constructor')
|
|
|
|
self.assertEqual(obj.ref_type, 'constructor')
|
|
|
|
self.assertEqual(obj.ref_directive, 'ctor')
|
|
|
|
|
|
|
|
obj = dotnet.DotNetInterface({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(obj.type, 'interface')
|
|
|
|
self.assertEqual(obj.ref_type, 'interface')
|
|
|
|
self.assertEqual(obj.ref_directive, 'iface')
|
|
|
|
|
|
|
|
obj = dotnet.DotNetDelegate({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(obj.type, 'delegate')
|
|
|
|
self.assertEqual(obj.ref_type, 'delegate')
|
|
|
|
self.assertEqual(obj.ref_directive, 'del')
|
2015-04-14 23:54:43 +00:00
|
|
|
|
|
|
|
obj = dotnet.DotNetClass({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(obj.type, 'class')
|
2015-04-15 01:05:15 +00:00
|
|
|
self.assertEqual(obj.ref_type, 'class')
|
|
|
|
self.assertEqual(obj.ref_directive, 'cls')
|
|
|
|
|
|
|
|
obj = dotnet.DotNetField({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(obj.type, 'field')
|
|
|
|
self.assertEqual(obj.ref_type, 'field')
|
|
|
|
self.assertEqual(obj.ref_directive, 'field')
|
|
|
|
|
|
|
|
obj = dotnet.DotNetEvent({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(obj.type, 'event')
|
|
|
|
self.assertEqual(obj.ref_type, 'event')
|
|
|
|
self.assertEqual(obj.ref_directive, 'event')
|
|
|
|
|
2015-04-14 23:54:43 +00:00
|
|
|
def test_names(self):
|
|
|
|
'''Test names of objects'''
|
|
|
|
obj = dotnet.DotNetNamespace({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(obj.name, 'Foo.Bar')
|
|
|
|
self.assertEqual(obj.short_name, 'Bar')
|
|
|
|
|
|
|
|
obj = dotnet.DotNetNamespace({'id': 'Foo.Bar.Something`1'})
|
|
|
|
self.assertEqual(obj.name, 'Foo.Bar.Something`1')
|
|
|
|
self.assertEqual(obj.short_name, 'Something`1')
|
|
|
|
|
2015-04-14 22:59:09 +00:00
|
|
|
def test_namespace_namespace(self):
|
|
|
|
'''Namespace parent resolution'''
|
2015-04-14 23:54:43 +00:00
|
|
|
ns = dotnet.DotNetNamespace({'id': 'Foo.Bar.Widgets'})
|
|
|
|
self.assertEqual(ns.namespace, 'Foo.Bar')
|
|
|
|
ns = dotnet.DotNetNamespace({'id': 'Foo.Bar'})
|
|
|
|
self.assertEqual(ns.namespace, 'Foo')
|
|
|
|
ns = dotnet.DotNetNamespace({'id': 'Foo'})
|
|
|
|
self.assertIsNone(ns.namespace)
|
2015-04-14 22:59:09 +00:00
|
|
|
|
|
|
|
def test_class_namespace(self):
|
|
|
|
'''Class parent resolution'''
|
|
|
|
cls = dotnet.DotNetClass(dict(id='Foo.Bar.Widget',
|
|
|
|
type='class'))
|
2015-04-14 23:54:43 +00:00
|
|
|
self.assertEqual(cls.namespace, 'Foo.Bar')
|
2015-04-14 22:59:09 +00:00
|
|
|
cls = dotnet.DotNetClass(dict(id='Foo.Bar',
|
|
|
|
type='class'))
|
2015-04-14 23:54:43 +00:00
|
|
|
self.assertEqual(cls.namespace, 'Foo')
|
2015-04-14 22:59:09 +00:00
|
|
|
cls = dotnet.DotNetClass(dict(id='Foo',
|
|
|
|
type='class'))
|
2015-04-14 23:54:43 +00:00
|
|
|
self.assertIsNone(cls.namespace)
|
2015-08-19 01:10:25 +00:00
|
|
|
|
|
|
|
def test_filename(self):
|
|
|
|
'''Object file name'''
|
|
|
|
cls = dotnet.DotNetClass({'id': 'Foo.Bar.Widget'})
|
2015-08-19 01:18:54 +00:00
|
|
|
self.assertEqual(cls.pathname, os.path.join('Foo', 'Bar', 'Widget'))
|
2015-08-19 01:10:25 +00:00
|
|
|
cls = dotnet.DotNetClass({'id': 'Foo.Bar.Widget<T>'})
|
2015-08-19 01:18:54 +00:00
|
|
|
self.assertEqual(cls.pathname, os.path.join('Foo', 'Bar', 'Widget-T'))
|
2015-08-19 01:10:25 +00:00
|
|
|
cls = dotnet.DotNetClass({'id': 'Foo.Bar.Widget<T>(TFoo)'})
|
2015-08-19 01:18:54 +00:00
|
|
|
self.assertEqual(cls.pathname, os.path.join('Foo', 'Bar', 'Widget-T'))
|
2015-08-19 01:10:25 +00:00
|
|
|
cls = dotnet.DotNetClass({'id': 'Foo.Foo-Bar.Widget<T>(TFoo)'})
|
2015-08-19 01:18:54 +00:00
|
|
|
self.assertEqual(cls.pathname, os.path.join('Foo', 'FooBar', 'Widget-T'))
|
2015-08-19 01:10:25 +00:00
|
|
|
cls = dotnet.DotNetClass({'id': u'Foo.Bär'})
|
2015-08-19 01:18:54 +00:00
|
|
|
self.assertEqual(cls.pathname, os.path.join('Foo', 'Bar'))
|
2015-08-19 01:10:25 +00:00
|
|
|
cls = dotnet.DotNetClass({'id': u'Ащщ.юИфк'})
|
2015-08-19 01:18:54 +00:00
|
|
|
self.assertEqual(cls.pathname, os.path.join('Ashchshch', 'iuIfk'))
|
2015-10-27 07:46:59 +00:00
|
|
|
|
|
|
|
def test_rendered_class_escaping(self):
|
|
|
|
"""Rendered class escaping"""
|
|
|
|
jinja_env = Environment(
|
|
|
|
loader=FileSystemLoader([TEMPLATE_DIR]),
|
|
|
|
)
|
|
|
|
cls = dotnet.DotNetClass(
|
|
|
|
{
|
|
|
|
'id': 'Foo.Bar`1',
|
|
|
|
'inheritance': ['Foo.Baz`1'],
|
|
|
|
},
|
|
|
|
jinja_env=jinja_env)
|
|
|
|
self.assertIn('* :dn:cls:`Foo.Baz\\`1`\n', cls.render())
|
2015-10-27 18:13:08 +00:00
|
|
|
|
|
|
|
def test_include_path(self):
|
|
|
|
"""Include path"""
|
|
|
|
cls = dotnet.DotNetClass({'id': 'Foo.Bar.Widget'})
|
|
|
|
self.assertEqual(cls.include_path, '/autoapi/Foo/Bar/Widget/index')
|
|
|
|
cls = dotnet.DotNetClass({'id': 'Foo.Bar.Widget'}, url_root='/autofoo')
|
|
|
|
self.assertEqual(cls.include_path, '/autofoo/Foo/Bar/Widget/index')
|