FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/embed_tests/TestRuntime.cs at pythonnet-jupyter-notebook · sekkit/pythonnet · GitHub
sekkit
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
TestRuntime.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (43 loc) · 1.71 KB
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
TestRuntime.cs
Copy path
File metadata and controls
51 lines (43 loc) · 1.71 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
using
System
;
using
NUnit
.
Framework
;
using
Python
.
Runtime
;
namespace
Python
.
EmbeddingTest
{
public
class
TestRuntime
{
[
Test
]
public
static
void
Py_IsInitializedValue
(
)
{
Runtime
.
Runtime
.
Py_Finalize
(
)
;
// In case another test left it on.
Assert
.
AreEqual
(
0
,
Runtime
.
Runtime
.
Py_IsInitialized
(
)
)
;
Runtime
.
Runtime
.
Py_Initialize
(
)
;
Assert
.
AreEqual
(
1
,
Runtime
.
Runtime
.
Py_IsInitialized
(
)
)
;
Runtime
.
Runtime
.
Py_Finalize
(
)
;
Assert
.
AreEqual
(
0
,
Runtime
.
Runtime
.
Py_IsInitialized
(
)
)
;
}
[
Test
]
public
static
void
RefCountTest
(
)
{
Runtime
.
Runtime
.
Py_Initialize
(
)
;
IntPtr
op
=
Runtime
.
Runtime
.
PyUnicode_FromString
(
"FooBar"
)
;
// New object RefCount should be one
Assert
.
AreEqual
(
1
,
Runtime
.
Runtime
.
Refcount
(
op
)
)
;
// Checking refcount didn't change refcount
Assert
.
AreEqual
(
1
,
Runtime
.
Runtime
.
Refcount
(
op
)
)
;
// New reference doesn't increase refcount
IntPtr
p
=
op
;
Assert
.
AreEqual
(
1
,
Runtime
.
Runtime
.
Refcount
(
p
)
)
;
// Py_IncRef/Py_DecRef increase and decrease RefCount
Runtime
.
Runtime
.
Py_IncRef
(
op
)
;
Assert
.
AreEqual
(
2
,
Runtime
.
Runtime
.
Refcount
(
op
)
)
;
Runtime
.
Runtime
.
Py_DecRef
(
op
)
;
Assert
.
AreEqual
(
1
,
Runtime
.
Runtime
.
Refcount
(
op
)
)
;
// XIncref/XDecref increase and decrease RefCount
Runtime
.
Runtime
.
XIncref
(
op
)
;
Assert
.
AreEqual
(
2
,
Runtime
.
Runtime
.
Refcount
(
op
)
)
;
Runtime
.
Runtime
.
XDecref
(
op
)
;
Assert
.
AreEqual
(
1
,
Runtime
.
Runtime
.
Refcount
(
op
)
)
;
Runtime
.
Runtime
.
Py_Finalize
(
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL