@@ -43,6 +43,21 @@ public void TestPyTupleEmpty()
43
43
}
44
44
}
45
45
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
+
46
61
/// <summary>
47
62
/// Test PyTuple.Concat(...) doesn't let invalid appends happen
48
63
/// and throws and exception.
@@ -51,6 +66,8 @@ public void TestPyTupleEmpty()
51
66
/// Test has second purpose. Currently it generated an Exception
52
67
/// that the GC failed to remove often and caused AppDomain unload
53
68
/// 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.
54
71
/// </remarks>
55
72
[ Test ]
56
73
public void TestPyTupleInvalidAppend ( )
@@ -59,7 +76,12 @@ public void TestPyTupleInvalidAppend()
59
76
{
60
77
PyObject s = new PyString ( "foo" ) ;
61
78
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 ) ;
63
85
}
64
86
}
65
87
@@ -114,5 +136,23 @@ public void TestNewPyTupleFromPyTuple()
114
136
Assert . IsInstanceOf ( typeof ( PyTuple ) , t ) ;
115
137
}
116
138
}
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
+ }
117
157
}
118
158
}
0 commit comments