Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests constructing python type from CLR and calling __init__
  • Loading branch information
Rickard Holmberg committed Jun 21, 2017
commit 6e78a42457aed62a52c0f913fa17f9268b828ec7
27 changes: 27 additions & 0 deletions src/tests/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,30 @@ class TestX(System.Object):
q = 1
t = TestX()
assert t.q == 1

def test_clr_subclass_init_from_clr():
import clr
calls = []
class TestX(System.Object):
__namespace__ = "test_clr_subclass_init_from_clr"
@clr.clrmethod(None, [int, str])
def __init__(self, i, s):
calls.append((i, s))

# Construct a TestX from Python
t = TestX(1, "foo")
assert len(calls) == 1
assert calls[0][0] == 1
assert calls[0][1] == "foo"

# Reset calls and construct a TestX from CLR
calls = []
tp = t.GetType()
t2 = tp.GetConstructors()[0].Invoke(None)
assert len(calls) == 0

# The object has only been constructed, now it needs to be initialized as well
tp.GetMethod("__init__").Invoke(t2, [1, "foo"])
assert len(calls) == 1
assert calls[0][0] == 1
assert calls[0][1] == "foo"