FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/embed_tests/TestPyList.cs at drop-python2 · filmor/pythonnet · GitHub
filmor
/
pythonnet
Public
forked from
pythonnet/pythonnet
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
TestPyList.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
172 lines (141 loc) · 4.46 KB
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
TestPyList.cs
Copy path
File metadata and controls
172 lines (141 loc) · 4.46 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using
System
;
using
System
.
Collections
.
Generic
;
using
NUnit
.
Framework
;
using
Python
.
Runtime
;
namespace
Python
.
EmbeddingTest
{
public
class
TestPyList
{
[
OneTimeSetUp
]
public
void
SetUp
(
)
{
PythonEngine
.
Initialize
(
)
;
}
[
OneTimeTearDown
]
public
void
Dispose
(
)
{
PythonEngine
.
Shutdown
(
)
;
}
[
Test
]
public
void
TestStringIsListType
(
)
{
var
s
=
new
PyString
(
"foo"
)
;
Assert
.
False
(
PyList
.
IsListType
(
s
)
)
;
}
[
Test
]
public
void
TestListIsListType
(
)
{
var
s
=
new
PyList
(
)
;
Assert
.
True
(
PyList
.
IsListType
(
s
)
)
;
}
[
Test
]
public
void
TestStringAsListType
(
)
{
var
i
=
new
PyInt
(
5
)
;
PyList
t
=
null
;
var
ex
=
Assert
.
Throws
<
PythonException
>
(
(
)
=>
t
=
PyList
.
AsList
(
i
)
)
;
Assert
.
AreEqual
(
"TypeError : 'int' object is not iterable"
,
ex
.
Message
)
;
Assert
.
IsNull
(
t
)
;
}
[
Test
]
public
void
TestListAsListType
(
)
{
var
l
=
new
PyList
(
)
;
PyList
t
=
PyList
.
AsList
(
l
)
;
Assert
.
IsNotNull
(
t
)
;
Assert
.
IsInstanceOf
(
typeof
(
PyList
)
,
t
)
;
}
[
Test
]
public
void
TestEmptyCtor
(
)
{
var
s
=
new
PyList
(
)
;
Assert
.
IsInstanceOf
(
typeof
(
PyList
)
,
s
)
;
Assert
.
AreEqual
(
0
,
s
.
Length
(
)
)
;
}
[
Test
]
public
void
TestPyObjectArrayCtor
(
)
{
var
ai
=
new
PyObject
[
]
{
new
PyInt
(
3
)
,
new
PyInt
(
2
)
,
new
PyInt
(
1
)
}
;
var
s
=
new
PyList
(
ai
)
;
Assert
.
IsInstanceOf
(
typeof
(
PyList
)
,
s
)
;
Assert
.
AreEqual
(
3
,
s
.
Length
(
)
)
;
Assert
.
AreEqual
(
"3"
,
s
[
0
]
.
ToString
(
)
)
;
Assert
.
AreEqual
(
"2"
,
s
[
1
]
.
ToString
(
)
)
;
Assert
.
AreEqual
(
"1"
,
s
[
2
]
.
ToString
(
)
)
;
}
[
Test
]
public
void
TestPyObjectCtor
(
)
{
var
a
=
new
PyList
(
)
;
var
s
=
new
PyList
(
a
)
;
Assert
.
IsInstanceOf
(
typeof
(
PyList
)
,
s
)
;
Assert
.
AreEqual
(
0
,
s
.
Length
(
)
)
;
}
[
Test
]
public
void
TestBadPyObjectCtor
(
)
{
var
i
=
new
PyInt
(
5
)
;
PyList
t
=
null
;
var
ex
=
Assert
.
Throws
<
ArgumentException
>
(
(
)
=>
t
=
new
PyList
(
i
)
)
;
Assert
.
AreEqual
(
"object is not a list"
,
ex
.
Message
)
;
Assert
.
IsNull
(
t
)
;
}
[
Test
]
public
void
TestAppend
(
)
{
var
ai
=
new
PyObject
[
]
{
new
PyInt
(
3
)
,
new
PyInt
(
2
)
,
new
PyInt
(
1
)
}
;
var
s
=
new
PyList
(
ai
)
;
s
.
Append
(
new
PyInt
(
4
)
)
;
Assert
.
AreEqual
(
4
,
s
.
Length
(
)
)
;
Assert
.
AreEqual
(
"4"
,
s
[
3
]
.
ToString
(
)
)
;
}
[
Test
]
public
void
TestInsert
(
)
{
var
ai
=
new
PyObject
[
]
{
new
PyInt
(
3
)
,
new
PyInt
(
2
)
,
new
PyInt
(
1
)
}
;
var
s
=
new
PyList
(
ai
)
;
s
.
Insert
(
0
,
new
PyInt
(
4
)
)
;
Assert
.
AreEqual
(
4
,
s
.
Length
(
)
)
;
Assert
.
AreEqual
(
"4"
,
s
[
0
]
.
ToString
(
)
)
;
}
[
Test
]
public
void
TestReverse
(
)
{
var
ai
=
new
PyObject
[
]
{
new
PyInt
(
3
)
,
new
PyInt
(
1
)
,
new
PyInt
(
2
)
}
;
var
s
=
new
PyList
(
ai
)
;
s
.
Reverse
(
)
;
Assert
.
AreEqual
(
3
,
s
.
Length
(
)
)
;
Assert
.
AreEqual
(
"2"
,
s
[
0
]
.
ToString
(
)
)
;
Assert
.
AreEqual
(
"1"
,
s
[
1
]
.
ToString
(
)
)
;
Assert
.
AreEqual
(
"3"
,
s
[
2
]
.
ToString
(
)
)
;
}
[
Test
]
public
void
TestSort
(
)
{
var
ai
=
new
PyObject
[
]
{
new
PyInt
(
3
)
,
new
PyInt
(
1
)
,
new
PyInt
(
2
)
}
;
var
s
=
new
PyList
(
ai
)
;
s
.
Sort
(
)
;
Assert
.
AreEqual
(
3
,
s
.
Length
(
)
)
;
Assert
.
AreEqual
(
"1"
,
s
[
0
]
.
ToString
(
)
)
;
Assert
.
AreEqual
(
"2"
,
s
[
1
]
.
ToString
(
)
)
;
Assert
.
AreEqual
(
"3"
,
s
[
2
]
.
ToString
(
)
)
;
}
[
Test
]
public
void
TestOnPyList
(
)
{
var
list
=
new
PyList
(
)
;
list
.
Append
(
new
PyString
(
"foo"
)
)
;
list
.
Append
(
new
PyString
(
"bar"
)
)
;
list
.
Append
(
new
PyString
(
"baz"
)
)
;
var
result
=
new
List
<
string
>
(
)
;
foreach
(
PyObject
item
in
list
)
{
result
.
Add
(
item
.
ToString
(
)
)
;
}
Assert
.
AreEqual
(
3
,
result
.
Count
)
;
Assert
.
AreEqual
(
"foo"
,
result
[
0
]
)
;
Assert
.
AreEqual
(
"bar"
,
result
[
1
]
)
;
Assert
.
AreEqual
(
"baz"
,
result
[
2
]
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL