@@ -43,6 +43,21 @@ public void TestPyTupleEmpty()
4343 }
4444 }
4545
46+ [ Test ]
47+ public void TestPyTupleBadCtor ( )
48+ {
49+ using ( Py . GIL ( ) )
50+ {
51+ var i = new PyInt ( 5 ) ;
52+ PyTuple t = null ;
53+
54+ var ex = Assert . Throws < ArgumentException > ( ( ) => t = new PyTuple ( i ) ) ;
55+
56+ Assert . AreEqual ( "object is not a tuple" , ex . Message ) ;
57+ Assert . IsNull ( t ) ;
58+ }
59+ }
60+
4661 /// <summary>
4762 /// Test PyTuple.Concat(...) doesn't let invalid appends happen
4863 /// and throws and exception.
@@ -51,6 +66,8 @@ public void TestPyTupleEmpty()
5166 /// Test has second purpose. Currently it generated an Exception
5267 /// that the GC failed to remove often and caused AppDomain unload
5368 /// errors at the end of tests. See GH#397 for more info.
69+ /// <para />
70+ /// Curious, on PY27 it gets a Unicode on the ex.Message. On PY3+ its string.
5471 /// </remarks>
5572 [ Test ]
5673 public void TestPyTupleInvalidAppend ( )
@@ -59,7 +76,12 @@ public void TestPyTupleInvalidAppend()
5976 {
6077 PyObject s = new PyString ( "foo" ) ;
6178 var t = new PyTuple ( ) ;
62- Assert . Throws < PythonException > ( ( ) => t . Concat ( s ) ) ;
79+
80+ var ex = Assert . Throws < PythonException > ( ( ) => t . Concat ( s ) ) ;
81+
82+ StringAssert . StartsWith ( "TypeError : can only concatenate tuple" , ex . Message ) ;
83+ Assert . AreEqual ( 0 , t . Length ( ) ) ;
84+ Assert . IsEmpty ( t ) ;
6385 }
6486 }
6587
@@ -114,5 +136,23 @@ public void TestNewPyTupleFromPyTuple()
114136 Assert . IsInstanceOf ( typeof ( PyTuple ) , t ) ;
115137 }
116138 }
139+
140+ /// <remarks>
141+ /// TODO: Should this throw ArgumentError instead?
142+ /// </remarks>
143+ [ Test ]
144+ public void TestInvalidAsTuple ( )
145+ {
146+ using ( Py . GIL ( ) )
147+ {
148+ var i = new PyInt ( 5 ) ;
149+ PyTuple t = null ;
150+
151+ var ex = Assert . Throws < PythonException > ( ( ) => t = PyTuple . AsTuple ( i ) ) ;
152+
153+ Assert . AreEqual ( "TypeError : 'int' object is not iterable" , ex . Message ) ;
154+ Assert . IsNull ( t ) ;
155+ }
156+ }
117157 }
118158}
0 commit comments