11using System ;
22using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
53using NUnit . Framework ;
64using Python . Runtime ;
75
86namespace Python . EmbeddingTest
97{
108 class QCTests
119 {
10+ private static dynamic pythonSuperInitInt ;
11+ private static dynamic pythonSuperInitDefault ;
12+ private static dynamic pythonSuperInitNone ;
13+ private static dynamic pythonSuperInitNotCallingBase ;
14+
15+ private static dynamic withArgs_PythonSuperInitNotCallingBase ;
16+ private static dynamic withArgs_PythonSuperInitDefault ;
17+ private static dynamic withArgs_PythonSuperInitInt ;
18+
1219 private static dynamic containsTest ;
1320 private static dynamic module ;
1421 private static string testModule = @"
1522from clr import AddReference
1623AddReference(""System"")
1724AddReference(""Python.EmbeddingTest"")
18- from Python.EmbeddingTest import Algo, Insight
25+ from Python.EmbeddingTest import *
1926class PythonModule(Algo):
2027 def TestA(self):
2128 try:
@@ -28,6 +35,34 @@ def ContainsTest(key, collection):
2835 if key in collection.Keys:
2936 return True
3037 return False
38+
39+ class WithArgs_PythonSuperInitNotCallingBase(SuperInit):
40+ def __init__(self, jose):
41+ return
42+
43+ class WithArgs_PythonSuperInitDefault(SuperInit):
44+ def __init__(self, jose):
45+ super().__init__()
46+
47+ class WithArgs_PythonSuperInitInt(SuperInit):
48+ def __init__(self, jose):
49+ super().__init__(jose)
50+
51+ class PythonSuperInitNotCallingBase(SuperInit):
52+ def __init__(self):
53+ return
54+
55+ class PythonSuperInitDefault(SuperInit):
56+ def __init__(self):
57+ super().__init__()
58+
59+ class PythonSuperInitInt(SuperInit):
60+ def __init__(self):
61+ super().__init__(1)
62+
63+ class PythonSuperInitNone(SuperInit):
64+ def jose(self):
65+ return 1
3166" ;
3267
3368 [ OneTimeSetUp ]
@@ -37,6 +72,15 @@ public void Setup()
3772 var pyModule = PyModule . FromString ( "module" , testModule ) ;
3873 containsTest = pyModule . GetAttr ( "ContainsTest" ) ;
3974 module = pyModule . GetAttr ( "PythonModule" ) . Invoke ( ) ;
75+
76+ pythonSuperInitInt = pyModule . GetAttr ( "PythonSuperInitInt" ) ;
77+ pythonSuperInitDefault = pyModule . GetAttr ( "PythonSuperInitDefault" ) ;
78+ pythonSuperInitNone = pyModule . GetAttr ( "PythonSuperInitNone" ) ;
79+ pythonSuperInitNotCallingBase = pyModule . GetAttr ( "PythonSuperInitNotCallingBase" ) ;
80+
81+ withArgs_PythonSuperInitNotCallingBase = pyModule . GetAttr ( "WithArgs_PythonSuperInitNotCallingBase" ) ;
82+ withArgs_PythonSuperInitDefault = pyModule . GetAttr ( "WithArgs_PythonSuperInitDefault" ) ;
83+ withArgs_PythonSuperInitInt = pyModule . GetAttr ( "WithArgs_PythonSuperInitInt" ) ;
4084 }
4185
4286 [ OneTimeTearDown ]
@@ -62,6 +106,87 @@ public void ContainsTest(string key, bool expected)
62106 var dic = new Dictionary < string , object > { { "SPY" , new object ( ) } } ;
63107 Assert . AreEqual ( expected , ( bool ) containsTest ( key , dic ) ) ;
64108 }
109+
110+ [ Test ]
111+ public void WithArgs_NoBaseConstructorCall ( )
112+ {
113+ using ( Py . GIL ( ) )
114+ {
115+ var instance = withArgs_PythonSuperInitNotCallingBase ( 1 ) ;
116+ // this is true because we call the constructor always
117+ Assert . IsTrue ( ( bool ) instance . CalledInt ) ;
118+ Assert . IsFalse ( ( bool ) instance . CalledDefault ) ;
119+ }
120+ }
121+
122+ [ Test ]
123+ public void WithArgs_IntConstructor ( )
124+ {
125+ using ( Py . GIL ( ) )
126+ {
127+ var instance = withArgs_PythonSuperInitInt ( 1 ) ;
128+ Assert . IsTrue ( ( bool ) instance . CalledInt ) ;
129+ Assert . IsFalse ( ( bool ) instance . CalledDefault ) ;
130+ }
131+ }
132+
133+ [ Test ]
134+ public void WithArgs_DefaultConstructor ( )
135+ {
136+ using ( Py . GIL ( ) )
137+ {
138+ var instance = withArgs_PythonSuperInitDefault ( 1 ) ;
139+ Assert . IsTrue ( ( bool ) instance . CalledInt ) ;
140+ Assert . IsTrue ( ( bool ) instance . CalledDefault ) ;
141+ }
142+ }
143+
144+ [ Test ]
145+ public void NoArgs_NoBaseConstructorCall ( )
146+ {
147+ using ( Py . GIL ( ) )
148+ {
149+ var instance = pythonSuperInitNotCallingBase ( ) ;
150+ Assert . IsFalse ( ( bool ) instance . CalledInt ) ;
151+ // this is true because we call the default constructor always
152+ Assert . IsTrue ( ( bool ) instance . CalledDefault ) ;
153+ }
154+ }
155+
156+ [ Test ]
157+ public void NoArgs_IntConstructor ( )
158+ {
159+ using ( Py . GIL ( ) )
160+ {
161+ var instance = pythonSuperInitInt ( ) ;
162+ Assert . IsTrue ( ( bool ) instance . CalledInt ) ;
163+ // this is true because we call the default constructor always
164+ Assert . IsTrue ( ( bool ) instance . CalledDefault ) ;
165+ }
166+ }
167+
168+ [ Test ]
169+ public void NoArgs_DefaultConstructor ( )
170+ {
171+ using ( Py . GIL ( ) )
172+ {
173+ var instance = pythonSuperInitNone ( ) ;
174+ Assert . IsFalse ( ( bool ) instance . CalledInt ) ;
175+ Assert . IsTrue ( ( bool ) instance . CalledDefault ) ;
176+ }
177+ }
178+
179+ [ Test ]
180+ public void NoArgs_NoConstructor ( )
181+ {
182+ using ( Py . GIL ( ) )
183+ {
184+ var instance = pythonSuperInitDefault . Invoke ( ) ;
185+
186+ Assert . IsFalse ( ( bool ) instance . CalledInt ) ;
187+ Assert . IsTrue ( ( bool ) instance . CalledDefault ) ;
188+ }
189+ }
65190 }
66191
67192 public class Algo
@@ -83,6 +208,20 @@ public void EmitInsights(params Insight[] insights)
83208
84209 }
85210
211+ public class SuperInit
212+ {
213+ public bool CalledInt { get ; private set ; }
214+ public bool CalledDefault { get ; private set ; }
215+ public SuperInit ( int a )
216+ {
217+ CalledInt = true ;
218+ }
219+ public SuperInit ( )
220+ {
221+ CalledDefault = true ;
222+ }
223+ }
224+
86225 public class Insight
87226 {
88227 public string info ;
0 commit comments