|
| 1 | +using NUnit.Framework; |
| 2 | +using Python.Runtime; |
| 3 | + |
| 4 | +namespace Python.EmbeddingTest |
| 5 | +{ |
| 6 | + public class TestInterfaceClasses |
| 7 | + { |
| 8 | + public string testCode = @" |
| 9 | +from clr import AddReference |
| 10 | +AddReference(""System"") |
| 11 | +AddReference(""Python.EmbeddingTest"") |
| 12 | +from Python.EmbeddingTest import * |
| 13 | +
|
| 14 | +testModule = TestInterfaceClasses.GetInstance() |
| 15 | +print(testModule.Child.ChildBool) |
| 16 | +
|
| 17 | +"; |
| 18 | + |
| 19 | + [OneTimeSetUp] |
| 20 | + public void SetUp() |
| 21 | + { |
| 22 | + PythonEngine.Initialize(); |
| 23 | + } |
| 24 | + |
| 25 | + [OneTimeTearDown] |
| 26 | + public void Dispose() |
| 27 | + { |
| 28 | + PythonEngine.Shutdown(); |
| 29 | + } |
| 30 | + |
| 31 | + [Test] |
| 32 | + public void TestInterfaceDerivedClassMembers() |
| 33 | + { |
| 34 | + // This test gets an instance of the CSharpTestModule in Python |
| 35 | + // and then attempts to access it's member "Child"'s bool that is |
| 36 | + // not defined in the interface. |
| 37 | + PythonEngine.Exec(testCode); |
| 38 | + } |
| 39 | + |
| 40 | + public interface IInterface |
| 41 | + { |
| 42 | + bool InterfaceBool { get; set; } |
| 43 | + } |
| 44 | + |
| 45 | + public class Parent : IInterface |
| 46 | + { |
| 47 | + public bool InterfaceBool { get; set; } |
| 48 | + public bool ParentBool { get; set; } |
| 49 | + } |
| 50 | + |
| 51 | + public class Child : Parent |
| 52 | + { |
| 53 | + public bool ChildBool { get; set; } |
| 54 | + } |
| 55 | + |
| 56 | + public class CSharpTestModule |
| 57 | + { |
| 58 | + public IInterface Child; |
| 59 | + |
| 60 | + public CSharpTestModule() |
| 61 | + { |
| 62 | + Child = new Child |
| 63 | + { |
| 64 | + ChildBool = true, |
| 65 | + ParentBool = true, |
| 66 | + InterfaceBool = true |
| 67 | + }; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + public static CSharpTestModule GetInstance() |
| 72 | + { |
| 73 | + return new CSharpTestModule(); |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments