forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestNamedArguments.cs
More file actions
64 lines (50 loc) · 1.3 KB
/
TestNamedArguments.cs
File metadata and controls
64 lines (50 loc) · 1.3 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
59
60
61
62
63
64
using System;
using NUnit.Framework;
using Python.Runtime;
namespace Python.EmbeddingTest
{
public class TestNamedArguments
{
[OneTimeSetUp]
public void SetUp()
{
PythonEngine.Initialize();
}
[OneTimeTearDown]
public void Dispose()
{
PythonEngine.Shutdown();
}
/// <summary>
/// Test named arguments support through Py.kw method
/// </summary>
[Test]
public void TestKeywordArgs()
{
dynamic a = CreateTestClass();
var result = (int)a.Test3(2, Py.kw("a4", 8));
Assert.AreEqual(12, result);
}
/// <summary>
/// Test keyword arguments with .net named arguments
/// </summary>
[Test]
public void TestNamedArgs()
{
dynamic a = CreateTestClass();
var result = (int)a.Test3(2, a4: 8);
Assert.AreEqual(12, result);
}
private static PyObject CreateTestClass()
{
var locals = new PyDict();
PythonEngine.Exec(@"
class cmTest3:
def Test3(self, a1 = 1, a2 = 1, a3 = 1, a4 = 1):
return a1 + a2 + a3 + a4
a = cmTest3()
", null, locals.Handle);
return locals.GetItem("a");
}
}
}