-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDemoTests.cs
More file actions
62 lines (56 loc) · 1.67 KB
/
Copy pathDemoTests.cs
File metadata and controls
62 lines (56 loc) · 1.67 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
using System;
using System.IO;
using System.Reflection;
using NUnit.Framework;
using Python.Runtime;
namespace samples
{
[TestFixture]
public class DemoTests
{
[Test]
public void RunNumPy()
{
using (Py.GIL())
{
dynamic np = Py.Import("numpy");
dynamic sin = np.sin;
double value = sin(Math.PI / 2);
Assert.That(value, Is.EqualTo(1.00));
}
}
[Test]
public void RunCustomMethod()
{
string moduleDirectory = GetDllLocation();
using (Py.GIL())
{
dynamic syspy = Py.Import("sys");
syspy.path.append(moduleDirectory);
dynamic customModule = Py.Import("custom");
dynamic run = customModule.run;
string answer = run();
Assert.That(answer, Is.EqualTo("Hello from python"));
}
}
[Test]
public void RunCustomWithNumpyMethod()
{
string moduleDirectory = GetDllLocation();
using (Py.GIL())
{
dynamic syspy = Py.Import("sys");
syspy.path.append(moduleDirectory);
dynamic customModule = Py.Import("custom");
dynamic run = customModule.run_np_cos;
double result = run(0.0);
Assert.That(result, Is.EqualTo(1.0));
}
}
private string GetDllLocation()
{
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
return assemblyFolder;
}
}
}