@@ -6,18 +6,27 @@ namespace Python.EmbeddingTest
6
6
{
7
7
public class TestPyTuple
8
8
{
9
+ [ OneTimeSetUp ]
10
+ public void SetUp ( )
11
+ {
12
+ PythonEngine . Initialize ( ) ;
13
+ }
14
+
15
+ [ OneTimeTearDown ]
16
+ public void Dispose ( )
17
+ {
18
+ PythonEngine . Shutdown ( ) ;
19
+ }
20
+
9
21
/// <summary>
10
22
/// Test IsTupleType without having to Initialize a tuple.
11
23
/// PyTuple constructor use IsTupleType. This decouples the tests.
12
24
/// </summary>
13
25
[ Test ]
14
26
public void TestStringIsTupleType ( )
15
27
{
16
- using ( Py . GIL ( ) )
17
- {
18
- var s = new PyString ( "foo" ) ;
19
- Assert . IsFalse ( PyTuple . IsTupleType ( s ) ) ;
20
- }
28
+ var s = new PyString ( "foo" ) ;
29
+ Assert . False ( PyTuple . IsTupleType ( s ) ) ;
21
30
}
22
31
23
32
/// <summary>
@@ -26,72 +35,54 @@ public void TestStringIsTupleType()
26
35
[ Test ]
27
36
public void TestPyTupleIsTupleType ( )
28
37
{
29
- using ( Py . GIL ( ) )
30
- {
31
- var t = new PyTuple ( ) ;
32
- Assert . IsTrue ( PyTuple . IsTupleType ( t ) ) ;
33
- }
38
+ var t = new PyTuple ( ) ;
39
+ Assert . True ( PyTuple . IsTupleType ( t ) ) ;
34
40
}
35
41
36
42
[ Test ]
37
43
public void TestPyTupleEmpty ( )
38
44
{
39
- using ( Py . GIL ( ) )
40
- {
41
- var t = new PyTuple ( ) ;
42
- Assert . AreEqual ( 0 , t . Length ( ) ) ;
43
- }
45
+ var t = new PyTuple ( ) ;
46
+ Assert . AreEqual ( 0 , t . Length ( ) ) ;
44
47
}
45
48
46
49
[ Test ]
47
50
public void TestPyTupleBadCtor ( )
48
51
{
49
- using ( Py . GIL ( ) )
50
- {
51
- var i = new PyInt ( 5 ) ;
52
- PyTuple t = null ;
52
+ var i = new PyInt ( 5 ) ;
53
+ PyTuple t = null ;
53
54
54
- var ex = Assert . Throws < ArgumentException > ( ( ) => t = new PyTuple ( i ) ) ;
55
+ var ex = Assert . Throws < ArgumentException > ( ( ) => t = new PyTuple ( i ) ) ;
55
56
56
- Assert . AreEqual ( "object is not a tuple" , ex . Message ) ;
57
- Assert . IsNull ( t ) ;
58
- }
57
+ Assert . AreEqual ( "object is not a tuple" , ex . Message ) ;
58
+ Assert . IsNull ( t ) ;
59
59
}
60
60
61
61
[ Test ]
62
62
public void TestPyTupleCtorEmptyArray ( )
63
63
{
64
- using ( Py . GIL ( ) )
65
- {
66
- var a = new PyObject [ ] { } ;
67
- var t = new PyTuple ( a ) ;
64
+ var a = new PyObject [ ] { } ;
65
+ var t = new PyTuple ( a ) ;
68
66
69
- Assert . AreEqual ( 0 , t . Length ( ) ) ;
70
- }
67
+ Assert . AreEqual ( 0 , t . Length ( ) ) ;
71
68
}
72
69
73
70
[ Test ]
74
71
public void TestPyTupleCtorArrayPyIntEmpty ( )
75
72
{
76
- using ( Py . GIL ( ) )
77
- {
78
- var a = new PyInt [ ] { } ;
79
- var t = new PyTuple ( a ) ;
73
+ var a = new PyInt [ ] { } ;
74
+ var t = new PyTuple ( a ) ;
80
75
81
- Assert . AreEqual ( 0 , t . Length ( ) ) ;
82
- }
76
+ Assert . AreEqual ( 0 , t . Length ( ) ) ;
83
77
}
84
78
85
79
[ Test ]
86
80
public void TestPyTupleCtorArray ( )
87
81
{
88
- using ( Py . GIL ( ) )
89
- {
90
- var a = new PyObject [ ] { new PyInt ( 1 ) , new PyString ( "Foo" ) } ;
91
- var t = new PyTuple ( a ) ;
82
+ var a = new PyObject [ ] { new PyInt ( 1 ) , new PyString ( "Foo" ) } ;
83
+ var t = new PyTuple ( a ) ;
92
84
93
- Assert . AreEqual ( 2 , t . Length ( ) ) ;
94
- }
85
+ Assert . AreEqual ( 2 , t . Length ( ) ) ;
95
86
}
96
87
97
88
/// <summary>
@@ -108,69 +99,58 @@ public void TestPyTupleCtorArray()
108
99
[ Test ]
109
100
public void TestPyTupleInvalidAppend ( )
110
101
{
111
- using ( Py . GIL ( ) )
112
- {
113
- PyObject s = new PyString ( "foo" ) ;
114
- var t = new PyTuple ( ) ;
102
+ PyObject s = new PyString ( "foo" ) ;
103
+ var t = new PyTuple ( ) ;
115
104
116
- var ex = Assert . Throws < PythonException > ( ( ) => t . Concat ( s ) ) ;
105
+ var ex = Assert . Throws < PythonException > ( ( ) => t . Concat ( s ) ) ;
117
106
118
- StringAssert . StartsWith ( "TypeError : can only concatenate tuple" , ex . Message ) ;
119
- Assert . AreEqual ( 0 , t . Length ( ) ) ;
120
- Assert . IsEmpty ( t ) ;
121
- }
107
+ StringAssert . StartsWith ( "TypeError : can only concatenate tuple" , ex . Message ) ;
108
+ Assert . AreEqual ( 0 , t . Length ( ) ) ;
109
+ Assert . IsEmpty ( t ) ;
122
110
}
123
111
124
112
[ Test ]
125
113
public void TestPyTupleValidAppend ( )
126
114
{
127
- using ( Py . GIL ( ) )
128
- {
129
- var t0 = new PyTuple ( ) ;
130
- var t = new PyTuple ( ) ;
131
- t . Concat ( t0 ) ;
132
- Assert . IsNotNull ( t ) ;
133
- Assert . IsInstanceOf ( typeof ( PyTuple ) , t ) ;
134
- }
115
+ var t0 = new PyTuple ( ) ;
116
+ var t = new PyTuple ( ) ;
117
+ t . Concat ( t0 ) ;
118
+
119
+ Assert . IsNotNull ( t ) ;
120
+ Assert . IsInstanceOf ( typeof ( PyTuple ) , t ) ;
135
121
}
136
122
137
123
[ Test ]
138
124
public void TestPyTupleStringConvert ( )
139
125
{
140
- using ( Py . GIL ( ) )
141
- {
142
- PyObject s = new PyString ( "foo" ) ;
143
- PyTuple t = PyTuple . AsTuple ( s ) ;
144
- Assert . IsNotNull ( t ) ;
145
- Assert . IsInstanceOf ( typeof ( PyTuple ) , t ) ;
146
- Assert . AreEqual ( "f" , t [ 0 ] . ToString ( ) ) ;
147
- Assert . AreEqual ( "o" , t [ 1 ] . ToString ( ) ) ;
148
- Assert . AreEqual ( "o" , t [ 2 ] . ToString ( ) ) ;
149
- }
126
+ PyObject s = new PyString ( "foo" ) ;
127
+ PyTuple t = PyTuple . AsTuple ( s ) ;
128
+
129
+ Assert . IsNotNull ( t ) ;
130
+ Assert . IsInstanceOf ( typeof ( PyTuple ) , t ) ;
131
+ Assert . AreEqual ( "f" , t [ 0 ] . ToString ( ) ) ;
132
+ Assert . AreEqual ( "o" , t [ 1 ] . ToString ( ) ) ;
133
+ Assert . AreEqual ( "o" , t [ 2 ] . ToString ( ) ) ;
150
134
}
151
135
152
136
[ Test ]
153
137
public void TestPyTupleValidConvert ( )
154
138
{
155
- using ( Py . GIL ( ) )
156
- {
157
- var l = new PyList ( ) ;
158
- PyTuple t = PyTuple . AsTuple ( l ) ;
159
- Assert . IsNotNull ( t ) ;
160
- Assert . IsInstanceOf ( typeof ( PyTuple ) , t ) ;
161
- }
139
+ var l = new PyList ( ) ;
140
+ PyTuple t = PyTuple . AsTuple ( l ) ;
141
+
142
+ Assert . IsNotNull ( t ) ;
143
+ Assert . IsInstanceOf ( typeof ( PyTuple ) , t ) ;
162
144
}
163
145
164
146
[ Test ]
165
147
public void TestNewPyTupleFromPyTuple ( )
166
148
{
167
- using ( Py . GIL ( ) )
168
- {
169
- var t0 = new PyTuple ( ) ;
170
- var t = new PyTuple ( t0 ) ;
171
- Assert . IsNotNull ( t ) ;
172
- Assert . IsInstanceOf ( typeof ( PyTuple ) , t ) ;
173
- }
149
+ var t0 = new PyTuple ( ) ;
150
+ var t = new PyTuple ( t0 ) ;
151
+
152
+ Assert . IsNotNull ( t ) ;
153
+ Assert . IsInstanceOf ( typeof ( PyTuple ) , t ) ;
174
154
}
175
155
176
156
/// <remarks>
@@ -179,16 +159,13 @@ public void TestNewPyTupleFromPyTuple()
179
159
[ Test ]
180
160
public void TestInvalidAsTuple ( )
181
161
{
182
- using ( Py . GIL ( ) )
183
- {
184
- var i = new PyInt ( 5 ) ;
185
- PyTuple t = null ;
162
+ var i = new PyInt ( 5 ) ;
163
+ PyTuple t = null ;
186
164
187
- var ex = Assert . Throws < PythonException > ( ( ) => t = PyTuple . AsTuple ( i ) ) ;
165
+ var ex = Assert . Throws < PythonException > ( ( ) => t = PyTuple . AsTuple ( i ) ) ;
188
166
189
- Assert . AreEqual ( "TypeError : 'int' object is not iterable" , ex . Message ) ;
190
- Assert . IsNull ( t ) ;
191
- }
167
+ Assert . AreEqual ( "TypeError : 'int' object is not iterable" , ex . Message ) ;
168
+ Assert . IsNull ( t ) ;
192
169
}
193
170
}
194
171
}
0 commit comments