8000 Added test to detect an issue with object construction. · pythonnet/pythonnet@cf2c27a · GitHub
[go: up one dir, main page]

Skip to content

Commit cf2c27a

Browse files
committed
Added test to detect an issue with object construction.
1 parent 7980fc4 commit cf2c27a

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/testing/subclasstest.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Collections.Generic;
33
using System.Threading;
44

5+
using Python.Runtime;
6+
57
namespace Python.Test
68
{
79
public interface IInterfaceTest
@@ -215,6 +217,30 @@ public static object InvokeCtor(Type t)
215217
return obj;
216218
}
217219

220+
public object TestObj { get; set; }
221+
222+
public static object TestOnType(Type t)
223+
{
224+
using (Py.GIL())
225+
{
226+
var obj = (SimpleClass) Activator.CreateInstance(t);
227+
//obj = obj.ToPython().As<SimpleClass>();
228+
obj.TestObj = new object();
229+
var py = obj.ToPython();
230+
var man = py.As<SimpleClass>();
231+
if (!ReferenceEquals(man, obj))
232+
throw new Exception("Same object expected");
233+
var setObj = py.GetAttr("TestObj").As<object>();
234+
if (setObj == null)
235+
throw new NullReferenceException();
236+
if (ReferenceEquals(setObj, obj.TestObj) == false)
237+
throw new Exception("!!");
238+
239+
240+
return obj;
241+
}
242+
}
243+
218244
public static void Pause()
219245
{
220246

tests/test_subclass.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,27 @@ class ClassWithAttributes3(ISimpleInterface, SimpleClass):
361361

362362
c = ClassWithAttributes2()
363363
c2 = ClassWithAttributes3()
364+
365+
def test_subclass_ctor():
366+
import clr
367+
class SubClass0(SimpleClass):
368+
pass
369+
class SubClass1(SubClass0):
370+
def __init__(self):
371+
super().__init__()
372+
class SubClass2(SubClass1):
373+
__namespace__ = "TestModule"
374+
def __init__(self):
375+
super().__init__()
376+
SimpleClass.TestOnType(SubClass0)
377+
SimpleClass.TestOnType(SubClass1)
378+
SimpleClass.TestOnType(SubClass2)
379+
364380
def test_more_subclasses():
365381
import clr
366-
class SubClass1(SimpleClass):
382+
class SubClass0(SimpleClass):
383+
pass
384+
class SubClass1(SubClass0):
367385
X = clr.property(Double, 1.0)
368386
def __init__(self):
369387
super().__init__()
@@ -379,6 +397,9 @@ def __init__(self):
379397
super().__init__()
380398
def IncrementThing(self):
381399
return 6;
400+
SimpleClass.TestOnType(SubClass0)
401+
SimpleClass.TestOnType(SubClass1)
402+
SimpleClass.TestOnType(SubClass2)
382403
obj = SimpleClass.InvokeCtor(SubClass2)
383404

384405
obj2 = SubClass2()

0 commit comments

Comments
 (0)
0