3
3
using System . Collections . Generic ;
4
4
using NUnit . Framework ;
5
5
using Python . Runtime ;
6
+ using System . IO ;
6
7
7
8
namespace Python . EmbeddingTest
8
9
{
@@ -17,34 +18,19 @@ public void SetUp()
17
18
PythonEngine . Initialize ( ) ;
18
19
gs = PythonEngine . AcquireLock ( ) ;
19
20
20
- //string here = Environment.CurrentDirectory;
21
- //trunk\pythonnet\src\embed_tests\bin\x86\DebugWin
22
-
23
21
/*
24
22
* Append the tests directory to sys.path
25
23
* using reflection to circumvent the private modifires placed on most Runtime methods.
26
24
*/
27
25
const string s = @"../../../../tests" ;
28
26
29
- Type RTClass = typeof ( Runtime . Runtime ) ;
30
-
31
- /* pyStrPtr = PyString_FromString(s); */
32
- MethodInfo PyString_FromString = RTClass . GetMethod ( "PyString_FromString" ,
33
- BindingFlags . NonPublic | BindingFlags . Static ) ;
34
- object [ ] funcArgs = new object [ 1 ] ;
35
- funcArgs [ 0 ] = s ;
36
- IntPtr pyStrPtr = ( IntPtr ) PyString_FromString . Invoke ( null , funcArgs ) ;
37
-
38
- /* SysDotPath = sys.path */
39
- MethodInfo PySys_GetObject = RTClass . GetMethod ( "PySys_GetObject" ,
40
- BindingFlags . NonPublic | BindingFlags . Static ) ;
41
- funcArgs [ 0 ] = "path" ;
42
- IntPtr SysDotPath = ( IntPtr ) PySys_GetObject . Invoke ( null , funcArgs ) ;
27
+ var testPath = Path . Combine (
28
+ TestContext . CurrentContext . TestDirectory , s
29
+ ) ;
43
30
44
- /* SysDotPath.append(*pyStrPtr) */
45
- MethodInfo PyList_Append = RTClass . GetMethod ( "PyList_Append" , BindingFlags . NonPublic | BindingFlags . Static ) ;
46
- funcArgs = new object [ ] { SysDotPath , pyStrPtr } ;
47
- int r = ( int ) PyList_Append . Invoke ( null , funcArgs ) ;
31
+ IntPtr str = Runtime . Runtime . PyString_FromString ( testPath ) ;
32
+ IntPtr path = Runtime . Runtime . PySys_GetObject ( "path" ) ;
33
+ Runtime . Runtime . PyList_Append ( path , str ) ;
48
34
}
49
35
50
36
[ TearDown ]
0 commit comments