Skip to content

Commit 0032aad

Browse files
committed
python 增加 NestedTypesTestPython 用例
1 parent 63d3385 commit 0032aad

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#if !UNITY_WEBGL && !UNITY_IOS && !UNITY_ANDROID || FORCE_TEST_PYTHON
2+
using System;
3+
4+
namespace Puerts.UnitTest
5+
{
6+
[UnityEngine.Scripting.Preserve]
7+
public class TestNestedTypes
8+
{
9+
[UnityEngine.Scripting.Preserve]
10+
public class InnerClassA
11+
{
12+
public string Foo { get; set; } = "Hello";
13+
14+
public class NestedInnerClassA
15+
{
16+
public string Baz { get; set; } = "Hello";
17+
}
18+
}
19+
[UnityEngine.Scripting.Preserve]
20+
public class InnerClassB
21+
{
22+
public string Bar { get; set; } = "Hello";
23+
}
24+
[UnityEngine.Scripting.Preserve]
25+
public class InnerClassB<T>
26+
{
27+
public string Bar { get; set; } = "Hello";
28+
}
29+
[UnityEngine.Scripting.Preserve]
30+
public class InnerClassB<T1, T2>
31+
{
32+
public string Bar { get; set; } = "Hello";
33+
}
34+
}
35+
36+
[TestFixture]
37+
public class NestedTypesTestPython
38+
{
39+
[Test]
40+
public void TestNestedTypeInstantiation()
41+
{
42+
var pythonEnv = new ScriptEnv(new BackendPython());
43+
pythonEnv.Eval(@"
44+
exec('''
45+
import Puerts.UnitTest.TestHelper as TestHelper
46+
assertAndPrint = TestHelper.AssertAndPrint
47+
from System import Console, Int32, String
48+
import Puerts.UnitTest.TestNestedTypes as TestNestedTypes
49+
# ['Equals', 'InnerClassA', 'InnerClassB', 'InnerClassB__T1', 'InnerClassB__T2', 'ReferenceEquals', '__class__', '__context_puerts__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__loader__', '__lt__', '__module__', '__ne__', '__new__', '__package__', '__path__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__spec__', '__str__', '__subclasshook__', '_p_innerType', 'call_method']
50+
assertAndPrint('TestNestedTypeInstantiation Python TestNestedTypes members', str(dir(TestNestedTypes)), str([
51+
'Equals', 'InnerClassA', 'InnerClassB', 'InnerClassB__T1', 'InnerClassB__T2',
52+
'ReferenceEquals', '__class__', '__context_puerts__', '__delattr__', '__dir__',
53+
'__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__',
54+
'__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__loader__',
55+
'__lt__', '__module__', '__ne__', '__new__', '__package__', '__path__',
56+
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__',
57+
'__spec__', '__subclasshook__', '_p_innerType', 'call_method'
58+
]))
59+
InnerClassA = TestNestedTypes.InnerClassA
60+
NestedInnerClassA = TestNestedTypes.InnerClassA.NestedInnerClassA
61+
InnerClassB = TestNestedTypes.InnerClassB
62+
InnerClassB__T1 = puerts.generic(TestNestedTypes.InnerClassB, Int32)
63+
InnerClassB__T2 = puerts.generic(TestNestedTypes.InnerClassB, Int32, String)
64+
x = InnerClassA()
65+
r = NestedInnerClassA()
66+
o = InnerClassB()
67+
y = InnerClassB__T1()
68+
z = InnerClassB__T2()
69+
70+
assertAndPrint('TestNestedTypeInstantiation Python InnerClassA', x.Foo, 'Hello')
71+
assertAndPrint('TestNestedTypeInstantiation Python NestedInnerClassA', r.Baz, 'Hello')
72+
assertAndPrint('TestNestedTypeInstantiation Python InnerClassB', o.Bar, 'Hello')
73+
assertAndPrint('TestNestedTypeInstantiation Python InnerClassB_T1', y.Bar, 'Hello')
74+
assertAndPrint('TestNestedTypeInstantiation Python InnerClassB_T2', z.Bar, 'Hello')
75+
''')
76+
");
77+
pythonEnv.Dispose();
78+
}
79+
}
80+
}
81+
#endif

unity/test/Src/Cases/Python/NestedTypesTest.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)