forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyimport.cs
More file actions
69 lines (62 loc) · 1.95 KB
/
pyimport.cs
File metadata and controls
69 lines (62 loc) · 1.95 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
65
66
67
68
69
using System;
using System.IO;
using NUnit.Framework;
using Python.Runtime;
namespace Python.EmbeddingTest
{
/// <summary>
/// Test Import unittests and regressions
/// </summary>
/// <remarks>
/// Keeping in old-style SetUp/TearDown due to required SetUp.
/// The required directory structure was added to .\pythonnet\src\tests\ directory:
/// + PyImportTest/
/// | - __init__.py
/// | + test/
/// | | - __init__.py
/// | | - one.py
/// </remarks>
[TestFixture]
public class PyImportTest
{
private IntPtr gs;
[SetUp]
public void SetUp()
{
PythonEngine.Initialize();
gs = PythonEngine.AcquireLock();
/* Append the tests directory to sys.path
* using reflection to circumvent the private
* modifiers placed on most Runtime methods. */
const string s = "../../tests";
string testPath = Path.Combine(TestContext.CurrentContext.TestDirectory, s);
IntPtr str = Runtime.Runtime.PyPyString_FromString(testPath);
IntPtr path = Runtime.Runtime.PyPySys_GetObject("path");
Runtime.Runtime.PyPyList_Append(path, str);
}
[TearDown]
public void TearDown()
{
PythonEngine.ReleaseLock(gs);
PythonEngine.Shutdown();
}
/// <summary>
/// Test subdirectory import
/// </summary>
[Test]
public void TestDottedName()
{
PyObject module = PythonEngine.ImportModule("PyImportTest.test.one");
Assert.IsNotNull(module);
}
/// <summary>
/// Tests that sys.args is set. If it wasn't exception would be raised.
/// </summary>
[Test]
public void TestSysArgsImportException()
{
PyObject module = PythonEngine.ImportModule("PyImportTest.sysargv");
Assert.IsNotNull(module);
}
}
}