1
1
#include "parts.h"
2
2
3
- // Forward declarations
4
3
static struct PyModuleDef * _testcapimodule = NULL ; // set at initialization
5
- static PyObject * TestError ; /* set to exception object in init */
6
-
7
- /* Raise TestError with test_name + ": " + msg, and return NULL. */
8
- static PyObject *
9
- raiseTestError (const char * test_name , const char * msg )
10
- {
11
- PyErr_Format (TestError , "%s: %s" , test_name , msg );
12
- return NULL ;
13
- }
14
4
15
5
static PyObject *
16
6
codec_incrementalencoder (PyObject * self , PyObject * args )
@@ -41,7 +31,7 @@ test_unicode_compare_with_ascii(PyObject *self, PyObject *Py_UNUSED(ignored)) {
41
31
result = PyUnicode_CompareWithASCIIString (py_s , "str" );
42
32
Py_DECREF (py_s );
43
33
if (!result ) {
44
- PyErr_SetString (TestError , "Python string ending in NULL "
34
+ PyErr_SetString (PyExc_AssertionError , "Python string ending in NULL "
45
35
"should not compare equal to c string." );
46
36
return NULL ;
47
37
}
@@ -74,18 +64,22 @@ test_widechar(PyObject *self, PyObject *Py_UNUSED(ignored))
74
64
if (PyUnicode_GET_LENGTH (wide ) != PyUnicode_GET_LENGTH (utf8 )) {
75
65
Py_DECREF (wide );
76
66
Py_DECREF (utf8 );
77
- return raiseTestError ("test_widechar" ,
78
- "wide string and utf8 string "
79
- "have different length" );
67
+ PyErr_SetString (PyExc_AssertionError ,
68
+ "test_widechar: "
69
+ "wide string and utf8 string "
70
+ "have different length" );
71
+ return NULL ;
80
72
}
81
73
if (PyUnicode_Compare (wide , utf8 )) {
82
74
Py_DECREF (wide );
83
75
Py_DECREF (utf8 );
84
76
if (PyErr_Occurred ())
85
77
return NULL ;
86
- return raiseTestError ("test_widechar" ,
87
- "wide string and utf8 string "
88
- "are different" );
78
+ PyErr_SetString (PyExc_AssertionError ,
79
+ "test_widechar: "
80
+ "wide string and utf8 string "
81
+ "are different" );
82
+ return NULL ;
89
83
}
90
84
91
85
Py_DECREF (wide );
@@ -95,9 +89,12 @@ test_widechar(PyObject *self, PyObject *Py_UNUSED(ignored))
95
89
wide = PyUnicode_FromWideChar (invalid , 1 );
96
90
if (wide == NULL )
97
91
PyErr_Clear ();
98
- else
99
- return raiseTestError ("test_widechar" ,
100
- "PyUnicode_FromWideChar(L\"\\U00110000\", 1) didn't fail" );
92
+ else {
93
+ PyErr_SetString (PyExc_AssertionError ,
94
+ "test_widechar: "
95
+ "PyUnicode_FromWideChar(L\"\\U00110000\", 1) didn't fail" );
96
+ return NULL ;
97
+ }
101
98
#endif
102
99
Py_RETURN_NONE ;
103
100
}
@@ -287,7 +284,7 @@ test_string_from_format(PyObject *self, PyObject *Py_UNUSED(ignored))
287
284
if (result == NULL) \
288
285
return NULL; \
289
286
if (!_PyUnicode_EqualToASCIIString(result, EXPECTED)) { \
290
- PyErr_Format(TestError, \
287
+ PyErr_Format(PyExc_AssertionError, \
291
288
"test_string_from_format: failed at \"%s\" " \
292
289
"expected \"%s\" got \"%s\"", \
293
290
FORMAT, EXPECTED, PyUnicode_AsUTF8(result)); \
684
681
_PyTestCapi_Init_Unicode (PyObject * m ) {
685
682
_testcapimodule = PyModule_GetDef (m );
686
683
687
- TestError = PyErr_NewException ("_testcapi.unicode_error" , NULL , NULL );
688
- Py_INCREF (TestError );
689
- PyModule_AddObject (m , "unicode_error" , TestError );
690
-
691
684
if (PyModule_AddFunctions (m , TestMethods ) < 0 ) {
692
685
return -1 ;
693
686
}
0 commit comments