FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/embed_tests/TestPyTuple.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
/
TestPyTuple.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
171 lines (143 loc) · 4.52 KB
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
TestPyTuple.cs
Copy path
File metadata and controls
171 lines (143 loc) · 4.52 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
using
System
;
using
NUnit
.
Framework
;
using
Python
.
Runtime
;
namespace
Python
.
EmbeddingTest
{
public
class
TestPyTuple
{
[
OneTimeSetUp
]
public
void
SetUp
(
)
{
PythonEngine
.
Initialize
(
)
;
}
[
OneTimeTearDown
]
public
void
Dispose
(
)
{
PythonEngine
.
Shutdown
(
)
;
}
/// <summary>
/// Test IsTupleType without having to Initialize a tuple.
/// PyTuple constructor use IsTupleType. This decouples the tests.
/// </summary>
[
Test
]
public
void
TestStringIsTupleType
(
)
{
var
s
=
new
PyString
(
"foo"
)
;
Assert
.
False
(
PyTuple
.
IsTupleType
(
s
)
)
;
}
/// <summary>
/// Test IsTupleType with Tuple.
/// </summary>
[
Test
]
public
void
TestPyTupleIsTupleType
(
)
{
var
t
=
new
PyTuple
(
)
;
Assert
.
True
(
PyTuple
.
IsTupleType
(
t
)
)
;
}
[
Test
]
public
void
TestPyTupleEmpty
(
)
{
var
t
=
new
PyTuple
(
)
;
Assert
.
AreEqual
(
0
,
t
.
Length
(
)
)
;
}
[
Test
]
public
void
TestPyTupleBadCtor
(
)
{
var
i
=
new
PyInt
(
5
)
;
PyTuple
t
=
null
;
var
ex
=
Assert
.
Throws
<
ArgumentException
>
(
(
)
=>
t
=
new
PyTuple
(
i
)
)
;
Assert
.
AreEqual
(
"object is not a tuple"
,
ex
.
Message
)
;
Assert
.
IsNull
(
t
)
;
}
[
Test
]
public
void
TestPyTupleCtorEmptyArray
(
)
{
var
a
=
new
PyObject
[
]
{
}
;
var
t
=
new
PyTuple
(
a
)
;
Assert
.
AreEqual
(
0
,
t
.
Length
(
)
)
;
}
[
Test
]
public
void
TestPyTupleCtorArrayPyIntEmpty
(
)
{
var
a
=
new
PyInt
[
]
{
}
;
var
t
=
new
PyTuple
(
a
)
;
Assert
.
AreEqual
(
0
,
t
.
Length
(
)
)
;
}
[
Test
]
public
void
TestPyTupleCtorArray
(
)
{
var
a
=
new
PyObject
[
]
{
new
PyInt
(
1
)
,
new
PyString
(
"Foo"
)
}
;
var
t
=
new
PyTuple
(
a
)
;
Assert
.
AreEqual
(
2
,
t
.
Length
(
)
)
;
}
/// <summary>
/// Test PyTuple.Concat(...) doesn't let invalid appends happen
/// and throws and exception.
/// </summary>
/// <remarks>
/// Test has second purpose. Currently it generated an Exception
/// that the GC failed to remove often and caused AppDomain unload
/// errors at the end of tests. See GH#397 for more info.
/// <para />
/// Curious, on PY27 it gets a Unicode on the ex.Message. On PY3+ its string.
/// </remarks>
[
Test
]
public
void
TestPyTupleInvalidAppend
(
)
{
PyObject
s
=
new
PyString
(
"foo"
)
;
var
t
=
new
PyTuple
(
)
;
var
ex
=
Assert
.
Throws
<
PythonException
>
(
(
)
=>
t
.
Concat
(
s
)
)
;
StringAssert
.
StartsWith
(
"TypeError : can only concatenate tuple"
,
ex
.
Message
)
;
Assert
.
AreEqual
(
0
,
t
.
Length
(
)
)
;
Assert
.
IsEmpty
(
t
)
;
}
[
Test
]
public
void
TestPyTupleValidAppend
(
)
{
var
t0
=
new
PyTuple
(
)
;
var
t
=
new
PyTuple
(
)
;
t
.
Concat
(
t0
)
;
Assert
.
IsNotNull
(
t
)
;
Assert
.
IsInstanceOf
(
typeof
(
PyTuple
)
,
t
)
;
}
[
Test
]
public
void
TestPyTupleStringConvert
(
)
{
PyObject
s
=
new
PyString
(
"foo"
)
;
PyTuple
t
=
PyTuple
.
AsTuple
(
s
)
;
Assert
.
IsNotNull
(
t
)
;
Assert
.
IsInstanceOf
(
typeof
(
PyTuple
)
,
t
)
;
Assert
.
AreEqual
(
"f"
,
t
[
0
]
.
ToString
(
)
)
;
Assert
.
AreEqual
(
"o"
,
t
[
1
]
.
ToString
(
)
)
;
Assert
.
AreEqual
(
"o"
,
t
[
2
]
.
ToString
(
)
)
;
}
[
Test
]
public
void
TestPyTupleValidConvert
(
)
{
var
l
=
new
PyList
(
)
;
PyTuple
t
=
PyTuple
.
AsTuple
(
l
)
;
Assert
.
IsNotNull
(
t
)
;
Assert
.
IsInstanceOf
(
typeof
(
PyTuple
)
,
t
)
;
}
[
Test
]
public
void
TestNewPyTupleFromPyTuple
(
)
{
var
t0
=
new
PyTuple
(
)
;
var
t
=
new
PyTuple
(
t0
)
;
Assert
.
IsNotNull
(
t
)
;
Assert
.
IsInstanceOf
(
typeof
(
PyTuple
)
,
t
)
;
}
/// <remarks>
/// TODO: Should this throw ArgumentError instead?
/// </remarks>
[
Test
]
public
void
TestInvalidAsTuple
(
)
{
var
i
=
new
PyInt
(
5
)
;
PyTuple
t
=
null
;
var
ex
=
Assert
.
Throws
<
PythonException
>
(
(
)
=>
t
=
PyTuple
.
AsTuple
(
i
)
)
;
Assert
.
AreEqual
(
"TypeError : 'int' object is not iterable"
,
ex
.
Message
)
;
Assert
.
IsNull
(
t
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL