@@ -6,18 +6,27 @@ namespace Python.EmbeddingTest
66{
77 public class TestPyTuple
88 {
9+ [ OneTimeSetUp ]
10+ public void SetUp ( )
11+ {
12+ PythonEngine . Initialize ( ) ;
13+ }
14+
15+ [ OneTimeTearDown ]
16+ public void Dispose ( )
17+ {
18+ PythonEngine . Shutdown ( ) ;
19+ }
20+
921 /// <summary>
1022 /// Test IsTupleType without having to Initialize a tuple.
1123 /// PyTuple constructor use IsTupleType. This decouples the tests.
1224 /// </summary>
1325 [ Test ]
1426 public void TestStringIsTupleType ( )
1527 {
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 ) ) ;
2130 }
2231
2332 /// <summary>
@@ -26,72 +35,54 @@ public void TestStringIsTupleType()
2635 [ Test ]
2736 public void TestPyTupleIsTupleType ( )
2837 {
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 ) ) ;
3440 }
3541
3642 [ Test ]
3743 public void TestPyTupleEmpty ( )
3844 {
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 ( ) ) ;
4447 }
4548
4649 [ Test ]
4750 public void TestPyTupleBadCtor ( )
4851 {
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 ;
5354
54- var ex = Assert . Throws < ArgumentException > ( ( ) => t = new PyTuple ( i ) ) ;
55+ var ex = Assert . Throws < ArgumentException > ( ( ) => t = new PyTuple ( i ) ) ;
5556
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 ) ;
5959 }
6060
6161 [ Test ]
6262 public void TestPyTupleCtorEmptyArray ( )
6363 {
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 ) ;
6866
69- Assert . AreEqual ( 0 , t . Length ( ) ) ;
70- }
67+ Assert . AreEqual ( 0 , t . Length ( ) ) ;
7168 }
7269
7370 [ Test ]
7471 public void TestPyTupleCtorArrayPyIntEmpty ( )
7572 {
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 ) ;
8075
81- Assert . AreEqual ( 0 , t . Length ( ) ) ;
82- }
76+ Assert . AreEqual ( 0 , t . Length ( ) ) ;
8377 }
8478
8579 [ Test ]
8680 public void TestPyTupleCtorArray ( )
8781 {
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 ) ;
9284
93- Assert . AreEqual ( 2 , t . Length ( ) ) ;
94- }
85+ Assert . AreEqual ( 2 , t . Length ( ) ) ;
9586 }
9687
9788 /// <summary>
@@ -108,69 +99,58 @@ public void TestPyTupleCtorArray()
10899 [ Test ]
109100 public void TestPyTupleInvalidAppend ( )
110101 {
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 ( ) ;
115104
116- var ex = Assert . Throws < PythonException > ( ( ) => t . Concat ( s ) ) ;
105+ var ex = Assert . Throws < PythonException > ( ( ) => t . Concat ( s ) ) ;
117106
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 ) ;
122110 }
123111
124112 [ Test ]
125113 public void TestPyTupleValidAppend ( )
126114 {
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 ) ;
135121 }
136122
137123 [ Test ]
138124 public void TestPyTupleStringConvert ( )
139125 {
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 ( ) ) ;
150134 }
151135
152136 [ Test ]
153137 public void TestPyTupleValidConvert ( )
154138 {
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 ) ;
162144 }
163145
164146 [ Test ]
165147 public void TestNewPyTupleFromPyTuple ( )
166148 {
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 ) ;
174154 }
175155
176156 /// <remarks>
@@ -179,16 +159,13 @@ public void TestNewPyTupleFromPyTuple()
179159 [ Test ]
180160 public void TestInvalidAsTuple ( )
181161 {
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 ;
186164
187- var ex = Assert . Throws < PythonException > ( ( ) => t = PyTuple . AsTuple ( i ) ) ;
165+ var ex = Assert . Throws < PythonException > ( ( ) => t = PyTuple . AsTuple ( i ) ) ;
188166
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 ) ;
192169 }
193170 }
194171}
0 commit comments