@@ -191,7 +191,7 @@ def test_isinstance_check():
191
191
assert isinstance (x , System .Object )
192
192
assert isinstance (x , System .String )
193
193
194
- def test_clr_subclass_with_init_args ():
194
+ def test_namespace_and_init ():
195
195
calls = []
196
196
class TestX (System .Object ):
197
197
__namespace__ = "test_clr_subclass_with_init_args"
@@ -202,7 +202,7 @@ def __init__(self, *args, **kwargs):
202
202
assert calls [0 ][0 ] == (1 ,2 ,3 )
203
203
assert calls [0 ][1 ] == {"foo" :"bar" }
204
204
205
- def test_clr_subclass_without_init_args ():
205
+ def test_namespace_and_argless_init ():
206
206
calls = []
207
207
class TestX (System .Object ):
208
208
__namespace__ = "test_clr_subclass_without_init_args"
@@ -213,9 +213,36 @@ def __init__(self):
213
213
assert calls [0 ] == True
214
214
215
215
216
- def test_clr_subclass_without_init ():
216
+ def test_namespace_and_no_init ():
217
217
class TestX (System .Object ):
218
218
__namespace__ = "test_clr_subclass_without_init"
219
219
q = 1
220
220
t = TestX ()
221
221
assert t .q == 1
222
+
223
+ def test_construction_from_clr ():
224
+ import clr
225
+ calls = []
226
+ class TestX (System .Object ):
227
+ __namespace__ = "test_clr_subclass_init_from_clr"
228
+ @clr .clrmethod (None , [int , str ])
229
+ def __init__ (self , i , s ):
230
+ calls .append ((i , s ))
231
+
232
+ # Construct a TestX from Python
233
+ t = TestX (1 , "foo" )
234
+ assert len (calls ) == 1
235
+ assert calls [0 ][0 ] == 1
236
+ assert calls [0 ][1 ] == "foo"
237
+
238
+ # Reset calls and construct a TestX from CLR
239
+ calls = []
240
+ tp = t .GetType ()
241
+ t2 = tp .GetConstructors ()[0 ].Invoke (None )
242
+ assert len (calls ) == 0
243
+
244
+ # The object has only been constructed, now it needs to be initialized as well
245
+ tp .GetMethod ("__init__" ).Invoke (t2 , [1 , "foo" ])
246
+ assert len (calls ) == 1
247
+ assert calls [0 ][0 ] == 1
248
+ assert calls [0 ][1 ] == "foo"
0 commit comments