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