Skip to content

Commit 461c9c7

Browse files
committed
Add tests for deriving a Python subclass from a generic interface
1 parent fb17907 commit 461c9c7

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/testing/interfacetest.cs

+22-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private interface IPrivate
7979
{
8080
}
8181
}
82-
82+
8383
public interface IOutArg
8484
{
8585
string MyMethod_Out(string name, out int index);
@@ -93,4 +93,25 @@ public static int CallMyMethod_Out(IOutArg myInterface)
9393
return index;
9494
}
9595
}
96+
97+
public interface IGenericInterface<T>
98+
{
99+
public T Get(T x);
100+
}
101+
102+
public class SpecificInterfaceUser
103+
{
104+
public SpecificInterfaceUser(IGenericInterface<int> some, int x)
105+
{
106+
some.Get(x);
107+
}
108+
}
109+
110+
public class GenericInterfaceUser<T>
111+
{
112+
public GenericInterfaceUser(IGenericInterface<T> some, T x)
113+
{
114+
some.Get(x);
115+
}
116+
}
96117
}

tests/test_subclass.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import System
1010
import pytest
1111
from Python.Test import (IInterfaceTest, SubClassTest, EventArgsTest,
12-
FunctionsTest)
12+
FunctionsTest, IGenericInterface)
1313
from System.Collections.Generic import List
1414

1515

@@ -29,6 +29,17 @@ def bar(self, x, i):
2929
return InterfaceTestClass
3030

3131

32+
def interface_generic_class_fixture(subnamespace):
33+
34+
class GenericInterfaceImpl(IGenericInterface[int]):
35+
__namespace__ = "Python.Test." + subnamespace
36+
37+
def Get(self, x):
38+
return x
39+
40+
return GenericInterfaceImpl
41+
42+
3243
def derived_class_fixture(subnamespace):
3344
"""Delay creation of class until test starts."""
3445

@@ -306,3 +317,13 @@ class Derived(BaseClass):
306317

307318
import gc
308319
gc.collect()
320+
321+
def test_generic_interface():
322+
from System import Int32
323+
from Python.Test import GenericInterfaceUser, SpecificInterfaceUser
324+
325+
GenericInterfaceImpl = interface_generic_class_fixture(test_generic_interface.__name__)
326+
327+
obj = GenericInterfaceImpl()
328+
SpecificInterfaceUser(obj, Int32(0))
329+
GenericInterfaceUser[Int32](obj, Int32(0))

0 commit comments

Comments
 (0)