FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet-rawsvnmig/pythonnet/src/embed_tests/pyimport.cs at master · pythonnet/pythonnet-rawsvnmig · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Jun 4, 2019. It is now read-only.
pythonnet
/
pythonnet-rawsvnmig
Public archive
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet-rawsvnmig
/
pythonnet
/
src
/
embed_tests
/
pyimport.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (64 loc) · 2.45 KB
Breadcrumbs
pythonnet-rawsvnmig
/
pythonnet
/
src
/
embed_tests
/
pyimport.cs
Copy path
File metadata and controls
74 lines (64 loc) · 2.45 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
70
71
72
73
74
using
System
;
using
System
.
Reflection
;
using
System
.
Collections
.
Generic
;
using
NUnit
.
Framework
;
using
Python
.
Runtime
;
namespace
Python
.
EmbeddingTest
{
[
TestFixture
]
public
class
PyImportTest
{
private
IntPtr
gs
;
[
SetUp
]
public
void
SetUp
(
)
{
PythonEngine
.
Initialize
(
)
;
gs
=
PythonEngine
.
AcquireLock
(
)
;
//string here = Environment.CurrentDirectory;
//trunk\pythonnet\src\embed_tests\bin\x86\DebugWin
/*
* Append the tests directory to sys.path
* using reflection to circumvent the private modifires placed on most Runtime methods.
*/
const
string
s
=
@"../../../../tests"
;
Type
RTClass
=
typeof
(
Runtime
.
Runtime
)
;
/* pyStrPtr = PyString_FromString(s); */
MethodInfo
PyString_FromString
=
RTClass
.
GetMethod
(
"PyString_FromString"
,
BindingFlags
.
NonPublic
|
BindingFlags
.
Static
)
;
object
[
]
funcArgs
=
new
object
[
1
]
;
funcArgs
[
0
]
=
s
;
IntPtr
pyStrPtr
=
(
IntPtr
)
PyString_FromString
.
Invoke
(
null
,
funcArgs
)
;
/* SysDotPath = sys.path */
MethodInfo
PySys_GetObject
=
RTClass
.
GetMethod
(
"PySys_GetObject"
,
BindingFlags
.
NonPublic
|
BindingFlags
.
Static
)
;
funcArgs
[
0
]
=
"path"
;
IntPtr
SysDotPath
=
(
IntPtr
)
PySys_GetObject
.
Invoke
(
null
,
funcArgs
)
;
/* SysDotPath.append(*pyStrPtr) */
MethodInfo
PyList_Append
=
RTClass
.
GetMethod
(
"PyList_Append"
,
BindingFlags
.
NonPublic
|
BindingFlags
.
Static
)
;
funcArgs
=
new
object
[
]
{
SysDotPath
,
pyStrPtr
}
;
int
r
=
(
int
)
PyList_Append
.
Invoke
(
null
,
funcArgs
)
;
}
[
TearDown
]
public
void
TearDown
(
)
{
PythonEngine
.
ReleaseLock
(
gs
)
;
PythonEngine
.
Shutdown
(
)
;
}
/// <summary>
/// Test subdirectory import
/// </summary>
/// <remarks>
/// The required directory structure was added to the \trunk\pythonnet\src\tests directory:
///
/// PyImportTest/
/// __init__.py
/// test/
/// __init__.py
/// one.py
/// </remarks>
[
Test
]
public
void
TestDottedName
(
)
{
PyObject
module
=
PythonEngine
.
ImportModule
(
"PyImportTest.test.one"
)
;
Assert
.
IsNotNull
(
module
,
">>> import PyImportTest.test.one # FAILED"
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL