FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/embed_tests/NeedsReinit/TestRuntime.cs at just · pythonnet/pythonnet · GitHub
pythonnet
pythonnet
Repository navigation
Code
Issues
147
(147)
Pull requests
11
(11)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
NeedsReinit
/
TestRuntime.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
121 lines (101 loc) · 5.08 KB
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
NeedsReinit
/
TestRuntime.cs
Copy path
File metadata and controls
121 lines (101 loc) · 5.08 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using
System
;
using
System
.
Collections
.
Generic
;
using
NUnit
.
Framework
;
using
Python
.
Runtime
;
namespace
Python
.
EmbeddingTest
.
NeedsReinit
{
[
Ignore
(
"Tests for low-level Runtime functions, crashing currently"
)
]
public
class
TestRuntime
:
StopAndRestartEngine
{
[
Test
]
public
static
void
Py_IsInitializedValue
(
)
{
if
(
Runtime
.
Runtime
.
Py_IsInitialized
(
)
==
1
)
{
Runtime
.
Runtime
.
PyGILState_Ensure
(
)
;
}
Runtime
.
Runtime
.
Py_Finalize
(
)
;
Assert
.
That
(
Runtime
.
Runtime
.
Py_IsInitialized
(
)
,
Is
.
EqualTo
(
0
)
)
;
Runtime
.
Runtime
.
Py_Initialize
(
)
;
Assert
.
That
(
Runtime
.
Runtime
.
Py_IsInitialized
(
)
,
Is
.
EqualTo
(
1
)
)
;
Runtime
.
Runtime
.
Py_Finalize
(
)
;
Assert
.
That
(
Runtime
.
Runtime
.
Py_IsInitialized
(
)
,
Is
.
EqualTo
(
0
)
)
;
}
[
Test
]
public
static
void
RefCountTest
(
)
{
Runtime
.
Runtime
.
Py_Initialize
(
)
;
using
var
op
=
Runtime
.
Runtime
.
PyString_FromString
(
"FooBar"
)
;
// New object RefCount should be one
Assert
.
That
(
Runtime
.
Runtime
.
Refcount32
(
op
.
BorrowOrThrow
(
)
)
,
Is
.
EqualTo
(
1
)
)
;
// Checking refcount didn't change refcount
Assert
.
That
(
Runtime
.
Runtime
.
Refcount32
(
op
.
Borrow
(
)
)
,
Is
.
EqualTo
(
1
)
)
;
// Borrowing a reference doesn't increase refcount
BorrowedReference
p
=
op
.
Borrow
(
)
;
Assert
.
That
(
Runtime
.
Runtime
.
Refcount32
(
p
)
,
Is
.
EqualTo
(
1
)
)
;
// Py_IncRef/Py_DecRef increase and decrease RefCount
Runtime
.
Runtime
.
Py_IncRef
(
op
.
Borrow
(
)
)
;
Assert
.
That
(
Runtime
.
Runtime
.
Refcount32
(
p
)
,
Is
.
EqualTo
(
2
)
)
;
Runtime
.
Runtime
.
Py_DecRef
(
StolenReference
.
DangerousFromPointer
(
op
.
DangerousGetAddress
(
)
)
)
;
Assert
.
That
(
Runtime
.
Runtime
.
Refcount32
(
p
)
,
Is
.
EqualTo
(
1
)
)
;
// XIncref/XDecref increase and decrease RefCount
#pragma warning disable
CS0618
// Type or member is obsolete. We are testing corresponding members
Runtime
.
Runtime
.
XIncref
(
p
)
;
Assert
.
That
(
Runtime
.
Runtime
.
Refcount32
(
p
)
,
Is
.
EqualTo
(
2
)
)
;
Runtime
.
Runtime
.
XDecref
(
op
.
Steal
(
)
)
;
Assert
.
That
(
Runtime
.
Runtime
.
Refcount32
(
p
)
,
Is
.
EqualTo
(
1
)
)
;
#pragma warning restore
CS0618
// Type or member is obsolete
op
.
Dispose
(
)
;
Runtime
.
Runtime
.
Py_Finalize
(
)
;
}
[
Test
]
public
static
void
PyCheck_Iter_PyObject_IsIterable_Test
(
)
{
Runtime
.
Runtime
.
Py_Initialize
(
)
;
Runtime
.
Native
.
ABI
.
Initialize
(
Runtime
.
Runtime
.
PyVersion
)
;
// Tests that a python list is an iterable, but not an iterator
using
(
var
pyListNew
=
Runtime
.
Runtime
.
PyList_New
(
0
)
)
{
BorrowedReference
pyList
=
pyListNew
.
BorrowOrThrow
(
)
;
Assert
.
IsFalse
(
Runtime
.
Runtime
.
PyIter_Check
(
pyList
)
)
;
Assert
.
IsTrue
(
Runtime
.
Runtime
.
PyObject_IsIterable
(
pyList
)
)
;
// Tests that a python list iterator is both an iterable and an iterator
using
var
pyListIter
=
Runtime
.
Runtime
.
PyObject_GetIter
(
pyList
)
;
Assert
.
IsTrue
(
Runtime
.
Runtime
.
PyObject_IsIterable
(
pyListIter
.
BorrowOrThrow
(
)
)
)
;
Assert
.
IsTrue
(
Runtime
.
Runtime
.
PyIter_Check
(
pyListIter
.
Borrow
(
)
)
)
;
}
// Tests that a python float is neither an iterable nor an iterator
using
(
var
pyFloat
=
Runtime
.
Runtime
.
PyFloat_FromDouble
(
2.73
)
)
{
Assert
.
IsFalse
(
Runtime
.
Runtime
.
PyObject_IsIterable
(
pyFloat
.
BorrowOrThrow
(
)
)
)
;
Assert
.
IsFalse
(
Runtime
.
Runtime
.
PyIter_Check
(
pyFloat
.
Borrow
(
)
)
)
;
}
Runtime
.
Runtime
.
Py_Finalize
(
)
;
}
[
Test
]
public
static
void
PyCheck_Iter_PyObject_IsIterable_ThreadingLock_Test
(
)
{
Runtime
.
Runtime
.
Py_Initialize
(
)
;
Runtime
.
Native
.
ABI
.
Initialize
(
Runtime
.
Runtime
.
PyVersion
)
;
try
{
// Create an instance of threading.Lock, which is one of the very few types that does not have the
// TypeFlags.HaveIter set in Python 2. This tests a different code path in PyObject_IsIterable and PyIter_Check.
using
var
threading
=
Runtime
.
Runtime
.
PyImport_ImportModule
(
"threading"
)
;
BorrowedReference
threadingDict
=
Runtime
.
Runtime
.
PyModule_GetDict
(
threading
.
BorrowOrThrow
(
)
)
;
Exceptions
.
ErrorCheck
(
threadingDict
)
;
BorrowedReference
lockType
=
Runtime
.
Runtime
.
PyDict_GetItemString
(
threadingDict
,
"Lock"
)
;
if
(
lockType
.
IsNull
)
throw
PythonException
.
ThrowLastAsClrException
(
)
;
using
var
args
=
Runtime
.
Runtime
.
PyTuple_New
(
0
)
;
using
var
lockInstance
=
Runtime
.
Runtime
.
PyObject_CallObject
(
lockType
,
args
.
Borrow
(
)
)
;
Assert
.
IsFalse
(
Runtime
.
Runtime
.
PyObject_IsIterable
(
lockInstance
.
BorrowOrThrow
(
)
)
)
;
Assert
.
IsFalse
(
Runtime
.
Runtime
.
PyIter_Check
(
lockInstance
.
Borrow
(
)
)
)
;
}
finally
{
Runtime
.
Runtime
.
Py_Finalize
(
)
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL