This repository was archived by the owner on Jul 22, 2023. It is now read-only.
forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestInstanceWrapping.cs
More file actions
58 lines (50 loc) · 1.73 KB
/
TestInstanceWrapping.cs
File metadata and controls
58 lines (50 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Globalization;
using NUnit.Framework;
using Python.Runtime;
namespace Python.EmbeddingTest
{
public class TestInstanceWrapping
{
[OneTimeSetUp]
public void SetUp()
{
PythonEngine.Initialize();
}
[OneTimeTearDown]
public void Dispose()
{
PythonEngine.Shutdown();
}
// regression test for https://github.com/pythonnet/pythonnet/issues/811
[Test]
public void OverloadResolution_UnknownToObject()
{
var overloaded = new Overloaded();
using (Py.GIL())
{
var o = overloaded.ToPython();
dynamic callWithSelf = PythonEngine.Eval("lambda o: o.ObjOrClass(object())");
callWithSelf(o);
Assert.AreEqual(Overloaded.Object, overloaded.Value);
}
}
class Base {}
class Derived: Base { }
class Overloaded: Derived
{
public int Value { get; set; }
public void IntOrStr(int arg) => this.Value = arg;
public void IntOrStr(string arg) =>
this.Value = int.Parse(arg, NumberStyles.Integer, CultureInfo.InvariantCulture);
public const int Object = 1;
public const int ConcreteClass = 2;
public void ObjOrClass(object _) => this.Value = Object;
public void ObjOrClass(Overloaded _) => this.Value = ConcreteClass;
public const int Base = ConcreteClass + 1;
public const int Derived = Base + 1;
public void BaseOrDerived(Base _) => this.Value = Base;
public void BaseOrDerived(Derived _) => this.Value = Derived;
}
}
}