-
Notifications
You must be signed in to change notification settings - Fork 774
Expand file tree
/
Copy pathTestNamedArguments.cs
More file actions
52 lines (40 loc) · 1.09 KB
/
TestNamedArguments.cs
File metadata and controls
52 lines (40 loc) · 1.09 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
using System;
using NUnit.Framework;
using Python.Runtime;
namespace Python.EmbeddingTest
{
public class TestNamedArguments
{
/// <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.That(result, Is.EqualTo(12));
}
/// <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.That(result, Is.EqualTo(12));
}
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);
return locals.GetItem("a");
}
}
}