Skip to content

Commit 5f9a108

Browse files
author
Rickard Holmberg
committed
Add tests of subclassing with __namespace__
1 parent c8ae358 commit 5f9a108

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/tests/test_subclass.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,32 @@ def test_isinstance_check():
190190
for x in b:
191191
assert isinstance(x, System.Object)
192192
assert isinstance(x, System.String)
193+
194+
def test_clr_subclass_with_init_args():
195+
calls = []
196+
class TestX(System.Object):
197+
__namespace__ = "test_clr_subclass_with_init_args"
198+
def __init__(self, *args, **kwargs):
199+
calls.append((args, kwargs))
200+
t = TestX(1,2,3,foo="bar")
201+
assert len(calls) == 1
202+
assert calls[0][0] == (1,2,3)
203+
assert calls[0][1] == {"foo":"bar"}
204+
205+
def test_clr_subclass_without_init_args():
206+
calls = []
207+
class TestX(System.Object):
208+
__namespace__ = "test_clr_subclass_without_init_args"
209+
def __init__(self):
210+
calls.append(True)
211+
t = TestX()
212+
assert len(calls) == 1
213+
assert calls[0] == True
214+
215+
216+
def test_clr_subclass_without_init():
217+
class TestX(System.Object):
218+
__namespace__ = "test_clr_subclass_without_init"
219+
q = 1
220+
t = TestX()
221+
assert t.q == 1

0 commit comments

Comments
 (0)