forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestPyModule.cs
More file actions
50 lines (39 loc) · 1.12 KB
/
TestPyModule.cs
File metadata and controls
50 lines (39 loc) · 1.12 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
using NUnit.Framework;
using Python.Runtime;
namespace Python.EmbeddingTest
{
public class TestPyModule
{
[OneTimeSetUp]
public void SetUp()
{
PythonEngine.Initialize();
}
[OneTimeTearDown]
public void Dispose()
{
PythonEngine.Shutdown();
}
[Test]
public void TestCreate()
{
using PyScope scope = Py.CreateScope();
Assert.IsFalse(PyModule.SysModules.HasKey("testmod"));
PyModule testmod = new PyModule("testmod");
testmod.SetAttr("testattr1", "True".ToPython());
PyModule.SysModules.SetItem("testmod", testmod);
using PyObject code = PythonEngine.Compile(
"import testmod\n" +
"x = testmod.testattr1"
);
scope.Execute(code);
Assert.IsTrue(scope.TryGet("x", out dynamic x));
Assert.AreEqual("True", x.ToString());
}
[Test]
public void ImportClrNamespace()
{
Py.Import(typeof(TestPyModule).Namespace);
}
}
}