@@ -191,7 +191,7 @@ def test_isinstance_check():
191191 assert isinstance (x , System .Object )
192192 assert isinstance (x , System .String )
193193
194- def test_clr_subclass_with_init_args ():
194+ def test_namespace_and_init ():
195195 calls = []
196196 class TestX (System .Object ):
197197 __namespace__ = "test_clr_subclass_with_init_args"
@@ -202,7 +202,7 @@ def __init__(self, *args, **kwargs):
202202 assert calls [0 ][0 ] == (1 ,2 ,3 )
203203 assert calls [0 ][1 ] == {"foo" :"bar" }
204204
205- def test_clr_subclass_without_init_args ():
205+ def test_namespace_and_argless_init ():
206206 calls = []
207207 class TestX (System .Object ):
208208 __namespace__ = "test_clr_subclass_without_init_args"
@@ -213,9 +213,36 @@ def __init__(self):
213213 assert calls [0 ] == True
214214
215215
216- def test_clr_subclass_without_init ():
216+ def test_namespace_and_no_init ():
217217 class TestX (System .Object ):
218218 __namespace__ = "test_clr_subclass_without_init"
219219 q = 1
220220 t = TestX ()
221221 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