Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
Add tests for deriving a Python subclass from a generic interface
  • Loading branch information
filmor committed Nov 2, 2022
commit 461c9c708ce36a054c363700f232a1b5df09ed2e
23 changes: 22 additions & 1 deletion src/testing/interfacetest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private interface IPrivate
{
}
}

public interface IOutArg
{
string MyMethod_Out(string name, out int index);
Expand All @@ -93,4 +93,25 @@ public static int CallMyMethod_Out(IOutArg myInterface)
return index;
}
}

public interface IGenericInterface<T>
{
public T Get(T x);
}

public class SpecificInterfaceUser
{
public SpecificInterfaceUser(IGenericInterface<int> some, int x)
{
some.Get(x);
}
}

public class GenericInterfaceUser<T>
{
public GenericInterfaceUser(IGenericInterface<T> some, T x)
{
some.Get(x);
}
}
}
23 changes: 22 additions & 1 deletion tests/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import System
import pytest
from Python.Test import (IInterfaceTest, SubClassTest, EventArgsTest,
FunctionsTest)
FunctionsTest, IGenericInterface)
from System.Collections.Generic import List


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


def interface_generic_class_fixture(subnamespace):

class GenericInterfaceImpl(IGenericInterface[int]):
__namespace__ = "Python.Test." + subnamespace

def Get(self, x):
return x

return GenericInterfaceImpl


def derived_class_fixture(subnamespace):
"""Delay creation of class until test starts."""

Expand Down Expand Up @@ -306,3 +317,13 @@ class Derived(BaseClass):

import gc
gc.collect()

def test_generic_interface():
from System import Int32
from Python.Test import GenericInterfaceUser, SpecificInterfaceUser

GenericInterfaceImpl = interface_generic_class_fixture(test_generic_interface.__name__)

obj = GenericInterfaceImpl()
SpecificInterfaceUser(obj, Int32(0))
GenericInterfaceUser[Int32](obj, Int32(0))